Package org.alfresco.util.registry
Class NamedObjectRegistry<T>
- java.lang.Object
-
- org.alfresco.util.registry.NamedObjectRegistry<T>
-
@AlfrescoPublicApi public class NamedObjectRegistry<T> extends java.lang.Object
An generic registry of objects held by name. This is effectively a strongly-typed, synchronized map.- Since:
- 3.2
- Author:
- Derek Hulley
-
-
Constructor Summary
Constructors Constructor Description NamedObjectRegistry()
Default constructor.NamedObjectRegistry(java.lang.Class<T> type)
Constructor that takes care ofsetStorageType(Class)
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.Map<java.lang.String,T>
getAllNamedObjects()
T
getNamedObject(java.lang.String name)
Get a named object if it has been registeredvoid
register(java.lang.String name, T object)
Register a named object instance.void
reset()
void
setNamePattern(java.lang.String namePattern)
Optionally set a pattern to which all object names must conformvoid
setStorageType(java.lang.Class<T> clazz)
Set the type of class that the registry holds.
-
-
-
Constructor Detail
-
NamedObjectRegistry
public NamedObjectRegistry()
Default constructor. ThesetStorageType(Class)
method must be called.
-
NamedObjectRegistry
public NamedObjectRegistry(java.lang.Class<T> type)
Constructor that takes care ofsetStorageType(Class)
.- See Also:
setStorageType(Class)
-
-
Method Detail
-
setStorageType
public void setStorageType(java.lang.Class<T> clazz)
Set the type of class that the registry holds. Any attempt to register a an instance of another type will be rejected.- Parameters:
clazz
- the type to store
-
setNamePattern
public void setNamePattern(java.lang.String namePattern)
Optionally set a pattern to which all object names must conform- Parameters:
namePattern
- a regular expression
-
register
public void register(java.lang.String name, T object)
Register a named object instance.- Parameters:
name
- the name of the objectobject
- the instance to register, which correspond to the type
-
getNamedObject
public T getNamedObject(java.lang.String name)
Get a named object if it has been registered- Parameters:
name
- the name of the object to retrieve- Returns:
- Returns the instance of the object, which will necessarily be of the correct type, or null
-
getAllNamedObjects
public java.util.Map<java.lang.String,T> getAllNamedObjects()
- Returns:
- Returns a copy of the map of instances
-
reset
public void reset()
-
-