⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 peeradvertisement.java

📁 jxta_src_2.41b jxta 2.41b 最新版源码 from www.jxta.org
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
     */        public void setPeerGroupID(PeerGroupID gid) {        this.gid = gid;        incModCount();    }        /**     * Returns a unique ID for that peer X group intersection. This is for indexing     * purposes only.     *     * <p/>We return a composite ID that represents this peer is this group     * rather than in the platform, which is what the regular peerId shows.     *     * <p/>May-be one day we'll want to name a peer differently     * in each group, exactly in this way. In the meantime we still need     * it to uniquely identify this adv.     *     * <p/>FIXME 20020604 bondolo@jxta.org This is a total hack as it assumes the     *  format of a group id. It's supposed to be opaque. The real answer is to     *  use a unique value within each group.     *     * @return ID the composite ID     */        public ID getID() {                // If it is incomplete, there's no meaninfull ID that we can return.        if (gid == null || pid == null) {            return null;        }                String peer;        // That's tricky; we're not realy supposed to do that...                // Get the grp unique string of hex. Clip the two type bytes        // at the end.        if (gid.equals(PeerGroupID.defaultNetPeerGroupID) || gid.equals(PeerGroupID.worldPeerGroupID)) {                        peer = pid.getUniqueValue().toString();                    } else {            String grp = gid.getUniqueValue().toString();            grp = grp.substring(0, grp.length() - 2);                        // Get the peer unique string whih starts with the platform's unique            // string.            peer = pid.getUniqueValue().toString();            // Replace the platform's unique portion with this group's id.            peer = grp + peer.substring(grp.length());        }                // Forge a URI form for this chimaera and build a new PeerID out of it.        try {            return IDFactory.fromURI(new URI(ID.URIEncodingName + ":" + ID.URNNamespace + ":" + peer));        } catch (URISyntaxException iDontMakeMistakes) {            // Fall through,  iDontMakeMistakes sometimes makes mistakes :)            // iDontMakeMistakes.printStackTrace();            ;        }        // May be if we had an "internal error exception" we should throw it.        return null;    }        /**     * returns the description     *     * @return String the description     */    public String getDescription() {        if (null != description) {            return (String) description.getValue();        } else {            return null;        }    }        /**     * sets the description     *     * @since JXTA 1.0     *     * @param description the description     */    public void setDescription(String description) {                if (null != description) {            StructuredDocument newdoc = StructuredDocumentFactory.newStructuredDocument(MimeMediaType.XMLUTF8, "Desc", description);                        setDesc(newdoc);        } else {            this.description = null;        }                incModCount();    }        /**     * returns the description     *     * @return the description     *     */    public StructuredDocument getDesc() {        if (null != description) {            StructuredDocument newDoc = StructuredDocumentUtils.copyAsDocument(description);                        return newDoc;        } else {            return null;        }    }        /**     * sets the description     *     * @param desc the description     *     */    public void setDesc(Element desc) {                if (null != desc) {            this.description = StructuredDocumentUtils.copyAsDocument(desc);        } else {            this.description = null;        }                incModCount();    }        /**     *  sets the sets of parameters for all services. This method first makes a     *  deep copy, in order to protect the active information from uncontrolled     *  sharing. This quite an expensive operation. If only a few of the     *  parameters need to be added, it is wise to use putServiceParam()     *  instead.     *     *@param  params  The whole set of parameters.     */    public void setServiceParams(Hashtable params) {        serviceParams.clear();                if (params == null) {            return;        }                Iterator services = params.entrySet().iterator();        while (services.hasNext()) {            Map.Entry anEntry = (Map.Entry) services.next();                        Element e = (Element) anEntry.getValue();            Element newDoc = StructuredDocumentUtils.copyAsDocument(e);            serviceParams.put(anEntry.getKey(), newDoc);        }                incModCount();    }        /**     *  Returns the sets of parameters for all services. <p/>     *     *  This method returns a deep copy, in order to protect the real     *  information from uncontrolled sharing while keeping it shared as long as     *  it is safe. This quite an expensive operation. If only a few parameters     *  need to be accessed, it is wise to use getServiceParam() instead.     *     *@return    all of the parameters.     */    public Hashtable getServiceParams() {        Hashtable copy = new Hashtable();                Iterator services = serviceParams.entrySet().iterator();        while (services.hasNext()) {            Map.Entry anEntry = (Map.Entry) services.next();                        Element e = (Element) anEntry.getValue();            Element newDoc = StructuredDocumentUtils.copyAsDocument(e);            copy.put(anEntry.getKey(), newDoc);        }                return copy;    }        /**     *  Puts a service parameter in the service parameters table under the given     *  key. The key is of a subclass of ID; usually a ModuleClassID. This     *  method makes a deep copy of the given element into an independent     *  document.     *     *@param  key    The key.     *@param  param  The parameter, as an element. What is stored is a copy as a     *      standalone StructuredDocument which type is the element's name.     */    public void putServiceParam(ID key, Element param) {        if (param == null) {            serviceParams.remove(key);            incModCount();            return;        }                Element newDoc = StructuredDocumentUtils.copyAsDocument(param);        serviceParams.put(key, newDoc);                incModCount();    }        /**     *  Returns the parameter element that matches the given key from the     *  service parameters table. The key is of a subclass of ID; usually a     *  ModuleClassID.     *     *@param  key  The key.     *@return      StructuredDocument The matching parameter document or null if     *      none matched. The document type id "Param".     */    public StructuredDocument getServiceParam(ID key) {        Element param = (Element) serviceParams.get(key);        if (param == null) {            return null;        }                return  StructuredDocumentUtils.copyAsDocument(param);    }        /**     *  Removes and returns the parameter element that matches the given key     *  from the service parameters table. The key is of a subclass of ID;     *  usually a ModuleClassID.     *     *@param  key  The key.     *@return      Element the removed parameter element or null if not found.     *      This is actually a StructureDocument of type "Param".     */    public StructuredDocument removeServiceParam(ID key) {        Element param = (Element) serviceParams.remove(key);        if (param == null) {            return null;        }                incModCount();                       return StructuredDocumentUtils.copyAsDocument(param);    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -