|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.jpu.patterns.factory.PrototypeFactory
Implementation of IPrototypeFactory
.
Nested Class Summary |
Nested classes inherited from class org.jpu.patterns.factory.IPrototypeFactory |
IPrototypeFactory.IConfigStrategy, IPrototypeFactory.IInitializer, IPrototypeFactory.IInstantiator, IPrototypeFactory.IPrototypeReference |
Constructor Summary | |
PrototypeFactory()
|
Method Summary | |
void |
addInitializer(int i,
IPrototypeFactory.IInitializer initializer)
Adds the given initializer at position " i ". |
void |
assertTypeAllowed(java.lang.Class theType)
Calls isTypeAllowed(Class) and throws TypeMismatchException if it returns false . |
void |
clear()
Removes all prototypes from the factory. |
protected java.lang.Object |
clonePrototype(java.lang.Object prototype,
FactoryOptions options)
Clones the given prototype. |
protected java.lang.String |
descPrototype(java.lang.Object prototype)
Returns a description of the given prototype for logging. |
protected void |
doGetAllowableTypes(java.util.Set types)
The subclass can override this method to enable type checking for inserted prototypes. |
protected java.lang.Object |
doNewObject(java.lang.Object prototype,
FactoryOptions options)
Creates a new object based on the given prototype. |
java.util.Set |
getAllowableTypes()
Returns the set types allowable for prototypes held by this factory. |
IPrototypeFactory.IConfigStrategy |
getConfigStrategy()
Returns the IPrototypeFactory.IConfigStrategy used to configure this
factory. |
java.util.List |
getInitializers()
Returns a shallow copy of the internal list of IPrototypeFactory.IInitializer 's. |
void |
getIntrinsicAliases(java.lang.Object prototype,
java.util.Set aliases)
By default does nothing, but subclasses may override. |
IReentrantLock |
getLock()
Returns the lock used for synchronizing on shared data structures. |
boolean |
getLookupCaseSensitive()
Returns whether factory lookup of prototypes is case sensitive. |
protected java.util.List |
getModifiableKeysList()
Returns the modifiable list of prototype keys ordered by their insertion into the factory. |
protected java.util.Map |
getModifiablePrototypeMap()
Gets the modifiable prototype map. |
java.lang.Object |
getObject(java.lang.Object key,
FactoryOptions options)
|
protected java.lang.Object |
getPrototypeFromMap(java.lang.Object key)
|
java.util.List |
getPrototypeKeysInInsertionOrder()
If prototype insertion order is being preserved (as determined by preserveInsertionOrder() ),
returns the keys of these prototypes as an unmodifiable List in the order in which they were inserted; else
returns an empty unmodifiable List . |
java.util.Map |
getPrototypes()
Returns an unmodifiable Map defining the mapping between prototype keys and their corresponding prototypes. |
java.util.List |
getPrototypesInInsertionOrder()
If prototype insertion order is being preserved (as determined by preserveInsertionOrder() ),
returns the prototypes as an unmodifiable List in the order in which they were inserted; else
returns an empty unmodifiable List . |
boolean |
getSynchronized()
Returns whether the factory synchronizes on a IReentrantLock to protect shared data structures. |
void |
initializePrototype(java.lang.Object prototype,
int howCreated,
FactoryOptions options)
Calls all initializers registered with the factory in order. |
boolean |
isTypeAllowed(java.lang.Class theType)
Returns the set types allowable for prototypes held by this factory. |
boolean |
lock()
If getSynchronized() returns false this method does nothing; else it acquires
the lock returned by getLock() . |
IPrototypeFactory.IConfigStrategy |
newConfigStrategy()
Creates a new IPrototypeFactory.IConfigStrategy . |
protected java.lang.Object |
newInstance(java.lang.Class itsClass,
FactoryOptions options)
Creates a new instance of the given class. |
java.lang.Object |
newObject(java.lang.Class itsClass)
|
java.lang.Object |
newObject(java.lang.Class itsClass,
FactoryOptions options)
|
java.lang.Object |
newObject(java.lang.Object key)
|
java.lang.Object |
newObject(java.lang.Object key,
FactoryOptions options)
|
protected boolean |
okayToClone(java.lang.Object prototype)
By default returns false , but subclasses may override. |
protected java.lang.String |
prepareKeyForLookup(java.lang.Object key)
Changes the given key to a String for lookup. |
boolean |
preserveInsertionOrder()
Retruns whether prototype insertion order is preserved and thus avaiable for later retrieval via getPrototypeKeysInInsertionOrder() . |
boolean |
prototypeExists(java.lang.Object key)
Returns whether a prototype is currently keyed under the given name. |
void |
putPrototype(java.lang.Object obj)
Convenience alias for " putPrototype( obj, (Object[])null ) ". |
void |
putPrototype(java.lang.Object obj,
java.lang.Object oneAlias)
Convenience alias for " putPrototype( obj, new Object[] { oneAlias } ) ". |
void |
putPrototype(java.lang.Object obj,
java.lang.Object[] explicitAliases)
Enters the given object into the factory as a prototype. |
protected java.lang.Object |
putPrototypeToMap(java.lang.Object key,
java.lang.Object value)
|
IPrototypeFactory.IInitializer |
removeInitializer(int i)
Removes the given initializer at position " i ". |
boolean |
removeInitializer(IPrototypeFactory.IInitializer ini)
Removes the given initializer. |
void |
setConfigStrategy(IPrototypeFactory.IConfigStrategy strat)
Causes this factory to use " strat " as its configuration strategy. |
void |
setLock(IReentrantLock lock)
Sets the lock used for synchronizing on shared data structures. |
void |
setLookupCaseSensitive(boolean b)
Sets the flag indicating whether lookup of prototypes is case sensitive or not. |
void |
setSynchronized(boolean s)
Sets the flag indiciating whether the factory synchronizes on a IReentrantLock to protect shared data structures. |
void |
unlock(boolean locked)
If locked is true , calls "getLock().unlock() "; else does nothing. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public PrototypeFactory()
Method Detail |
public java.util.List getInitializers()
IPrototypeFactory
IPrototypeFactory.IInitializer
's. Since
the List
is a copy, the caller can query and modify it at will without synchronization.
getInitializers
in interface IPrototypeFactory
public void addInitializer(int i, IPrototypeFactory.IInitializer initializer)
IPrototypeFactory
i
".
addInitializer
in interface IPrototypeFactory
public IPrototypeFactory.IInitializer removeInitializer(int i)
IPrototypeFactory
i
".
removeInitializer
in interface IPrototypeFactory
public boolean removeInitializer(IPrototypeFactory.IInitializer ini)
IPrototypeFactory
removeInitializer
in interface IPrototypeFactory
public IReentrantLock getLock()
IPrototypeFactory
IPrototypeFactory.getSynchronized()
returns true
.
getLock
in interface IPrototypeFactory
public void setLock(IReentrantLock lock)
IPrototypeFactory
IPrototypeFactory.getSynchronized()
returns true
.
setLock
in interface IPrototypeFactory
public boolean lock()
IPrototypeFactory
IPrototypeFactory.getSynchronized()
returns false
this method does nothing; else it acquires
the lock returned by IPrototypeFactory.getLock()
. Returns whether a lock was acquired or not.
lock
in interface IPrototypeFactory
public void unlock(boolean locked)
IPrototypeFactory
locked
is true
, calls "getLock().unlock()
"; else does nothing.
unlock
in interface IPrototypeFactory
public java.util.Set getAllowableTypes()
IPrototypeFactory
Class
instance.
getAllowableTypes
in interface IPrototypeFactory
public boolean isTypeAllowed(java.lang.Class theType)
IPrototypeFactory
Class
instance.
isTypeAllowed
in interface IPrototypeFactory
public void assertTypeAllowed(java.lang.Class theType)
IPrototypeFactory
IPrototypeFactory.isTypeAllowed(Class)
and throws TypeMismatchException
if it returns false
.
assertTypeAllowed
in interface IPrototypeFactory
public java.util.Map getPrototypes()
IPrototypeFactory
Map
defining the mapping between prototype keys and their corresponding prototypes.
getPrototypes
in interface IPrototypeFactory
public java.util.List getPrototypeKeysInInsertionOrder()
IPrototypeFactory
preserveInsertionOrder()
),
returns the keys of these prototypes as an unmodifiable List
in the order in which they were inserted; else
returns an empty unmodifiable List
.
getPrototypeKeysInInsertionOrder
in interface IPrototypeFactory
public java.util.List getPrototypesInInsertionOrder() throws PrototypeFactoryException
IPrototypeFactory
IPrototypeFactory.preserveInsertionOrder()
),
returns the prototypes as an unmodifiable List
in the order in which they were inserted; else
returns an empty unmodifiable List
.
getPrototypesInInsertionOrder
in interface IPrototypeFactory
PrototypeFactoryException
public void setConfigStrategy(IPrototypeFactory.IConfigStrategy strat)
IPrototypeFactory
strat
" as its configuration strategy.
setConfigStrategy
in interface IPrototypeFactory
public IPrototypeFactory.IConfigStrategy getConfigStrategy()
IPrototypeFactory
IPrototypeFactory.IConfigStrategy
used to configure this
factory.
getConfigStrategy
in interface IPrototypeFactory
public IPrototypeFactory.IConfigStrategy newConfigStrategy()
IPrototypeFactory
IPrototypeFactory.IConfigStrategy
.
The default implementation creates a PropertyFactoryConfigStrategy
,
but subclasses are free to override.
newConfigStrategy
in interface IPrototypeFactory
public java.lang.Object newObject(java.lang.Class itsClass, FactoryOptions options) throws PrototypeFactoryException
newObject
in interface IPrototypeFactory
PrototypeFactoryException
public java.lang.Object newObject(java.lang.Class itsClass) throws PrototypeFactoryException
newObject
in interface IPrototypeFactory
PrototypeFactoryException
public java.lang.Object newObject(java.lang.Object key) throws PrototypeFactoryException
newObject
in interface IPrototypeFactory
PrototypeFactoryException
public java.lang.Object newObject(java.lang.Object key, FactoryOptions options) throws PrototypeFactoryException
newObject
in interface IPrototypeFactory
PrototypeFactoryException
public java.lang.Object getObject(java.lang.Object key, FactoryOptions options) throws PrototypeFactoryException
getObject
in interface IPrototypeFactory
PrototypeFactoryException
public boolean prototypeExists(java.lang.Object key)
IPrototypeFactory
prototypeExists
in interface IPrototypeFactory
public void clear()
IPrototypeFactory
clear
in interface IPrototypeFactory
public void putPrototype(java.lang.Object obj)
IPrototypeFactory
putPrototype( obj, (Object[])null )
".
putPrototype
in interface IPrototypeFactory
public void putPrototype(java.lang.Object obj, java.lang.Object oneAlias)
IPrototypeFactory
putPrototype( obj, new Object[] { oneAlias } )
".
putPrototype
in interface IPrototypeFactory
public void putPrototype(java.lang.Object obj, java.lang.Object[] explicitAliases)
IPrototypeFactory
explicitAliases
", as well as all keys
returned by IPrototypeFactory.getIntrinsicAliases(java.lang.Object, java.util.Set)
.
putPrototype
in interface IPrototypeFactory
public boolean getSynchronized()
IPrototypeFactory
IReentrantLock
to protect shared data structures.
Synchronization is enabled by default but can be disabled if needed. If synchronization is disabled, IPrototypeFactory.getLock()
and IPrototypeFactory.setLock(IReentrantLock)
can be used to respectively get and set the IReentrantLock
used for synchronization.
getSynchronized
in interface IPrototypeFactory
public void setSynchronized(boolean s)
IPrototypeFactory
IReentrantLock
to protect shared data structures.
Synchronization is enabled by default but can be disabled if needed. If synchronization is disabled, IPrototypeFactory.getLock()
and IPrototypeFactory.setLock(IReentrantLock)
can be used to respectively get and set the IReentrantLock
used for synchronization.
setSynchronized
in interface IPrototypeFactory
public boolean getLookupCaseSensitive()
IPrototypeFactory
true
by default
but can be changed via IPrototypeFactory.setLookupCaseSensitive(boolean)
.
getLookupCaseSensitive
in interface IPrototypeFactory
true
if lookup is case sensitive, false
otherwise.public void setLookupCaseSensitive(boolean b)
IPrototypeFactory
true
by default.
setLookupCaseSensitive
in interface IPrototypeFactory
public boolean preserveInsertionOrder()
IPrototypeFactory
IPrototypeFactory.getPrototypeKeysInInsertionOrder()
.
preserveInsertionOrder
in interface IPrototypeFactory
true
if prototype insertion order is preserved, false
otherwise.protected java.lang.Object putPrototypeToMap(java.lang.Object key, java.lang.Object value)
protected java.lang.Object getPrototypeFromMap(java.lang.Object key)
protected java.lang.Object doNewObject(java.lang.Object prototype, FactoryOptions options)
clonePrototype(Object,FactoryOptions)
if
okayToClone(Object)
returns true
; else newInstance()
is called on the prototype's class to
invoke the no-arg constructor.
public void initializePrototype(java.lang.Object prototype, int howCreated, FactoryOptions options)
IPrototypeFactory
IPrototypeFactory.IInitializer.initialize(org.jpu.patterns.factory.IPrototypeFactory, java.lang.Object, int, org.jpu.patterns.factory.FactoryOptions)
.
initializePrototype
in interface IPrototypeFactory
protected boolean okayToClone(java.lang.Object prototype)
false
, but subclasses may override. Returns whether it is acceptable for
the factory to clone the given prototype when a new instance of this prototype is requested. If this
method returns true
, reflection will be used to call a public clone()
method;
else the class of the prototype will be obtained and newInstance()
called on it.
prototype
- The prototype.
protected java.lang.String prepareKeyForLookup(java.lang.Object key)
String
for lookup. Default implementation converts the key to a string and downcases it if getLookupCaseSensitive()
is true
, but subclasses are free to override.
public void getIntrinsicAliases(java.lang.Object prototype, java.util.Set aliases)
IPrototypeFactory
aliases
set zero or more such aliases.
The alias should be unique among all the prototype keys; if it isn't, any previous mapping associated
with the alias you assign will be silently overwritten.
It is good practice to call super.getIntrinsicAliases(prototype, aliases)
before doing
anything else in your subclass implementation of this method.
getIntrinsicAliases
in interface IPrototypeFactory
prototype
- The prototype.aliases
- The set into which aliases may be inserted.protected java.lang.Object clonePrototype(java.lang.Object prototype, FactoryOptions options)
JPUObjectUtils.cloneObjectEfficiently(Object)
, but subclasses are free to override.
protected java.lang.Object newInstance(java.lang.Class itsClass, FactoryOptions options)
itClass.newInstance()
, but subclasses are free to override.
protected java.util.Map getModifiablePrototypeMap()
Map
and calls IPrototypeFactory.IConfigStrategy.configure()
on
this factory's IPrototypeFactory.IConfigStrategy
;
else calls IPrototypeFactory.IConfigStrategy.reconfigureIfNecessary()
on the config
strategy and returns the Map
.
protected java.util.List getModifiableKeysList()
List
.
protected java.lang.String descPrototype(java.lang.Object prototype)
protected void doGetAllowableTypes(java.util.Set types)
types.add(x.class)
for all permissible classes x
.
The default implementation does nothing.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |