Project JXTA

net.jxta.id
Class IDFactory

java.lang.Object
  |
  +--net.jxta.util.ClassFactory
        |
        +--net.jxta.id.IDFactory

public final class IDFactory
extends ClassFactory

A factory class for constructing ID instances from external representations such as strings or URIs and for constructing new ID instances.

Since:
JXTA 1.0
Version:
$Revision: 1.23 $
See Also:
ClassFactory, ID

Inner Class Summary
static interface IDFactory.Instantiator
          Interface for instantiators of IDs
 
Method Summary
static ID fromURL(java.net.URL source)
          Construct a new ID instance from a JXTA ID contained in a URI.
protected  java.util.Hashtable getAssocTable()
          Used by ClassFactory methods to get the mapping of ID types to constructors.
protected  java.lang.Class getClassForKey()
          Used by ClassFactory methods to ensure that all keys used with the mapping are of the correct type.
protected  java.lang.Class getClassOfInstantiators()
          Used by ClassFactory methods to ensure that all of the instance classes which register with this factory have the correct base class
static java.net.URL jxtaURL(java.lang.String uri)
          This method should be used instead of "new java.net.URL( )" when constructing JXTA URI, this avoid the system classLoader from failing to load the JXTA urn Handler, in env.
static java.net.URL jxtaURL(java.lang.String protocol, java.lang.String host, java.lang.String file)
          This method should be used instead of "new java.net.URL( )" when constructing JXTA URI, this avoid the system classLoader from failing to load the JXTA urn Handler, in env.
static CodatID newCodatID(PeerGroupID groupID)
          Creates a new CodatID Instance.
static CodatID newCodatID(PeerGroupID groupID, java.io.InputStream in)
          Creates a new CodatID Instance.
static ModuleClassID newModuleClassID()
          Creates a new ModuleClassID Instance.
static ModuleClassID newModuleClassID(ModuleClassID baseClass)
          Creates a new ModuleClassID Instance.
static ModuleSpecID newModuleSpecID(ModuleClassID baseClass)
          Creates a new ModuleClassID Instance.
static PeerGroupID newPeerGroupID()
          Creates a new PeerGroupID Instance.
static PeerID newPeerID(PeerGroupID groupID)
          Creates a new PeerID Instance.
static PipeID newPipeID(PeerGroupID groupID)
          Creates a new PipeID Instance.
static PipeID newPipeID(PeerGroupID groupID, byte[] seed)
          Creates a new PipeID Instance.
protected  boolean registerAssoc(java.lang.String className)
          Register a class with the factory from its class name.
static boolean registerIDType(int type, java.lang.Class instanceClass)
          Register a constructor for an ID type to enable IDs of that type to be constructed.
 
Methods inherited from class net.jxta.util.ClassFactory
getAvailableKeys, getInstantiator, registerAssoc, registerFromResources, registerFromString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getAssocTable

protected java.util.Hashtable getAssocTable()
Used by ClassFactory methods to get the mapping of ID types to constructors.
Overrides:
getAssocTable in class ClassFactory
Returns:
Hashtable the hashtable containing the mappings.
Since:
JXTA 1.0

getClassForKey

protected java.lang.Class getClassForKey()
Used by ClassFactory methods to ensure that all keys used with the mapping are of the correct type.
Overrides:
getClassForKey in class ClassFactory
Returns:
Class object of the key type.
Since:
JXTA 1.0

getClassOfInstantiators

protected java.lang.Class getClassOfInstantiators()
Used by ClassFactory methods to ensure that all of the instance classes which register with this factory have the correct base class
Overrides:
getClassOfInstantiators in class ClassFactory
Returns:
Class object of the key type.
Since:
JXTA 1.0

registerAssoc

protected boolean registerAssoc(java.lang.String className)
Register a class with the factory from its class name. We override the standard implementation to get the id type from the class and use that as the key to register the class with the factory.
Overrides:
registerAssoc in class ClassFactory
Parameters:
className - The class name which will be regiestered.
Returns:
boolean true if the class was registered otherwise false.
Since:
JXTA 1.0

registerIDType

public static boolean registerIDType(int type,
                                     java.lang.Class instanceClass)
Register a constructor for an ID type to enable IDs of that type to be constructed.
Parameters:
type - the identifying value for this id format
instanceClass - the Instantiator to use in constructing objects of this ID format.
Returns:
true if the ID format is registered. If there is already a constructor for this format then false will be returned.
Since:
JXTA 1.0

fromURL

public static ID fromURL(java.net.URL source)
                  throws java.net.MalformedURLException,
                         java.net.UnknownServiceException
Construct a new ID instance from a JXTA ID contained in a URI.
Parameters:
source - URI which will be decoded to create a new ID instance.
Returns:
ID containing the new ID instance initialized from the URI.
Throws:
java.net.UnknownServiceException - Is thrown if the URI provided is of a format unrecognized by this JXTA implementation.
java.net.MalformedURLException - Is thrown if the URI provided is not a valid, recognized JXTA URI.
Since:
JXTA 1.0
See Also:
ID, URL

newCodatID

public static CodatID newCodatID(PeerGroupID groupID)
Creates a new CodatID Instance. A new random Codata ID is created for the provided Peer Group. This type of CodatID can be used as a canonical reference for dynamic content.
Parameters:
groupID - the group to which this content will belong.
Returns:
the newly created ID.
Since:
JXTA 1.0
See Also:
CodatID

newCodatID

public static CodatID newCodatID(PeerGroupID groupID,
                                 java.io.InputStream in)
                          throws java.io.IOException
Creates a new CodatID Instance. A new random Codata ID is created for the provided Peer Group and contains a hash value for the Codat data. This type of Codat ID is most appropriate for static content. By including a hash value this form of Codat ID provides greater assurance of the canonical property of IDs. It also allows the document content returned when this ID is used to be verified to ensure it has not been altered.
Parameters:
groupID - The group to which this ID will belong.
in - The InputStream from which the content hash is calculated. The stream is read until EOF and then closed.
Returns:
the newly created ID.
Throws:
java.io.IOException - I/O Error reading document
Since:
JXTA 1.0
See Also:
CodatID

newPeerID

public static PeerID newPeerID(PeerGroupID groupID)
Creates a new PeerID Instance. A new random peer id will be generated. The PeerID will be a member of the provided group.
Parameters:
groupID - the group to which this PeerID will belong.
Returns:
the newly created ID.
Since:
JXTA 1.0
See Also:
PeerID

newPeerGroupID

public static PeerGroupID newPeerGroupID()
Creates a new PeerGroupID Instance. A new random peer group id will be generated.
Returns:
the newly created ID.
Since:
JXTA 1.0
See Also:
PeerGroupID

newPipeID

public static PipeID newPipeID(PeerGroupID groupID)
Creates a new PipeID Instance. A new random pipe id will be generated. The Pipe ID will be a member of the provided group.
Parameters:
groupID - the group to which this Pipe ID will belong.
Returns:
the newly created ID.
Since:
JXTA 1.0
See Also:
PipeID

newPipeID

public static PipeID newPipeID(PeerGroupID groupID,
                               byte[] seed)
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. The seed information should be at least four bytes in length, though longer values are better. This varient of Pipe ID 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 form of Pipe ID should be used sparingly.
Parameters:
groupID - the group to which this Pipe ID will belong.
seed - The seed information which will be used in creating the pipeID.
Returns:
the newly created ID.
Since:
JXTA 1.0
See Also:
PipeID

newModuleClassID

public static ModuleClassID newModuleClassID()
Creates a new ModuleClassID Instance. A new random Module Class Id will be generated with a zero value role identifier. This form of Module Class Id is appropriate for cases where the module does not need to be distinguished from other instances of the same Module.
Returns:
the newly created ID.
Since:
JXTA 1.0
See Also:
ModuleClassID

newModuleClassID

public static ModuleClassID newModuleClassID(ModuleClassID baseClass)
Creates a new ModuleClassID Instance. A new random Module Class Id will be generated with a a random value role identifier and a base class of the provided Module Class ID. This form of Module Class Id is appropriate for cases where it is necessary to distinguish instances of the same service interface.
Parameters:
baseClass - The module class ID which will be used as a base class for this new role value instance.
Returns:
the newly created ID.
Since:
JXTA 1.0
See Also:
ModuleClassID

newModuleSpecID

public static ModuleSpecID newModuleSpecID(ModuleClassID baseClass)
Creates a new ModuleClassID Instance. A new random Module Spec Id will be generated.
Parameters:
baseClass - The module class ID which will be used as a base class for this new Spec ID.
Returns:
the newly created ID.
Since:
JXTA 1.0
See Also:
ModuleSpecID

jxtaURL

public static java.net.URL jxtaURL(java.lang.String protocol,
                                   java.lang.String host,
                                   java.lang.String file)
                            throws java.net.MalformedURLException
This method should be used instead of "new java.net.URL( )" when constructing JXTA URI, this avoid the system classLoader from failing to load the JXTA urn Handler, in env. such as web-server, or web start where a user class loader is used to load all jxta resources
Parameters:
protocol - the name of the protocol to use.
host - the name of the host.
port - the port number on the host.
file - the file on the host
Returns:
JXTA URI
Throws:
java.net.MalformedURLException - if an unknown protocol is specified.

jxtaURL

public static java.net.URL jxtaURL(java.lang.String uri)
                            throws java.net.MalformedURLException
This method should be used instead of "new java.net.URL( )" when constructing JXTA URI, this avoid the system classLoader from failing to load the JXTA urn Handler, in env. such as web-server, or web start where a user class loader is used to load all jxta resources
Parameters:
spec - the String to parse as a URL.
Returns:
JXTA URI
Throws:
java.net.MalformedURLException - if an unknown protocol is specified.

Project JXTA