idfactory.java
来自「JXTA™ is a set of open, generalize」· Java 代码 · 共 1,211 行 · 第 1/4 页
JAVA
1,211 行
* generated using the provided seed information. The PeerGroupID will * be created using the default ID Format. * * <p/>This method allows you to create "Well-known" PeerGroupIDs. * This is similar to how the JXTA "World Peer Group" and "Net * Peer Group". "Well-known" IDs can be useful for common services * that need to do discovery without advertisements or for network * organization services. Because of the potential for ID collisions * and the difficulties with maintaining common service interfaces this * variant of PeerGroupID should be used with great caution and * pre-planning. * * @see net.jxta.peergroup.PeerGroup * * @param seed The seed information which will be used in creating the * PeerGroupID. The seed information should be at least four bytes in * length, though longer values are better. * @return The newly created PeerGroupID. */ public PeerGroupID newPeerGroupID(byte[] seed); /** * Creates a new PeerGroupID instance with the specified parent group. * A new random peer group id will be generated. * * @see net.jxta.peergroup.PeerGroup * * @param parent The group which will be the parent of this group. * @return The newly created PeerGroupID. */ public PeerGroupID newPeerGroupID(PeerGroupID parent); /** * Creates a new PeerGroupID instance with the specified parent group. * A new PeerGroupID will be generated using the provided seed * information. * * <p/>This method allows you to create "Well-known" PeerGroupIDs. * This is similar to how the JXTA "World Peer Group" and "Net * Peer Group". "Well-known" IDs can be useful for common services * that need to do discovery without advertisements or for network * organization services. Because of the potential for ID collisions * and the difficulties with maintaining common service interfaces this * variant of PeerGroupID should be used with great caution and * pre-planning. * * @see net.jxta.peergroup.PeerGroup * * @param parent The group which will be the parent of this group. * @param seed The seed information which will be used in creating the * PeerGroupID. The seed information should be at least four bytes in * length, though longer values are better. * @return The newly created PeerGroupID. */ public PeerGroupID newPeerGroupID(PeerGroupID parent, byte[] seed); /** * Creates a new PipeID instance. A new random PipeID will be generated. * * * @param groupID The group to which this Pipe ID will belong. * @return The newly created PipeID. */ public PipeID newPipeID(PeerGroupID groupID); /** * Creates a new PipeID instance. A new pipe id will be generated with * the provided seed information. The Pipe ID will be a member of the * provided group. * * <p/>This variant of PipeID allows you to create "Well-known" pipes * within the context of diverse groups. This can be useful for common * services that need to do discovery without advertisements or for * network organization services. Because of the potential for ID * collisions and the difficulties with maintaining common service * interfaces this variant of PipeID should be used with great caution * and pre-planning. * * * @param groupID the group to which this Pipe ID will belong. * @param seed The seed information which will be used in creating the * pipeID. The seed information should be at least four bytes in * length, though longer values are better. * @return the newly created PipeID. */ public PipeID newPipeID(PeerGroupID groupID, byte[] seed); /** * Creates a new ModuleClassID instance. A new random ModuleClassID * will be generated with a zero value role identifier. This form of * ModuleClassID is appropriate for cases where the module does not * need to be distinguished from other instances of the same Module. * The ModuleClassID will be created using the default ID Format. * * @see net.jxta.platform.Module * * @return The newly created ModuleClassID. */ public ModuleClassID newModuleClassID(); /** * Creates a new ModuleClassID instance. A new random ModuleClassID * will be generated with a a random value role identifier and a base * class of the provided ModuleClassID. This form of ModuleClassID is * appropriate for cases where it is necessary to distinguish instances * of the same service interface. * * @see net.jxta.platform.Module * * @param baseClass The ModuleClassID which will be used as a base * class for this new role value instance. * @return The newly created ModuleClassID. */ public ModuleClassID newModuleClassID(ModuleClassID baseClass); /** * Creates a new ModuleSpecID instance. A new random ModuleSpecID will * be generated. * * @see net.jxta.platform.Module * * @param baseClass The ModuleClassID which will be used as a base * class for this new ModuleSpecID. * @return The newly created ModuleSpecID. */ public ModuleSpecID newModuleSpecID(ModuleClassID baseClass); } /** * @deprecated This interface formerly contained optional URI based * construction methods. These have now been moved to the primary * instantiator interface in preparation for the removal of the URL * based interfaces. This interface will be removed in a future release. */ @Deprecated public interface URIInstantiator extends Instantiator {} /** * Standard Constructor. This class is a singleton so the only constructor * is private. * * <p/>Uses net.jxta.impl.config.properties file as the * source for settings. * * <p/>Example entry from the file net.jxta.impl.config.properties : * * <p/><pre><code> * #Default type of ID to use when creating an ID (this should not be changed in most implementations). * IDNewInstances=uuid * </code></pre> */ private IDFactory() { // required format registerAssoc("net.jxta.id.jxta.IDFormat"); // required by this implementation. registerAssoc("net.jxta.impl.id.unknown.IDFormat"); // Register a list of classes for association with an ID format registerProviders(ID.class.getName()); try { // Get our resource bundle ResourceBundle jxtaRsrcs = ResourceBundle.getBundle("net.jxta.impl.config"); // set the default ID Format. idNewInstances = jxtaRsrcs.getString("IDNewInstances").trim(); } catch (MissingResourceException notFound) { // This is an error because we can't start without a concept of ID. IllegalStateException failure = new IllegalStateException("Could not initialize ID defaults", notFound); LOG.log(Level.SEVERE, "Cound not initialize IDFactory", failure); throw failure; } } /** * Used by ClassFactory methods to get the mapping of ID types to constructors. * * @return the mapping of ID types to instantiators. */ @Override protected Map<String, Instantiator> getAssocTable() { return idFormats; } /** * Used by ClassFactory methods to ensure that all keys used with the mapping are * of the correct type. * * @return Class object of the key type. */ @Override protected Class<String> getClassForKey() { return String.class; } /** * Used by ClassFactory methods to ensure that all of the instance classes * which register with this factory have the correct base class * * @return Class object of the key type. */ @Override protected Class<Instantiator> getClassOfInstantiators() { return Instantiator.class; } /** * Register a class with the factory from its class name. We override the * standard implementation to get the id format from the class and * use that as the key to register the class with the factory. * * @param className The class name which will be registered. * @return boolean true if the class was registered otherwise false. */ @Override public boolean registerAssoc(String className) { boolean registeredSomething = false; try { Class<?> idClass; try { idClass = Class.forName(className); if (null == idClass) { throw new ClassNotFoundException("forName() result was null"); } } catch (ClassNotFoundException notThere) { LOG.severe("Could not find class named : " + className); return false; } catch (NoClassDefFoundError notThere) { LOG.severe("Could not find class named : " + className); return false; } Field instantiatorField; try { instantiatorField = idClass.getField("INSTANTIATOR"); if (null == instantiatorField) { throw new NoSuchFieldException("getField() result was null for field 'INSTANTIATOR'"); // caught locally } } catch (NoSuchFieldException notThere) { LOG.severe("Could not find INSTANTIATOR field in class named : " + className); return false; } if (!Instantiator.class.isAssignableFrom(instantiatorField.getType())) { throw new ClassCastException("INSTANTIATOR is not of type " + Instantiator.class.getName()); } Instantiator instantiator = (Instantiator) instantiatorField.get(null); if (null == instantiator) { LOG.severe("INSTANTIATOR field is null for class : " + className); return false; } String idFormat = instantiator.getSupportedIDFormat(); registeredSomething = registerAssoc(idFormat, instantiator); } catch (Exception failed) { LOG.log(Level.SEVERE, "Failed to register class : " + className, failed); } return registeredSomething; } /** * Returns a String containing the name of the default ID Format. * * @return The current default ID Format. */ public static String getDefaultIDFormat() { return factory.idNewInstances; } /** * Construct a new ID instance from a JXTA ID contained in a URI. * * @param source URI which will be decoded to create a new ID instance. * @return ID containing the new ID instance initialized from the URI. * @throws URISyntaxException If the URI provided is not a valid, * recognized JXTA URI. */ public static ID fromURI(URI source) throws URISyntaxException { ID result = null; // check the protocol if (!ID.URIEncodingName.equalsIgnoreCase(source.getScheme())) { throw new URISyntaxException(source.toString(), "URI scheme was not as expected."); } String decoded = source.getSchemeSpecificPart(); int colonAt = decoded.indexOf(':'); // There's a colon right?
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?