📄 advcooker.java
字号:
/************************************************************************
*
* $Id: AdvCooker.java,v 1.4 2002/06/18 20:46:01 hamada 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 net.jxta.id.IDFactory;
import net.jxta.peergroup.PeerGroupID;
import net.jxta.peergroup.PeerGroup;
import net.jxta.impl.peergroup.StdPeerGroup;
import net.jxta.impl.peergroup.StdPeerGroupParamAdv;
import net.jxta.pipe.PipeID;
import net.jxta.platform.ModuleClassID;
import net.jxta.platform.ModuleSpecID;
import net.jxta.exception.PeerGroupException;
import net.jxta.protocol.*;
import net.jxta.document.*;
import java.net.URL;
import java.util.Hashtable;
import java.util.Enumeration;
/** 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
* @version 1.1
*/
public class AdvCooker {
/** Prints public static String declarations of new module class and
* spec ID's for hardcoding into a module, as per J-C's posted recipe. Use
* this form unless your module is a custom implementation of a
* standard module such as RendezvousServiceImpl.
*/
public static void printNewClassAndModuleID(){
ModuleClassID mcid = IDFactory.newModuleClassID();
ModuleSpecID msid = IDFactory.newModuleSpecID(mcid);
System.out.println("public static final String ClassID = \"" + mcid + "\";");
System.out.println("public static final String SpecID = \"" + msid + "\";");
}
/** Use this form if your module is a custom implementation of a well-known
* module such as RendezvousServiceImpl. The class id's of well-known
* modules are static members of net.jxta.peergroup.PeerGroup, e.g.,
* PeerGroup.rendezvousClassID.
* @param baseClassID --the class ID of the module to customized, e.g.
* that of RendezvousServiceImpl.
*/
public static void printNewClassAndModuleID(ModuleClassID baseClassID){
ModuleClassID mcid = IDFactory.newModuleClassID(baseClassID);
ModuleSpecID msid = IDFactory.newModuleSpecID(mcid);
System.out.println("public static final String ClassID = \"" + mcid + "\";");
System.out.println("public static final String SpecID = \"" + msid + "\";");
}
/** 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
*/
public static ModuleClassID buildModuleClassID(String url)
throws java.net.MalformedURLException, java.net.UnknownServiceException {
return (ModuleClassID)IDFactory.fromURL(IDFactory.jxtaURL(url));
}
/** 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
*/
public static ModuleSpecID buildModuleSpecID(String url)
throws java.net.MalformedURLException, java.net.UnknownServiceException {
return (ModuleSpecID)IDFactory.fromURL(IDFactory.jxtaURL(url));
}
/** 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 ModuleSpecAdvertisement javadocs.)
* 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 1.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 ModuleSpecAdvertisement javadocs)
* @param proxySpecID -- sometimes required for remote use (see ModuleSpecAdvertisement javadocs)
* @param authorizationSpecID -- sometimes required for remote use (see ModuleSpecAdvertisement javadocs)
* @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 1.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.stdCompatStatement.getMimeType(),
StdPeerGroup.stdCompatStatement.getStream());
} catch (Exception e){
// but if it doesn't work default to Nov 21 2001.
return buildCompat("JDK1.4", "V1.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) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -