org.pfsw.db.util
Class DefaultMultiCategoryIdentifierGenerator

java.lang.Object
  extended by org.pfsw.db.util.DefaultMultiCategoryIdentifierGenerator
All Implemented Interfaces:
MultiCategoryIdentifierGenerator

public class DefaultMultiCategoryIdentifierGenerator
extends java.lang.Object
implements MultiCategoryIdentifierGenerator

A default implementation of an identifier generator for multiple categories. The assumption is that an instance of this class gets generated and populated (see register(String, ObjectIdentifierProducer)) with category related ID producers once and then will be used with that setup for ID generation. Registering further ID producers at a later time might cause errors because the underlying ID producer registry is not thread-safe.


Constructor Summary
DefaultMultiCategoryIdentifierGenerator()
           
 
Method Summary
protected  java.util.Map<java.lang.String,ObjectIdentifierProducer> getGeneratorRegistry()
           
protected  ObjectIdentifierProducer getIdProducer(java.lang.String categoryName)
           
protected  org.pfsw.logging.Logger2 log()
           
 java.lang.String newIdentifier(java.lang.String category)
          Returns a new identifier for the given category.
 long nextIdentifier(java.lang.String category)
          Returns a new identifier which is different to the last one for the given category.
protected  java.lang.String normalizeCategory(java.lang.String category)
           
 DefaultMultiCategoryIdentifierGenerator register(java.lang.String categoryName, ObjectIdentifierProducer idProducer)
          Registers the given identifier producer for the specified category.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultMultiCategoryIdentifierGenerator

public DefaultMultiCategoryIdentifierGenerator()
Method Detail

newIdentifier

public java.lang.String newIdentifier(java.lang.String category)
Description copied from interface: MultiCategoryIdentifierGenerator
Returns a new identifier for the given category.

Specified by:
newIdentifier in interface MultiCategoryIdentifierGenerator
Parameters:
category - An arbitrary but unique name for the ID sequence (must not be null).

nextIdentifier

public long nextIdentifier(java.lang.String category)
Description copied from interface: MultiCategoryIdentifierGenerator
Returns a new identifier which is different to the last one for the given category.

Specified by:
nextIdentifier in interface MultiCategoryIdentifierGenerator
Parameters:
category - An arbitrary but unique name for the ID sequence (must not be null).
Returns:
The next ID value.

register

public DefaultMultiCategoryIdentifierGenerator register(java.lang.String categoryName,
                                                        ObjectIdentifierProducer idProducer)
Registers the given identifier producer for the specified category. If the category is null or blank or the ID producer is null, a warning will be logged and nothing registered.

Parameters:
categoryName - The category to register the ID producer under (must not be null or blank).
idProducer - The ID producer to be registered (must not be null).
Returns:
this object.

getIdProducer

protected ObjectIdentifierProducer getIdProducer(java.lang.String categoryName)

normalizeCategory

protected java.lang.String normalizeCategory(java.lang.String category)

log

protected org.pfsw.logging.Logger2 log()

getGeneratorRegistry

protected java.util.Map<java.lang.String,ObjectIdentifierProducer> getGeneratorRegistry()