|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Interface for classes that provide general-purpose functionality commonly needed
by prototype-based factories, especially those that need to be initialized from
an external configuration source such as a properties or XML file. See
PrototypeFactory
for a an implementation.
Features include the following:
IPrototypeFactory.IConfigStrategy
interface, which
can support any arbitrary configuration source. A property-based configurator
called PropertyFactoryConfigStrategy
is included, and can be
tailored to hook into whichever configuration source your application uses; or you can write
your own custom strategy.
PrototypeFactory.doGetAllowableTypes(java.util.Set)
to define which types are
permitted. An attempt to add a prototype of an illegal type results in an exception.
false
to setSynchronized(boolean)
. If you disable
synchronization, you should enclose calls to IPrototypeFactory
in
appropriate synchronized
blocks if the factory can be referenced
concurrently by multiple threads.
IPrototypeFactory.IInstantiator
,
and list the instantiator's name in the configuration file, the factory will delegate
prototype creation to your instantiator's IPrototypeFactory.IInstantiator.create(org.jpu.patterns.factory.FactoryOptions)
method, which in turn
can use any arbitrary approach to instantiation including use of
java.lang.reflect.Proxy.newProxyInstance()
.
IPrototypeFactory.IInitializer
may be registered with the factory, and they will be
called in the specified order to initialize an object after its instantiation prior to its return to the client.
Nested Class Summary | |
static interface |
IPrototypeFactory.IConfigStrategy
Defines the interface to the factory's configurator. |
static interface |
IPrototypeFactory.IInitializer
Interface to be implemented by classes that are registered as initializers via addInitializer(int, org.jpu.patterns.factory.IPrototypeFactory.IInitializer) . |
static interface |
IPrototypeFactory.IInstantiator
Interface to be implemented by a class to which object creation should be delegated. |
static interface |
IPrototypeFactory.IPrototypeReference
|
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. |
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. |
java.lang.Object |
getObject(java.lang.Object key,
FactoryOptions options)
|
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 . |
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 name)
|
java.lang.Object |
newObject(java.lang.Object name,
FactoryOptions options)
|
boolean |
preserveInsertionOrder()
Retruns whether prototype insertion order is preserved and thus avaiable for later retrieval via getPrototypeKeysInInsertionOrder() . |
boolean |
prototypeExists(java.lang.Object name)
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. |
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. |
Method Detail |
public void initializePrototype(java.lang.Object prototype, int howCreated, FactoryOptions options)
IPrototypeFactory.IInitializer.initialize(org.jpu.patterns.factory.IPrototypeFactory, java.lang.Object, int, org.jpu.patterns.factory.FactoryOptions)
.
public java.util.List getInitializers()
IPrototypeFactory.IInitializer
's. Since
the List
is a copy, the caller can query and modify it at will without synchronization.
public void addInitializer(int i, IPrototypeFactory.IInitializer initializer)
i
".
public IPrototypeFactory.IInitializer removeInitializer(int i)
i
".
public boolean removeInitializer(IPrototypeFactory.IInitializer ini)
public IPrototypeFactory.IConfigStrategy getConfigStrategy()
IPrototypeFactory.IConfigStrategy
used to configure this
factory.
public boolean lock()
getSynchronized()
returns false
this method does nothing; else it acquires
the lock returned by getLock()
. Returns whether a lock was acquired or not.
public void unlock(boolean locked)
locked
is true
, calls "getLock().unlock()
"; else does nothing.
public IReentrantLock getLock()
getSynchronized()
returns true
.
public void setLock(IReentrantLock lock)
getSynchronized()
returns true
.
public boolean getSynchronized()
IReentrantLock
to protect shared data structures.
Synchronization is enabled by default but can be disabled if needed. If synchronization is disabled, getLock()
and setLock(IReentrantLock)
can be used to respectively get and set the IReentrantLock
used for synchronization.
public void setSynchronized(boolean s)
IReentrantLock
to protect shared data structures.
Synchronization is enabled by default but can be disabled if needed. If synchronization is disabled, getLock()
and setLock(IReentrantLock)
can be used to respectively get and set the IReentrantLock
used for synchronization.
public java.util.Set getAllowableTypes()
Class
instance.
public boolean isTypeAllowed(java.lang.Class theType)
Class
instance.
public void assertTypeAllowed(java.lang.Class theType)
isTypeAllowed(Class)
and throws TypeMismatchException
if it returns false
.
public java.util.Map getPrototypes()
Map
defining the mapping between prototype keys and their corresponding prototypes.
public java.util.List getPrototypeKeysInInsertionOrder()
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
.
public java.util.List getPrototypesInInsertionOrder() throws PrototypeFactoryException
preserveInsertionOrder()
),
returns the prototypes as an unmodifiable List
in the order in which they were inserted; else
returns an empty unmodifiable List
.
PrototypeFactoryException
public boolean preserveInsertionOrder()
getPrototypeKeysInInsertionOrder()
.
true
if prototype insertion order is preserved, false
otherwise.public boolean prototypeExists(java.lang.Object name)
public void clear()
public java.lang.Object newObject(java.lang.Class itsClass, FactoryOptions options) throws PrototypeFactoryException
PrototypeFactoryException
public java.lang.Object newObject(java.lang.Class itsClass) throws PrototypeFactoryException
PrototypeFactoryException
public java.lang.Object newObject(java.lang.Object name, FactoryOptions options) throws PrototypeFactoryException
PrototypeFactoryException
public java.lang.Object newObject(java.lang.Object name) throws PrototypeFactoryException
PrototypeFactoryException
public java.lang.Object getObject(java.lang.Object key, FactoryOptions options) throws PrototypeFactoryException
PrototypeFactoryException
public void putPrototype(java.lang.Object obj)
putPrototype( obj, (Object[])null )
".
public void putPrototype(java.lang.Object obj, java.lang.Object oneAlias)
putPrototype( obj, new Object[] { oneAlias } )
".
public void getIntrinsicAliases(java.lang.Object prototype, java.util.Set aliases)
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.
prototype
- The prototype.aliases
- The set into which aliases may be inserted.public void putPrototype(java.lang.Object obj, java.lang.Object[] explicitAliases)
explicitAliases
", as well as all keys
returned by getIntrinsicAliases(java.lang.Object, java.util.Set)
.
public void setConfigStrategy(IPrototypeFactory.IConfigStrategy strat)
strat
" as its configuration strategy.
public IPrototypeFactory.IConfigStrategy newConfigStrategy()
IPrototypeFactory.IConfigStrategy
.
The default implementation creates a PropertyFactoryConfigStrategy
,
but subclasses are free to override.
public boolean getLookupCaseSensitive()
true
by default
but can be changed via setLookupCaseSensitive(boolean)
.
true
if lookup is case sensitive, false
otherwise.public void setLookupCaseSensitive(boolean b)
true
by default.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |