| java.lang.Object org.geotools.factory.AbstractFactory
All known Subclasses: org.geotools.data.geometryless.LocationsXYDataStoreFactory, org.geotools.data.geometryless.BBOXDataStoreFactory, org.geotools.coverage.grid.GridCoverageFactory, org.geotools.factory.FactoryUsingVolatileDependencies, org.geotools.referencing.factory.ReferencingFactory, org.geotools.data.geometryless.JDBCDataStoreFactory,
AbstractFactory | public class AbstractFactory implements Factory,RegisterableService(Code) | | Skeletal implementation of factories. This base classe provides no
createFoo methods,
(they must be provided by subclasses), but provides two convenience features:
- An initially empty
to be filled by subclasses
constructors. They are the hints to be returned by
AbstractFactory.getImplementationHints .
- An automatic
applied
on the basis of subclasses-provided
rank.
When more than one factory implementation is
for the same category (i.e. they
implement the same
Factory sub-interface), the actual instance to be used is selected
according their
and user-supplied
. 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
.
This implies that the ordering is unspecified between all factories created with the
, since they all have the same
level.
How hints are set
Hints are used for two purposes. The distinction is important because the set
of hints may not be identical in both cases:
- Hints are used for creating new factories.
- Hints are used in order to check if an existing factory is suitable.
AbstractFactory 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 use the
AbstractFactory.hints field for
that; use 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
AbstractFactory.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. If a hint is
relevant but the user didn't specified any value, the hint key should be added to the
AbstractFactory.hints map anyway with a
null value. Only direct dependencies shall be put
in the
AbstractFactory.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.
Note: The lack of constructor expecting a
Map argument is intentional.
This is in order to discourage blind-copy of all user-supplied hints to the
AbstractFactory.hints map.
Example: Lets two factories, A and B. Factory A need an instance of Factory B.
Factory A can be implemented as below:
Code | Observations |
class FactoryA extends AbstractFactory {
FactoryB fb;
FactoryA(Hints userHints) {
fb = FactoryFinder.getFactoryB(userHints);
hints.put(Hints.FACTORY_B, fb);
}
}
|
- The user-supplied map (
userHints ) is never modified.
- All hints relevant to other factories are used in the constructor. Hints relevant to
factory B are used when
FactoryFinder.getFactoryB(...) is invoked.
- The
FactoryA constructor stores only the hints relevant to
FactoryA .
Indirect dependencies (e.g. hints relevant to
FactoryB ) will be inspected
recursively by
FactoryRegistry .
- In the above example,
AbstractFactory.hints will never be used for creating new factories.
|
since: 2.1 version: $Id: AbstractFactory.java 25421 2007-05-05 16:55:18Z desruisseaux $ author: Martin Desruisseaux |
Constructor Summary | |
protected | AbstractFactory() Creates a new factory with the
. | protected | AbstractFactory(int priority) Constructs a factory with the specified priority. |
hints | final protected Map hints(Code) | | The
. This map should be
filled by subclasses at construction time. If possible, constructors should not copy blindly
all user-provided hints. They should select only the relevant hints and resolve them as of
contract.
Note: This field is not an instance of
Hints because:
- The primary use of this map is to check if this factory can be reused.
It is not for creating new factories.
- This map needs to allow null values, as of
contract.
|
AbstractFactory | protected AbstractFactory()(Code) | | Creates a new factory with the
.
|
equals | final public boolean equals(Object object)(Code) | | Compares this factory with the specified object for equality.
The default implementation returns
true if and only if:
- Both objects are of the exact same class
(a is instance of relationship is not enough).
-
are
.
The requirement for the exact same class is needed for consistency with the
working, since at most one instance of a given
class
in a registry.
since: 2.3 |
getImplementationHints | public Map getImplementationHints()(Code) | | Returns an
view of
.
The map of hints, or an empty map if none. |
hashCode | final public int hashCode()(Code) | | Returns a hash value for this factory. The default implementation computes the hash
value using only immutable properties. This computation do not relies
on
, since there is no garantee
that they will not change.
since: 2.3 |
onDeregistration | public void onDeregistration(ServiceRegistry registry, Class category)(Code) | | Called when this factory is removed from the given
category of the given
registry . The object may still be registered under another category or categories.
This method is invoked automatically when this factory is no longer registered as a plugin,
and should not be invoked directly by the user.
Parameters: registry - A service registry from which this object is being (wholly or partially)deregistered. Parameters: category - The registry category from which this object is being deregistered. |
onRegistration | public void onRegistration(ServiceRegistry registry, Class category)(Code) | | Called when this factory is added to the given
category of the given
registry . The factory may already be registered under another category
or categories.
This method is invoked automatically when this factory is registered as a plugin,
and should not be invoked directly by the user. The default implementation iterates
through all services under the same category that extends the
AbstractFactory class, and set the ordering according the priority given at construction time.
Parameters: registry - A service registry where this factory has been registered. Parameters: category - The registry category under which this object has been registered. See Also: AbstractFactory.MINIMUM_PRIORITY See Also: AbstractFactory.MAXIMUM_PRIORITY |
toString | public String toString()(Code) | | Returns a string representation of this factory. This method is mostly for debugging purpose,
so the string format may vary across different implementations or versions. The default
implementation formats all
as a
tree. If the implementation hints include some
dependencies,
then the implementation hints for those dependencies will appears under a tree branch.
since: 2.3 |
toString | static String toString(Map hints)(Code) | | Returns a string representation of the specified hints. This is used by
Hints.toString in order to share the code provided in this class.
|
|
|