com.metamatrix.core.id
Class IDGenerator

java.lang.Object
  extended by com.metamatrix.core.id.IDGenerator

public class IDGenerator
extends java.lang.Object

IDGenerator


Constructor Summary
IDGenerator()
           
 
Method Summary
 void addBuiltInFactories()
          Method that creates and adds to this generator all the built-in factories, and if there is no default factory, set the default factory to the UUIDFactory.
 void addFactory(ObjectIDFactory factory)
          Supply to this generator a new factory for a type of ObjectID.
 ObjectID create()
          Create a new ObjectID using the default factory
 ObjectID create(java.lang.String protocol)
          Create a new ObjectID for the type specified by the protocol
 ObjectIDFactory getDefaultFactory()
          Get the factory that is used by default for the create() method is invoked.
 java.util.Collection getFactories()
          Method to obtain the collection of ObjectIDFactory instances that each describe one of the types of ObjectIDs that are available to this generator.
 ObjectIDFactory getFactory(java.lang.String protocol)
          Method to obtain the collection of ObjectIDFactory instances that each describe one of the types of ObjectIDs that are available to this generator.
static IDGenerator getInstance()
          Obtain the shared instance of this class.
 java.util.Set getProtocols()
          Method to obtain the set of String protocols.
 boolean hasDefaultFactory()
          Return whether there is a factory that is used by default for the create() method is invoked.
 boolean removeFactory(java.lang.String protocol)
          Remove a factory from this generator.
 void setDefaultFactory(ObjectIDFactory factory)
          Set the factory that should be used by default for the create() method is invoked.
 void setDefaultFactory(java.lang.String protocol)
          Set the factory that should be used by default for the create() method is invoked.
 ObjectID stringToObject(java.lang.String id)
          Attempt to convert the specified string to the appropriate ObjectID instance.
 ObjectID stringToObject(java.lang.String id, char delim)
          Attempt to convert the specified string to the appropriate ObjectID instance.
 ObjectID stringToObject(java.lang.String id, java.lang.String protocol)
          Attempt to convert the specified string to the appropriate ObjectID instance.
 java.lang.String toString(ObjectID id)
          Convenience method for obtaining the stringified form of an ObjectID.
 java.lang.String toString(ObjectID id, char delim)
          Convenience method for obtaining the stringified form of an ObjectID.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IDGenerator

public IDGenerator()
Method Detail

getInstance

public static IDGenerator getInstance()
Obtain the shared instance of this class.

Returns:
the statically shared instance of this class.

addBuiltInFactories

public void addBuiltInFactories()
Method that creates and adds to this generator all the built-in factories, and if there is no default factory, set the default factory to the UUIDFactory. This method may be called multiple times without side effect.


addFactory

public void addFactory(ObjectIDFactory factory)
Supply to this generator a new factory for a type of ObjectID. This method has no effect if the factory is null, or if this generator already knows about the factory.

Parameters:
factory - the new factory

removeFactory

public boolean removeFactory(java.lang.String protocol)
Remove a factory from this generator. This method has no effect if the supplied protocol doesn't match the protocol of any descriptor known to this generator.

Parameters:
protocol - the protocol for which the factory is to be removed
Returns:
whether a factory was found and removed for the supplied protocol

getFactories

public java.util.Collection getFactories()
Method to obtain the collection of ObjectIDFactory instances that each describe one of the types of ObjectIDs that are available to this generator.

Returns:
the collection of ObjectIDFactory instances.

getFactory

public ObjectIDFactory getFactory(java.lang.String protocol)
Method to obtain the collection of ObjectIDFactory instances that each describe one of the types of ObjectIDs that are available to this generator.

Returns:
the collection of ObjectIDFactory instances.

getProtocols

public java.util.Set getProtocols()
Method to obtain the set of String protocols. This is a utility that merely obtains the protocols from the factories.

Returns:
the Set of String protocols; never null

hasDefaultFactory

public boolean hasDefaultFactory()
Return whether there is a factory that is used by default for the create() method is invoked.

Returns:
true if there is a default factory, or false otherwise

getDefaultFactory

public ObjectIDFactory getDefaultFactory()
Get the factory that is used by default for the create() method is invoked.

Returns:
the default factory, or null if there is no default factory

setDefaultFactory

public void setDefaultFactory(ObjectIDFactory factory)
Set the factory that should be used by default for the create() method is invoked.

Parameters:
factory - the factory that should be used by default; may be null if no default is to be allowed.

setDefaultFactory

public void setDefaultFactory(java.lang.String protocol)
Set the factory that should be used by default for the create() method is invoked.

Parameters:
protocol - the protocol for factory that should be used by default; may be null if no default is to be allowed.

create

public ObjectID create()
Create a new ObjectID using the default factory

Returns:
the new ObjectID

create

public ObjectID create(java.lang.String protocol)
Create a new ObjectID for the type specified by the protocol

Parameters:
protocol - the protocol of the type of ObjectID to be created; may not be null
Returns:
the new ObjectID

toString

public java.lang.String toString(ObjectID id)
Convenience method for obtaining the stringified form of an ObjectID.

Parameters:
id -
Returns:

toString

public java.lang.String toString(ObjectID id,
                                 char delim)
Convenience method for obtaining the stringified form of an ObjectID.

Parameters:
id -
Returns:

stringToObject

public ObjectID stringToObject(java.lang.String id)
                        throws InvalidIDException
Attempt to convert the specified string to the appropriate ObjectID instance.

Parameters:
id - the stringified id of the form protocol:value, where protocol defines the protocol of the ID, and valueReturns:
the ObjectID instance for the stringified ID
Throws:
InvalidIDException - if the specified string does not contain a valid ObjectID or if the protocol is unknown

stringToObject

public ObjectID stringToObject(java.lang.String id,
                               java.lang.String protocol)
                        throws InvalidIDException
Attempt to convert the specified string to the appropriate ObjectID instance.

Parameters:
id - the stringified id of the form protocol:value, where protocol defines the protocol of the ID, and valueReturns:
the ObjectID instance for the stringified ID
Throws:
InvalidIDException - if the specified string does not contain a valid ObjectID or if the protocol is unknown

stringToObject

public ObjectID stringToObject(java.lang.String id,
                               char delim)
                        throws InvalidIDException
Attempt to convert the specified string to the appropriate ObjectID instance.

Parameters:
id - the stringified id of the form protocol:value, where protocol defines the protocol of the ID, and valueReturns:
the ObjectID instance for the stringified ID
Throws:
InvalidIDException - if the specified string does not contain a valid ObjectID or if the protocol is unknown


Copyright © 2009. All Rights Reserved.