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

📄 advertisementutilities.java

📁 JXTA&#8482 is a set of open, generalized peer-to-peer (P2P) protocols that allow any networked devi
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
     * @param xmlText The source of the advertisement     * @return The Advertisement     * @throws JxtaException if Unable to parse the Advertisement     * @deprecated This method should not be used because it interprets the     *             input using the local default encoding which is not precidcatable and     *             may (will) differ from JVM to JVM.     */    @Deprecated    public static Advertisement newAdvertisementFromXml(String xmlText) throws JxtaException {        try {            return AdvertisementFactory.newAdvertisement(MimeMediaType.XML_DEFAULTENCODING, new StringReader(xmlText));        } catch (Exception e) {            throw new JxtaException("Unable to create Advertisement from the provided XML", e);        }    }    /**     * Create a Pipe Advertisement     *     * @return A new Pipe Advertisement     */    public static PipeAdvertisement createPipeAdvertisement() {        return (PipeAdvertisement) AdvertisementFactory.newAdvertisement(PipeAdvertisement.getAdvertisementType());    }    /**     * Create a Pipe Advertisement     *     * @param pipeId   The pipe ID     * @param pipeType The type of the Pipe     * @return A new Pipe Advertisement     */    public static PipeAdvertisement createPipeAdvertisement(PipeID pipeId, String pipeType) {        PipeAdvertisement pipeAdvertisement = (PipeAdvertisement) AdvertisementFactory.newAdvertisement(                PipeAdvertisement.getAdvertisementType());        pipeAdvertisement.setPipeID(pipeId);        pipeAdvertisement.setType(pipeType);        return pipeAdvertisement;    }    /**     * Create a Pipe Advertisement     *     * @param pipeIdText The pipe ID     * @param pipeType   The type of the Pipe     * @return A new Pipe Advertisement     */    public static PipeAdvertisement createPipeAdvertisement(String pipeIdText, String pipeType) throws JxtaException {        PipeID pipeId;        try {            pipeId = (PipeID) IDFactory.fromURI(new URI(pipeIdText));        } catch (URISyntaxException failed) {            IllegalArgumentException failure = new IllegalArgumentException("Bad pipe id");            failure.initCause(failed);            throw failure;        }        PipeAdvertisement pipeAdvertisement = (PipeAdvertisement) AdvertisementFactory.newAdvertisement(                PipeAdvertisement.getAdvertisementType());        pipeAdvertisement.setPipeID(pipeId);        pipeAdvertisement.setType(pipeType);        return pipeAdvertisement;    }    /**     * Create a Pipe Advertisement     *     * @param root Element containing a Pipe Advertisement     * @return A new Pipe Advertisement     */    public static PipeAdvertisement createPipeAdvertisement(Element root) {        TextElement pipeAdvElement = (TextElement) DocumentUtilities.getChild(root, PipeAdvertisement.getAdvertisementType());        if (pipeAdvElement == null) {            return null;        }        return (PipeAdvertisement) AdvertisementFactory.newAdvertisement(pipeAdvElement);    }    /**     * Create a Pipe Advertisement     *     * @param peerGroup The peerGroup     * @param pipeType  The pipeType     * @return A new Pipe Advertisement     */    public static PipeAdvertisement createPipeAdvertisement(PeerGroup peerGroup, String pipeType) {        PipeID pipeID = IDFactory.newPipeID(peerGroup.getPeerGroupID());        return createPipeAdvertisement(pipeID, pipeType);    }    /**     * Create a Pipe Advertisement     *     * @param pipeID   The pipeID     * @param pipeType The pipeType     * @return A new Pipe Advertisement     */    public static PipeAdvertisement createPipeAdvertisement(ID pipeID, String pipeType) {        PipeAdvertisement pipeAdvertisement = createPipeAdvertisement();        pipeAdvertisement.setPipeID(pipeID);        pipeAdvertisement.setType(pipeType);        return pipeAdvertisement;    }    /**     * Create a Pipe Advertisement     *     * @param peerGroup The peerGroup     * @param pipeType  The pipeType     * @param name      The Pime Name     * @return A new Pipe Advertisement     */    public static PipeAdvertisement createPipeAdvertisement(PeerGroup peerGroup, String sPipeID, String pipeType, String name) throws JxtaException {        PipeAdvertisement pipeAdvertisement = createPipeAdvertisement(peerGroup, pipeType);        PipeID pipeId;        try {            pipeId = (PipeID) IDFactory.fromURI(new URI(sPipeID));        } catch (URISyntaxException failed) {            IllegalArgumentException failure = new IllegalArgumentException("Bad pipe id");            failure.initCause(failed);            throw failure;        }        pipeAdvertisement.setPipeID(pipeId);        if (name != null) {            pipeAdvertisement.setName(name);        }        return pipeAdvertisement;    }    /**     * Create a Pipe Advertisement     *     * @param root The Root element containing the Advertisement     * @return A new Pipe Advertisement     * @deprecated These utilities are too specialized for general use.     */    @Deprecated    public static PipeAdvertisement getPipeAdvertisement(Element root) {        TextElement pipeAdvElement = (TextElement) DocumentUtilities.getChild(root, PipeAdvertisement.getAdvertisementType());        if (pipeAdvElement == null) {            return null;        }        return (PipeAdvertisement) AdvertisementFactory.newAdvertisement(pipeAdvElement);    }    /**     * Create a Peer Advertisement     *     * @param root The Root element containing the Advertisement     * @return A new Peer Advertisement     * @deprecated These utilities are too specialized for general use.     */    @Deprecated    public static PeerAdvertisement getPeerAdvertisement(Element root) {        TextElement peerAdvElement = (TextElement) DocumentUtilities.getChild(root, PeerAdvertisement.getAdvertisementType());        if (peerAdvElement == null) {            return null;        }        return (PeerAdvertisement) AdvertisementFactory.newAdvertisement(peerAdvElement);    }    /**     * Create a ModuleClassAdvertisement     *     * @param name        The name     * @param description The description     * @return An ModuleClassAdvertisement     */    public static ModuleClassAdvertisement createModuleClassAdvertisement(String name, String description) {        String moduleClassAdvertisementType = ModuleClassAdvertisement.getAdvertisementType();        ModuleClassAdvertisement moduleClassAdvertisement = (ModuleClassAdvertisement) AdvertisementFactory.newAdvertisement(                moduleClassAdvertisementType);        moduleClassAdvertisement.setName(name);        moduleClassAdvertisement.setDescription(description);        ModuleClassID mcID = IDFactory.newModuleClassID();        moduleClassAdvertisement.setModuleClassID(mcID);        return moduleClassAdvertisement;    }    /**     * Create a ModuleSpecAdvertisement     *     * @param name  The name     * @param param The param     * @return An ModuleSpecAdvertisement     * @deprecated This implementation incompletely initializes the module     *             spec advertisement. Consider creating Module Spec Advertisements without     *             this method.     */    @Deprecated    public static ModuleSpecAdvertisement createModuleSpecAdvertisement(String name, StructuredDocument param) {        return createModuleSpecAdvertisement(name, null, param);    }    /**     * Create a ModuleSpecAdvertisement     *     * @param name                     The name     * @param moduleClassAdvertisement The moduleClassAdvertisement     * @param param                    The param     * @return An ModuleSpecAdvertisement     * @deprecated This implementation incompletely initializes the module     *             spec advertisement. Consider creating Module Spec Advertisements without     *             this method.     */    @Deprecated    public static ModuleSpecAdvertisement createModuleSpecAdvertisement(String name, ModuleClassAdvertisement moduleClassAdvertisement, StructuredDocument param) {        String moduleSpecAdvertisementType = ModuleSpecAdvertisement.getAdvertisementType();        ModuleSpecAdvertisement moduleSpecAdvertisement = (ModuleSpecAdvertisement) AdvertisementFactory.newAdvertisement(                moduleSpecAdvertisementType);        moduleSpecAdvertisement.setName(name);        moduleSpecAdvertisement.setVersion("Unknown");        moduleSpecAdvertisement.setCreator("Unknown");        if (moduleClassAdvertisement != null) {            ModuleClassID moduleClassID = moduleClassAdvertisement.getModuleClassID();            moduleSpecAdvertisement.setModuleSpecID(IDFactory.newModuleSpecID(moduleClassID));        }        moduleSpecAdvertisement.setSpecURI("Unknown");        if (param != null) {            moduleSpecAdvertisement.setParam(param);        }        return moduleSpecAdvertisement;    }    /**     * Publish and advertisement to the Cache     *     * @param peerGroup         The peerGroup     * @param peerAdvertisement The Advertisement     * @throws JxtaException if Unable to cache the Advertisement     */    public static void cachePeerAdvertisement(PeerGroup peerGroup, PeerAdvertisement peerAdvertisement) throws JxtaException {        cachePeerAdvertisement(peerGroup, peerAdvertisement, DiscoveryService.DEFAULT_EXPIRATION                ,                DiscoveryService.DEFAULT_EXPIRATION);    }    private static void cachePeerAdvertisement(PeerGroup peerGroup, PeerAdvertisement peerAdvertisement, long lifetime, long lifetimeForOthers) throws JxtaException {        try {            DiscoveryService discoveryService = peerGroup.getDiscoveryService();            if (peerAdvertisement.getPeerID().equals(peerGroup.getPeerID())) {                return;            }            // no reason to persist our own peer ID            discoveryService.publish(peerAdvertisement, lifetime, lifetimeForOthers);        } catch (IOException e) {            throw new JxtaException("Unable to cache advertisement", e);        }    }    /**     * Create a ModuleImplAdvertisement     *     * @param specID      The specID     * @param code        The code     * @param description the advertisement description     * @return An ModuleImplAdvertisement     * @deprecated This implementation initializes some fields of the     *             resulting ModuleImplAdvertisement to constant values who's value may     *             not be correct for all circumstances. Consider creating ModuleImpl     *             Advertisements directly in your application.     */    @Deprecated    public static ModuleImplAdvertisement createModuleImplAdvertisement(ModuleSpecID specID, String code, String description) {        ModuleImplAdvertisement moduleImplAdvertisement = (ModuleImplAdvertisement)                AdvertisementFactory.newAdvertisement(ModuleImplAdvertisement.getAdvertisementType());        moduleImplAdvertisement.setModuleSpecID(specID);        moduleImplAdvertisement.setCompat(STANDARD_COMPATABILITY);        moduleImplAdvertisement.setCode(code);        moduleImplAdvertisement.setUri(STANDARD_URI);        moduleImplAdvertisement.setProvider(STANDARD_PROVIDER);        moduleImplAdvertisement.setDescription(description);        return moduleImplAdvertisement;    }}

⌨️ 快捷键说明

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