📄 advcooker.java
字号:
/************************************************************************ * * $Id: AdvCooker.java,v 1.9 2006/02/22 01:29:47 bondolo Exp $ * * Copyright (c) 2001 Sun Microsystems, Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Sun Microsystems, Inc. for Project JXTA." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "Sun", "Sun Microsystems, Inc.", "JXTA" and "Project JXTA" * must not be used to endorse or promote products derived from this * software without prior written permission. For written * permission, please contact Project JXTA at http://www.jxta.org. * * 5. Products derived from this software may not be called "JXTA", * nor may "JXTA" appear in their name, without prior written * permission of Sun. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL SUN MICROSYSTEMS OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of Project JXTA. For more * information on Project JXTA, please see * <http://www.jxta.org/>. * * This license is based on the BSD license adopted by the Apache Foundation. *********************************************************************************/package net.jxta.impl.util;import java.net.URI;import java.net.URISyntaxException;import java.util.HashMap;import java.util.Iterator;import java.util.Map;import net.jxta.document.AdvertisementFactory;import net.jxta.document.Element;import net.jxta.document.MimeMediaType;import net.jxta.document.StructuredDocument;import net.jxta.document.StructuredDocumentFactory;import net.jxta.document.StructuredTextDocument;import net.jxta.document.TextElement;import net.jxta.id.IDFactory;import net.jxta.peergroup.PeerGroup;import net.jxta.platform.ModuleClassID;import net.jxta.platform.ModuleSpecID;import net.jxta.protocol.ModuleClassAdvertisement;import net.jxta.protocol.ModuleImplAdvertisement;import net.jxta.protocol.ModuleSpecAdvertisement;import net.jxta.protocol.PipeAdvertisement;import net.jxta.impl.peergroup.StdPeerGroup;import net.jxta.impl.peergroup.StdPeerGroupParamAdv;/** * Advertisements and ID's "cooked" according to recipes lifted * from J-C and Frog. Static methods meant for convenience in developing * experimental propagation modules (pipe or rendezvous services, * rendezvous managers) but maybe generally useful. * * @author vasha */public class AdvCooker { /** * Reconstructs a ModuleClassID from its String representation * as printed by the foregoing recipes. * * @param url -- the module class id in String form, "urn:jxta:uuid-[the big hex string]" * @throws MalformedURLException -- if url is messed up * @throws UnknownServiceException --if urn: isn't supported, meaning a jar is missing * @return -- module class id reconstructed from String */ private static ModuleClassID buildModuleClassID(String uri) throws URISyntaxException { return (ModuleClassID)IDFactory.fromURI(new URI(uri)); } /** Reconstructs a ModuleSpecID from its String representation * as printed by the foregoing recipes. * * @param url -- the module spec id in String form, "urn:jxta:uuid-[the big hex string]" * @throws MalformedURLException -- if url is messed up * @throws UnknownServiceException --if urn: isn't supported, meaning a jar is missing * @return -- module spec id reconstructed from String */ private static ModuleSpecID buildModuleSpecID(String uri) throws URISyntaxException { return (ModuleSpecID)IDFactory.fromURI(new URI(uri)); } /** * The module class advertisement is to simply advertise the * existence of a module. * * @param mcid -- the module class id * @param serviceName -- something like "JXTAMOD:JXTA-WIRE-MyNewThing" * @param serviceDescription -- something like "JXTA-WIRE MyNewThing Module" * @return an appropriate ModuleClassAdvertisement */ public static ModuleClassAdvertisement buildModuleClassAdvertisement( ModuleClassID mcid, String serviceName, String serviceDescription){ ModuleClassAdvertisement mcadv = (ModuleClassAdvertisement) AdvertisementFactory.newAdvertisement( ModuleClassAdvertisement.getAdvertisementType()); mcadv.setName(serviceName); mcadv.setDescription(serviceDescription); mcadv.setModuleClassID(mcid); return mcadv; } /** * The ModuleSpecAdvertisement has two purposes, to publish * the uri of its formal specs for developers and to publish the * means of remote access to the module's services if that * is appropriate. (See {@link ModuleSpecAdvertisement} ) * Use this form for a minimal advertisement, suitable * for development. * * @param msid -- the module spec id, "urn:jxta:uuid-[the big hex string]" * @param moduleSpecName -- something like "JXTASPEC:JXTA-WIRE-MyNewThing-SPEC" * @param moduleSpecDescription -- something like "JXTA-WIRE MyNewThing Specification" * @return -- a boilerplate suitable for development. */ public static ModuleSpecAdvertisement buildModuleSpecAdvertisement( ModuleSpecID msid, String moduleSpecName, String moduleSpecDescription){ return buildModuleSpecAdvertisement( msid, moduleSpecName, moduleSpecDescription, null, null, null, null, null, null, null); } /** * Use this form for production provided remote access is not required. * * @param msid -- the module spec id, "urn:jxta:uuid-[the big hex string]" * @param moduleSpecName -- something like "JXTASPEC:JXTA-WIRE-MyNewThing-SPEC" * @param moduleSpecDescription -- something like "JXTA-WIRE MyNewThing Specification" * @param creator -- something like "jxta.org" * @param version -- something like "Version 1.0" * @param specURI -- where to locate the formal specs, e.g. "http://www.jxta.org/MyNewThing" * @return -- a fully populated advert suitable if remote access is not required. */ public static ModuleSpecAdvertisement buildModuleSpecAdvertisement( ModuleSpecID msid, String moduleSpecName, String moduleSpecDescription, String creator, String version, String specURI){ return buildModuleSpecAdvertisement( msid, moduleSpecName, moduleSpecDescription, creator, version, specURI, null, null, null, null); } /** * Use this form for a fully populated advert. * * @param msid -- the module spec id, "urn:jxta:uuid-[the big hex string]" * @param moduleSpecName -- something like "JXTASPEC:JXTA-WIRE-MyNewThing-SPEC" * @param moduleSpecDescription -- something like "JXTA-WIRE MyNewThing Specification" * @param creator -- something like "jxta.org" * @param version -- something like "Version 2.0" * @param specURI -- where to locate the formal specs, e.g. "http://www.jxta.org/MyNewThing" * @param pipeAdv -- to make the module useable remotely (see {@link ModuleSpecAdvertisement}) * @param proxySpecID -- sometimes required for remote use (see {@link ModuleSpecAdvertisement}) * @param authorizationSpecID -- sometimes required for remote use (see {@link ModuleSpecAdvertisement}) * @param param -- anything else * @return -- a fully populated advert specifying remote access to module services. */ public static ModuleSpecAdvertisement buildModuleSpecAdvertisement( ModuleSpecID msid, String moduleSpecName, String moduleSpecDescription, String creator, String version, String specURI, PipeAdvertisement pipeAdv, ModuleSpecID proxySpecID, ModuleSpecID authorizationSpecID, StructuredDocument param){ ModuleSpecAdvertisement msadv = (ModuleSpecAdvertisement) AdvertisementFactory.newAdvertisement( ModuleSpecAdvertisement.getAdvertisementType()); msadv.setModuleSpecID(msid); msadv.setName(moduleSpecName); msadv.setDescription(moduleSpecDescription); msadv.setCreator( creator == null ? "jxta.org" : creator); msadv.setVersion( version == null ? "Version 2.0" : version); msadv.setSpecURI( specURI == null ? "http://www.jxta.org/" + moduleSpecName : specURI); if(pipeAdv != null)msadv.setPipeAdvertisement(pipeAdv); if(proxySpecID != null)msadv.setProxySpecID(proxySpecID); if(authorizationSpecID != null)msadv.setAuthSpecID(authorizationSpecID); if(param != null)msadv.setParam(param); return msadv; } /** * Compat's (compatibility statements) serve to narrow the search * for a ModuleImplAdvertisement. Basically you want something * compatible with your group's implementation. Use this form for * compatibilty with the current StdPeerGroup. * * @return -- boilerplate compat for StdPeerGroup */ public static StructuredTextDocument buildCompat() { try{ // try to remain current with StdPeerGroup: return (StructuredTextDocument) StructuredDocumentFactory.newStructuredDocument( StdPeerGroup.STD_COMPAT.getMimeType(), StdPeerGroup.STD_COMPAT.getStream()); } catch (Exception e){ // but if it doesn't work default to Nov 21 2001. return buildCompat("JDK1.4.1", "V2.0 Ref Impl"); } } /** * Use this form for customized compatibility statements. * Alternatively a group's compat is accessible via * group.getCompat() * * @param efmt -- something like "JDK1.4" * @param bind -- something like "V1.0 Ref Impl" * @return -- custom compatibility tag */ public static StructuredTextDocument buildCompat(String efmt, String bind) { StructuredTextDocument doc = (StructuredTextDocument) StructuredDocumentFactory.newStructuredDocument( MimeMediaType.XMLUTF8, "Comp"); Element e = doc.createElement("Efmt", efmt ); doc.appendChild(e);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -