|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.geotools.factory.AbstractFactory
Skeletal implementation of factories. This base classe provides no methods, (they must be provided by subclasses), but provides two convenience features:
getImplementationHints()
.
When more than one factory implementation is
registered for the same category (i.e. they
implement the same Factory
sub-interface), the actual instance to be used is selected
according their ordering and user-supplied
hints. Hints have precedence. If more than one factory matches the hints
(including the common case where the user doesn't provide any hint at all), then ordering
matter.
The ordering is unspecified for every pairs of factories with the same priority. This implies that the ordering is unspecified between all factories created with the default constructor, since they all have the same default priority level.
do not provides any facility for the first case.
Factories implementations shall inspect themselves all relevant hints supplied by the user,
and pass them to any dependencies. Do not uses the hints
field for
that; uses the hints provided by the user in the constructor. If all dependencies are created
at construction time (constructor injection), there is no need to keep user's hints
once the construction is finished.
The hints
field is for the second case only. Implementations shall copy in this
field only the user's hints that are know to be relevant to this factory. Only direct
dependencies shall be put in the hints
map. Indirect dependencies (i.e. hints used
by other factories used by this factory) will be inspected automatically by
FactoryRegistry
in a recursive way.
The lack of constructor expecting a Map
argument is intentional. Implementations
should not copy blindly all user-supplied hints into the hints
field. Instead, they
should pickup only the relevant hints and put them in the hints
field. An exception to this rule is when not all factories can be created at construction time.
In this case, all user-supplied hints must be kept.
Example: Lets two factories, A and B. Factory A need an instance of Factory B. Factory A can be implemented as below:
class FactoryA extends AbstractFactory { FactoryB fb; FactoryA(Hints userHints) { fb = FactoryFinder.getFactoryB(userHints); this.hints.put(Hints.FACTORY_B, fb); } } |
Observations:
|
Field Summary | |
protected Hints |
hints
The implementation hints. |
static int |
MAXIMUM_PRIORITY
The maximum priority for a factory, which is 100. |
static int |
MINIMUM_PRIORITY
The minimum priority for a factory, which is 1. |
static int |
NORMAL_PRIORITY
The default priority, which is 50. |
int |
priority
The priority for this factory. |
Constructor Summary | |
protected |
AbstractFactory()
Creates a new factory with the default priority. |
protected |
AbstractFactory(int priority)
Constructs a factory with the specified priority. |
Method Summary | |
java.util.Map |
getImplementationHints()
Returns an unmodifiable view of hints. |
void |
onDeregistration(javax.imageio.spi.ServiceRegistry registry,
java.lang.Class category)
Called when this factory is removed from the given of the given . |
void |
onRegistration(javax.imageio.spi.ServiceRegistry registry,
java.lang.Class category)
Called when this factory is added to the given of the given . |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final int MINIMUM_PRIORITY
onRegistration(javax.imageio.spi.ServiceRegistry, java.lang.Class)
,
Constant Field Valuespublic static final int NORMAL_PRIORITY
onRegistration(javax.imageio.spi.ServiceRegistry, java.lang.Class)
,
Constant Field Valuespublic static final int MAXIMUM_PRIORITY
onRegistration(javax.imageio.spi.ServiceRegistry, java.lang.Class)
,
Constant Field Valuespublic final int priority
protected final Hints hints
Reminder: the primary use of this map is to check if this factory can be reused. It is not for creating new factories.
Once the hints are accessibles to the user (this usually means when the subclass construction is finished), this map should not change anymore.
Constructor Detail |
protected AbstractFactory()
protected AbstractFactory(int priority)
priority
- The priority for this factory, as a number between
MINIMUM_PRIORITY
and MAXIMUM_PRIORITY
inclusive.Method Detail |
public java.util.Map getImplementationHints()
getImplementationHints
in interface Factory
public void onRegistration(javax.imageio.spi.ServiceRegistry registry, java.lang.Class category)
onRegistration
in interface javax.imageio.spi.RegisterableService
registry
- A service registry where this factory has been registered.category
- The registry category under which this object has been registered.MINIMUM_PRIORITY
,
MAXIMUM_PRIORITY
public void onDeregistration(javax.imageio.spi.ServiceRegistry registry, java.lang.Class category)
onDeregistration
in interface javax.imageio.spi.RegisterableService
registry
- A service registry from which this object is being (wholly or partially)
deregistered.category
- The registry category from which this object is being deregistered.
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |