org.geotoolkit.referencing.factory
Class CachingAuthorityFactory

Object
  extended by Factory
      extended by ReferencingFactory
          extended by AbstractAuthorityFactory
              extended by CachingAuthorityFactory
All Implemented Interfaces:
AuthorityFactory, Factory
Direct Known Subclasses:
ThreadedAuthorityFactory

@Buffered
@ThreadSafe
@Decorator(value=AbstractAuthorityFactory.class)
public class CachingAuthorityFactory
extends AbstractAuthorityFactory

An authority factory that caches all objects created by an other factory. All createFoo(String) methods first looks if a previously created object exists for the given code. If such an object exists, it is returned. Otherwise, the object creation is delegated to the authority factory specified at creation time, and the result is cached in this factory.

Objects are cached by strong references, up to the amount of objects specified at construction time. If a greater amount of objects are cached, the oldest ones will be retained through a weak reference instead of a strong one. This means that this caching factory will continue to returns them as long as they are in use somewhere else in the Java virtual machine, but will be discarded (and recreated on the fly if needed) otherwise.

Since:
2.1
Version:
3.14
Author:
Martin Desruisseaux (IRD, Geomatys)
Module:
referencing/geotk-referencing (download)    View source code for this class

Nested Class Summary
 
Nested classes/interfaces inherited from class Factory
Factory.Availability, Factory.Organizer
 
Field Summary
 
Fields inherited from class AbstractAuthorityFactory
nameFactory
 
Fields inherited from class ReferencingFactory
LOGGER
 
Fields inherited from class Factory
EMPTY_HINTS, hints
 
Constructor Summary
protected CachingAuthorityFactory(AbstractAuthorityFactory factory)
          Constructs an instance wrapping the specified factory with a default number of entries to keep by strong reference.
protected CachingAuthorityFactory(AbstractAuthorityFactory factory, int maxStrongReferences)
          Constructs an instance wrapping the specified factory.
 
Method Summary
 ConformanceResult availability()
          Returns whatever this factory is available.
 CartesianCS createCartesianCS(String code)
          Returns a Cartesian coordinate system from a code.
 CompoundCRS createCompoundCRS(String code)
          Returns a 3D coordinate reference system from a code.
 CoordinateOperation createCoordinateOperation(String code)
          Returns an operation from a single operation code.
 CoordinateReferenceSystem createCoordinateReferenceSystem(String code)
          Returns an arbitrary coordinate reference system from a code.
 CoordinateSystem createCoordinateSystem(String code)
          Returns an arbitrary coordinate system from a code.
 CoordinateSystemAxis createCoordinateSystemAxis(String code)
          Returns a coordinate system axis from a code.
 CylindricalCS createCylindricalCS(String code)
          Returns a cylindrical coordinate system from a code.
 Datum createDatum(String code)
          Returns an arbitrary datum from a code.
 DerivedCRS createDerivedCRS(String code)
          Returns a derived coordinate reference system from a code.
 Ellipsoid createEllipsoid(String code)
          Returns an ellipsoid from a code.
 EllipsoidalCS createEllipsoidalCS(String code)
          Returns an ellipsoidal coordinate system from a code.
 EngineeringCRS createEngineeringCRS(String code)
          Returns an engineering coordinate reference system from a code.
 EngineeringDatum createEngineeringDatum(String code)
          Returns an engineering datum from a code.
 Extent createExtent(String code)
          Returns an extent (usually an area of validity) from a code.
 Set<CoordinateOperation> createFromCoordinateReferenceSystemCodes(String sourceCRS, String targetCRS)
          Returns an operation from coordinate reference system codes.
 GeocentricCRS createGeocentricCRS(String code)
          Returns a geocentric coordinate reference system from a code.
 GeodeticDatum createGeodeticDatum(String code)
          Returns a geodetic datum from a code.
 GeographicCRS createGeographicCRS(String code)
          Returns a geographic coordinate reference system from a code.
 ImageCRS createImageCRS(String code)
          Returns an image coordinate reference system from a code.
 ImageDatum createImageDatum(String code)
          Returns an image datum from a code.
 IdentifiedObject createObject(String code)
          Returns an arbitrary object from a code.
 OperationMethod createOperationMethod(String code)
          Returns an operation method from a code.
 ParameterDescriptor<?> createParameterDescriptor(String code)
          Returns a parameter descriptor from a code.
 PolarCS createPolarCS(String code)
          Returns a polar coordinate system from a code.
 PrimeMeridian createPrimeMeridian(String code)
          Returns a prime meridian from a code.
 ProjectedCRS createProjectedCRS(String code)
          Returns a projected coordinate reference system from a code.
 SphericalCS createSphericalCS(String code)
          Returns a spherical coordinate system from a code.
 TemporalCRS createTemporalCRS(String code)
          Returns a temporal coordinate reference system from a code.
 TemporalDatum createTemporalDatum(String code)
          Returns a temporal datum from a code.
 TimeCS createTimeCS(String code)
          Returns a temporal coordinate system from a code.
 Unit<?> createUnit(String code)
          Returns an unit from a code.
 VerticalCRS createVerticalCRS(String code)
          Returns a vertical coordinate reference system from a code.
 VerticalCS createVerticalCS(String code)
          Returns a vertical coordinate system from a code.
 VerticalDatum createVerticalDatum(String code)
          Returns a vertical datum from a code.
protected  void dispose(boolean shutdown)
          Releases resources immediately instead of waiting for the garbage collector.
 Citation getAuthority()
          Returns the organization or party responsible for definition and maintenance of the underlying database.
 Set<String> getAuthorityCodes(Class<? extends IdentifiedObject> type)
          Returns the set of authority codes of the given type.
 String getBackingStoreDescription()
          Returns a description of the underlying backing store, or null if unknown.
 InternationalString getDescriptionText(String code)
          Gets a description of the object corresponding to a code.
 IdentifiedObjectFinder getIdentifiedObjectFinder(Class<? extends IdentifiedObject> type)
          Returns a finder which can be used for looking up unidentified objects.
 Citation getVendor()
          Returns the vendor responsible for creating the underlying factory implementation.
 void printCacheContent(PrintWriter out)
          Prints the cache content to the standard output stream.
protected  void setKeyCollisionAllowed(boolean allowed)
          true if different values may be assigned to the same key.
 
Methods inherited from class AbstractAuthorityFactory
noSuchAuthorityCode, trimAuthority
 
Methods inherited from class ReferencingFactory
ensureNonNull
 
Methods inherited from class Factory
equals, getImplementationHints, hasCompatibleHints, hashCode, setOrdering, toString
 
Methods inherited from class Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CachingAuthorityFactory

protected CachingAuthorityFactory(AbstractAuthorityFactory factory)
Constructs an instance wrapping the specified factory with a default number of entries to keep by strong reference.

This constructor is protected because subclasses must declare which of the DatumAuthorityFactory, CSAuthorityFactory, CRSAuthorityFactory and CoordinateOperationAuthorityFactory interfaces they choose to implement.

Parameters:
factory - The factory to cache. Can not be null.

CachingAuthorityFactory

protected CachingAuthorityFactory(AbstractAuthorityFactory factory,
                                  int maxStrongReferences)
Constructs an instance wrapping the specified factory. The maxStrongReferences argument specify the maximum number of objects to keep by strong reference. If a greater amount of objects are created, then the strong references for the eldest ones are replaced by weak references.

This constructor is protected because subclasses must declare which of the DatumAuthorityFactory, CSAuthorityFactory, CRSAuthorityFactory and CoordinateOperationAuthorityFactory interfaces they choose to implement.

Parameters:
factory - The factory to cache. Can not be null.
maxStrongReferences - The maximum number of objects to keep by strong reference.
Method Detail

availability

public ConformanceResult availability()
Returns whatever this factory is available. The factory is considered unavailable if it has been disposed, or if no backing store was specified at construction time and ThreadedAuthorityFactory.createBackingStore() threw an exception.

Overrides:
availability in class Factory
Since:
3.03

getVendor

public Citation getVendor()
Returns the vendor responsible for creating the underlying factory implementation. This method should be invoked only if this factory is available.

Specified by:
getVendor in interface Factory
Overrides:
getVendor in class ReferencingFactory
Returns:
The vendor for this factory implementation.
See Also:
Citations.GEOTOOLKIT

getAuthority

public Citation getAuthority()
Returns the organization or party responsible for definition and maintenance of the underlying database. This method should be invoked only if this factory is available.

Specified by:
getAuthority in interface AuthorityFactory
Specified by:
getAuthority in class AbstractAuthorityFactory

getBackingStoreDescription

public String getBackingStoreDescription()
                                  throws FactoryException
Returns a description of the underlying backing store, or null if unknown. This is for example the database software used for storing the data.

Overrides:
getBackingStoreDescription in class AbstractAuthorityFactory
Returns:
The description of the underlying backing store, or null.
Throws:
FactoryException - if a failure occurred while fetching the engine description.

getAuthorityCodes

public Set<String> getAuthorityCodes(Class<? extends IdentifiedObject> type)
                              throws FactoryException
Returns the set of authority codes of the given type. The type argument specifies the base class.

Parameters:
type - The spatial reference objects type.
Returns:
The set of authority codes for spatial reference objects of the given type. If this factory doesn't contains any object of the given type, then this method returns an empty set.
Throws:
FactoryException - if access to the underlying database failed.

getDescriptionText

public InternationalString getDescriptionText(String code)
                                       throws NoSuchAuthorityCodeException,
                                              FactoryException
Gets a description of the object corresponding to a code.

Parameters:
code - Value allocated by authority.
Returns:
A description of the object, or null if the object corresponding to the specified code has no description.
Throws:
NoSuchAuthorityCodeException - if the specified code was not found.
FactoryException - if the query failed for some other reason.

createObject

public IdentifiedObject createObject(String code)
                              throws FactoryException
Returns an arbitrary object from a code.

Specified by:
createObject in interface AuthorityFactory
Overrides:
createObject in class AbstractAuthorityFactory
Parameters:
code - Value allocated by authority.
Throws:
FactoryException - if the object creation failed.

createDatum

public Datum createDatum(String code)
                  throws FactoryException
Returns an arbitrary datum from a code.

Overrides:
createDatum in class AbstractAuthorityFactory
Parameters:
code - Value allocated by authority.
Returns:
The datum for the given code.
Throws:
FactoryException - if the object creation failed.

createEngineeringDatum

public EngineeringDatum createEngineeringDatum(String code)
                                        throws FactoryException
Returns an engineering datum from a code.

Overrides:
createEngineeringDatum in class AbstractAuthorityFactory
Parameters:
code - Value allocated by authority.
Returns:
The datum for the given code.
Throws:
FactoryException - if the object creation failed.

createImageDatum

public ImageDatum createImageDatum(String code)
                            throws FactoryException
Returns an image datum from a code.

Overrides:
createImageDatum in class AbstractAuthorityFactory
Parameters:
code - Value allocated by authority.
Returns:
The datum for the given code.
Throws:
FactoryException - if the object creation failed.

createVerticalDatum

public VerticalDatum createVerticalDatum(String code)
                                  throws FactoryException
Returns a vertical datum from a code.

Overrides:
createVerticalDatum in class AbstractAuthorityFactory
Parameters:
code - Value allocated by authority.
Returns:
The datum for the given code.
Throws:
FactoryException - if the object creation failed.

createTemporalDatum

public TemporalDatum createTemporalDatum(String code)
                                  throws FactoryException
Returns a temporal datum from a code.

Overrides:
createTemporalDatum in class AbstractAuthorityFactory
Parameters:
code - Value allocated by authority.
Returns:
The datum for the given code.
Throws:
FactoryException - if the object creation failed.

createGeodeticDatum

public GeodeticDatum createGeodeticDatum(String code)
                                  throws FactoryException
Returns a geodetic datum from a code.

Overrides:
createGeodeticDatum in class AbstractAuthorityFactory
Parameters:
code - Value allocated by authority.
Returns:
The datum for the given code.
Throws:
FactoryException - if the object creation failed.

createEllipsoid

public Ellipsoid createEllipsoid(String code)
                          throws FactoryException
Returns an ellipsoid from a code.

Overrides:
createEllipsoid in class AbstractAuthorityFactory
Parameters:
code - Value allocated by authority.
Returns:
The ellipsoid for the given code.
Throws:
FactoryException - if the object creation failed.

createPrimeMeridian

public PrimeMeridian createPrimeMeridian(String code)
                                  throws FactoryException
Returns a prime meridian from a code.

Overrides:
createPrimeMeridian in class AbstractAuthorityFactory
Parameters:
code - Value allocated by authority.
Returns:
The prime meridian for the given code.
Throws:
FactoryException - if the object creation failed.

createExtent

public Extent createExtent(String code)
                    throws FactoryException
Returns an extent (usually an area of validity) from a code.

Overrides:
createExtent in class AbstractAuthorityFactory
Parameters:
code - Value allocated by authority.
Returns:
The extent for the given code.
Throws:
FactoryException - if the object creation failed.

createCoordinateSystem

public CoordinateSystem createCoordinateSystem(String code)
                                        throws FactoryException
Returns an arbitrary coordinate system from a code.

Overrides:
createCoordinateSystem in class AbstractAuthorityFactory
Parameters:
code - Value allocated by authority.
Returns:
The coordinate system for the given code.
Throws:
FactoryException - if the object creation failed.

createCartesianCS

public CartesianCS createCartesianCS(String code)
                              throws FactoryException
Returns a Cartesian coordinate system from a code.

Overrides:
createCartesianCS in class AbstractAuthorityFactory
Parameters:
code - Value allocated by authority.
Returns:
The coordinate system for the given code.
Throws:
FactoryException - if the object creation failed.

createPolarCS

public PolarCS createPolarCS(String code)
                      throws FactoryException
Returns a polar coordinate system from a code.

Overrides:
createPolarCS in class AbstractAuthorityFactory
Parameters:
code - Value allocated by authority.
Returns:
The coordinate system for the given code.
Throws:
FactoryException - if the object creation failed.

createCylindricalCS

public CylindricalCS createCylindricalCS(String code)
                                  throws FactoryException
Returns a cylindrical coordinate system from a code.

Overrides:
createCylindricalCS in class AbstractAuthorityFactory
Parameters:
code - Value allocated by authority.
Returns:
The coordinate system for the given code.
Throws:
FactoryException - if the object creation failed.

createSphericalCS

public SphericalCS createSphericalCS(String code)
                              throws FactoryException
Returns a spherical coordinate system from a code.

Overrides:
createSphericalCS in class AbstractAuthorityFactory
Parameters:
code - Value allocated by authority.
Returns:
The coordinate system for the given code.
Throws:
FactoryException - if the object creation failed.

createEllipsoidalCS

public EllipsoidalCS createEllipsoidalCS(String code)
                                  throws FactoryException
Returns an ellipsoidal coordinate system from a code.

Overrides:
createEllipsoidalCS in class AbstractAuthorityFactory
Parameters:
code - Value allocated by authority.
Returns:
The coordinate system for the given code.
Throws:
FactoryException - if the object creation failed.

createVerticalCS

public VerticalCS createVerticalCS(String code)
                            throws FactoryException
Returns a vertical coordinate system from a code.

Overrides:
createVerticalCS in class AbstractAuthorityFactory
Parameters:
code - Value allocated by authority.
Returns:
The coordinate system for the given code.
Throws:
FactoryException - if the object creation failed.

createTimeCS

public TimeCS createTimeCS(String code)
                    throws FactoryException
Returns a temporal coordinate system from a code.

Overrides:
createTimeCS in class AbstractAuthorityFactory
Parameters:
code - Value allocated by authority.
Returns:
The coordinate system for the given code.
Throws:
FactoryException - if the object creation failed.

createCoordinateSystemAxis

public CoordinateSystemAxis createCoordinateSystemAxis(String code)
                                                throws FactoryException
Returns a coordinate system axis from a code.

Overrides:
createCoordinateSystemAxis in class AbstractAuthorityFactory
Parameters:
code - Value allocated by authority.
Returns:
The axis for the given code.
Throws:
FactoryException - if the object creation failed.

createUnit

public Unit<?> createUnit(String code)
                   throws FactoryException
Returns an unit from a code.

Overrides:
createUnit in class AbstractAuthorityFactory
Parameters:
code - Value allocated by authority.
Returns:
The unit for the given code.
Throws:
FactoryException - if the object creation failed.

createCoordinateReferenceSystem

public CoordinateReferenceSystem createCoordinateReferenceSystem(String code)
                                                          throws FactoryException
Returns an arbitrary coordinate reference system from a code.

Overrides:
createCoordinateReferenceSystem in class AbstractAuthorityFactory
Parameters:
code - Value allocated by authority.
Returns:
The coordinate reference system for the given code.
Throws:
FactoryException - if the object creation failed.

createCompoundCRS

public CompoundCRS createCompoundCRS(String code)
                              throws FactoryException
Returns a 3D coordinate reference system from a code.

Overrides:
createCompoundCRS in class AbstractAuthorityFactory
Parameters:
code - Value allocated by authority.
Returns:
The coordinate reference system for the given code.
Throws:
FactoryException - if the object creation failed.

createDerivedCRS

public DerivedCRS createDerivedCRS(String code)
                            throws FactoryException
Returns a derived coordinate reference system from a code.

Overrides:
createDerivedCRS in class AbstractAuthorityFactory
Parameters:
code - Value allocated by authority.
Returns:
The coordinate reference system for the given code.
Throws:
FactoryException - if the object creation failed.

createEngineeringCRS

public EngineeringCRS createEngineeringCRS(String code)
                                    throws FactoryException
Returns an engineering coordinate reference system from a code.

Overrides:
createEngineeringCRS in class AbstractAuthorityFactory
Parameters:
code - Value allocated by authority.
Returns:
The coordinate reference system for the given code.
Throws:
FactoryException - if the object creation failed.

createGeographicCRS

public GeographicCRS createGeographicCRS(String code)
                                  throws FactoryException
Returns a geographic coordinate reference system from a code.

Overrides:
createGeographicCRS in class AbstractAuthorityFactory
Parameters:
code - Value allocated by authority.
Returns:
The coordinate reference system for the given code.
Throws:
FactoryException - if the object creation failed.

createGeocentricCRS

public GeocentricCRS createGeocentricCRS(String code)
                                  throws FactoryException
Returns a geocentric coordinate reference system from a code.

Overrides:
createGeocentricCRS in class AbstractAuthorityFactory
Parameters:
code - Value allocated by authority.
Returns:
The coordinate reference system for the given code.
Throws:
FactoryException - if the object creation failed.

createImageCRS

public ImageCRS createImageCRS(String code)
                        throws FactoryException
Returns an image coordinate reference system from a code.

Overrides:
createImageCRS in class AbstractAuthorityFactory
Parameters:
code - Value allocated by authority.
Returns:
The coordinate reference system for the given code.
Throws:
FactoryException - if the object creation failed.

createProjectedCRS

public ProjectedCRS createProjectedCRS(String code)
                                throws FactoryException
Returns a projected coordinate reference system from a code.

Overrides:
createProjectedCRS in class AbstractAuthorityFactory
Parameters:
code - Value allocated by authority.
Returns:
The coordinate reference system for the given code.
Throws:
FactoryException - if the object creation failed.

createTemporalCRS

public TemporalCRS createTemporalCRS(String code)
                              throws FactoryException
Returns a temporal coordinate reference system from a code.

Overrides:
createTemporalCRS in class AbstractAuthorityFactory
Parameters:
code - Value allocated by authority.
Returns:
The coordinate reference system for the given code.
Throws:
FactoryException - if the object creation failed.

createVerticalCRS

public VerticalCRS createVerticalCRS(String code)
                              throws FactoryException
Returns a vertical coordinate reference system from a code.

Overrides:
createVerticalCRS in class AbstractAuthorityFactory
Parameters:
code - Value allocated by authority.
Returns:
The coordinate reference system for the given code.
Throws:
FactoryException - if the object creation failed.

createParameterDescriptor

public ParameterDescriptor<?> createParameterDescriptor(String code)
                                                 throws FactoryException
Returns a parameter descriptor from a code.

Overrides:
createParameterDescriptor in class AbstractAuthorityFactory
Parameters:
code - Value allocated by authority.
Returns:
The coordinate reference system for the given code.
Throws:
FactoryException - if the object creation failed.
Since:
2.2

createOperationMethod

public OperationMethod createOperationMethod(String code)
                                      throws FactoryException
Returns an operation method from a code.

Overrides:
createOperationMethod in class AbstractAuthorityFactory
Parameters:
code - Value allocated by authority.
Returns:
The operation method for the given code.
Throws:
FactoryException - if the object creation failed.
Since:
2.2

createCoordinateOperation

public CoordinateOperation createCoordinateOperation(String code)
                                              throws FactoryException
Returns an operation from a single operation code.

Overrides:
createCoordinateOperation in class AbstractAuthorityFactory
Parameters:
code - Value allocated by authority.
Returns:
The operation for the given code.
Throws:
FactoryException - if the object creation failed.
Since:
2.2

createFromCoordinateReferenceSystemCodes

public Set<CoordinateOperation> createFromCoordinateReferenceSystemCodes(String sourceCRS,
                                                                         String targetCRS)
                                                                  throws FactoryException
Returns an operation from coordinate reference system codes.

Overrides:
createFromCoordinateReferenceSystemCodes in class AbstractAuthorityFactory
Parameters:
sourceCRS - Coded value of source coordinate reference system.
targetCRS - Coded value of target coordinate reference system.
Returns:
The operations from sourceCRS to targetCRS.
Throws:
FactoryException - if the object creation failed.
Since:
2.2

getIdentifiedObjectFinder

public IdentifiedObjectFinder getIdentifiedObjectFinder(Class<? extends IdentifiedObject> type)
                                                 throws FactoryException
Returns a finder which can be used for looking up unidentified objects. The default implementation delegates lookup to the underlying backing store and caches the result.

Overrides:
getIdentifiedObjectFinder in class AbstractAuthorityFactory
Parameters:
type - The type of objects to look for. Should be a GeoAPI interface like GeographicCRS.class, but this method accepts also implementation class. If the type is unknown, use IdentifiedObject.class. A more accurate type may help to speed up the search, since it reduces the amount of tables to scan in some implementations (for example the factories backed by EPSG databases).
Returns:
A finder to use for looking up unidentified objects.
Throws:
FactoryException - if the finder can not be created.
Since:
2.4

printCacheContent

@Debug
public void printCacheContent(PrintWriter out)
Prints the cache content to the standard output stream. Keys are sorted by numerical order if possible, or alphabetical order otherwise. This method is used for debugging purpose only.

Parameters:
out - The output printer, or null for the standard output stream.
Since:
3.17

setKeyCollisionAllowed

protected void setKeyCollisionAllowed(boolean allowed)
true if different values may be assigned to the same key. This is usually an error, so the default Cache behavior is to thrown an exception in such case. However in some cases we may want to relax this check. For example the EPSG database sometime assign the same key to different kind of objects.

This property can also be set in order to allow some recursivity. If during the creation of an object, the program asks to this CachingAuthorityFactory for the same object (using the same key), then the default CachingAuthorityFactory implementation will consider this situation as a key collision unless this property has been set to true.

Parameters:
allowed - true if key collisions are allowed.
See Also:
Cache.setKeyCollisionAllowed(boolean)

dispose

protected void dispose(boolean shutdown)
Releases resources immediately instead of waiting for the garbage collector.

Overrides:
dispose in class AbstractAuthorityFactory
Parameters:
shutdown - false for normal disposal, or true if this method is invoked during the process of a JVM shutdown.


Copyright © 2009-2011 Geotoolkit.org. All Rights Reserved.