Package org.geotools.referencing.factory
Class CachedCRSAuthorityDecorator
- Object
-
- AbstractFactory
-
- ReferencingFactory
-
- AbstractAuthorityFactory
-
- CachedCRSAuthorityDecorator
-
- All Implemented Interfaces:
AuthorityFactory
,CRSAuthorityFactory
,Factory
,BufferedFactory
,Factory
,RegistrableFactory
public final class CachedCRSAuthorityDecorator extends AbstractAuthorityFactory implements AuthorityFactory, CRSAuthorityFactory, BufferedFactory
An authority factory that caches all objects created by the delegate CRSAuthorityFactory. The behaviour of thecreateFoo(String)
methods first looks if a previously created object exists for the given code. If such an object exists, it is returned directly. The testing of the cache is synchronized and may block if the referencing object is under construction.If the object is not yet created, the definition is delegated to the appropriate the AuthorityFactory authority factory and the result is cached for next time.
This object is responsible for owning a {{ReferencingObjectCache}}; there are several implementations to choose from on construction.
- Since:
- 2.4
- Author:
- Jody Garnett
-
-
Field Summary
-
Fields inherited from class ReferencingFactory
LOGGER
-
Fields inherited from class AbstractFactory
hints, MAXIMUM_PRIORITY, MINIMUM_PRIORITY, NORMAL_PRIORITY, priority
-
-
Constructor Summary
Constructors Modifier Constructor Description CachedCRSAuthorityDecorator(CRSAuthorityFactory factory)
Constructs an instance wrapping the specified factory with a default cache.protected
CachedCRSAuthorityDecorator(CRSAuthorityFactory factory, ObjectCache<Object,Object> cache)
Constructs an instance wrapping the specified factory.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected static <K,V>
ObjectCache<K,V>createCache(Hints hints)
Utility method used to produce cache based on hintCompoundCRS
createCompoundCRS(String code)
Creates a 3D coordinate reference system from a code.CoordinateReferenceSystem
createCoordinateReferenceSystem(String code)
Returns an arbitrary coordinate reference system from a code.DerivedCRS
createDerivedCRS(String code)
Creates a derived coordinate reference system from a code.EngineeringCRS
createEngineeringCRS(String code)
Creates a engineering coordinate reference system from a code.GeocentricCRS
createGeocentricCRS(String code)
Returns a geocentric coordinate reference system from a code.GeographicCRS
createGeographicCRS(String code)
Returns a geographic coordinate reference system from a code.ImageCRS
createImageCRS(String code)
Creates a image coordinate reference system from a code.IdentifiedObject
createObject(String code)
Returns an arbitrary object from a code.ProjectedCRS
createProjectedCRS(String code)
Returns a projected coordinate reference system from a code.TemporalCRS
createTemporalCRS(String code)
Creates a temporal coordinate reference system from a code.VerticalCRS
createVerticalCRS(String code)
Creates a vertical coordinate reference system from a code.void
dispose()
Releases resources immediately instead of waiting for the garbage collector.Citation
getAuthority()
Returns the organization or party responsible for definition and maintenance of the 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, ornull
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.protected String
toKey(String code)
-
Methods inherited from class AbstractAuthorityFactory
createCartesianCS, createCoordinateOperation, createCoordinateSystem, createCoordinateSystemAxis, createCylindricalCS, createDatum, createEllipsoid, createEllipsoidalCS, createEngineeringDatum, createExtent, createFromCoordinateReferenceSystemCodes, createGeodeticDatum, createImageDatum, createOperationMethod, createParameterDescriptor, createPolarCS, createPrimeMeridian, createSphericalCS, createTemporalDatum, createTimeCS, createUnit, createVerticalCS, createVerticalDatum, noSuchAuthorityCode, trimAuthority
-
Methods inherited from class ReferencingFactory
ensureNonNull, getVendor
-
Methods inherited from class AbstractFactory
addImplementationHints, equals, getImplementationHints, getPriority, hashCode, onDeregistration, onRegistration, toString
-
Methods inherited from interface Factory
getImplementationHints
-
-
-
-
Constructor Detail
-
CachedCRSAuthorityDecorator
public CachedCRSAuthorityDecorator(CRSAuthorityFactory factory)
Constructs an instance wrapping the specified factory with a default cache.The provided authority factory must implement
DatumAuthorityFactory
,CSAuthorityFactory
,CRSAuthorityFactory
andCoordinateOperationAuthorityFactory
.- Parameters:
factory
- The factory to cache. Can not benull
.
-
CachedCRSAuthorityDecorator
protected CachedCRSAuthorityDecorator(CRSAuthorityFactory factory, ObjectCache<Object,Object> cache)
Constructs an instance wrapping the specified factory. ThemaxStrongReferences
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 oldest ones are replaced by weak references.This constructor is protected because subclasses must declare which of the
DatumAuthorityFactory
,CSAuthorityFactory
,CRSAuthorityFactory
SearchableAuthorityFactory
andCoordinateOperationAuthorityFactory
interfaces they choose to implement.- Parameters:
factory
- The factory to cache. Can not benull
.cache
- The underlying cache
-
-
Method Detail
-
createCache
protected static <K,V> ObjectCache<K,V> createCache(Hints hints) throws FactoryRegistryException
Utility method used to produce cache based on hint- Throws:
FactoryRegistryException
-
createObject
public IdentifiedObject createObject(String code) throws FactoryException
Description copied from class:AbstractAuthorityFactory
Returns an arbitrary object from a code. The returned object will typically be an instance ofDatum
,CoordinateSystem
,CoordinateReferenceSystem
orCoordinateOperation
. The default implementation always throw an exception. Subclasses should override this method if they are capable to automatically detect the object type from its code.- Specified by:
createObject
in interfaceAuthorityFactory
- Overrides:
createObject
in classAbstractAuthorityFactory
- Parameters:
code
- Value allocated by authority.- Returns:
- The object for the given code.
- Throws:
NoSuchAuthorityCodeException
- if the specifiedcode
was not found.FactoryException
- if the object creation failed for some other reason.- See Also:
AbstractAuthorityFactory.createCoordinateReferenceSystem(java.lang.String)
,AbstractAuthorityFactory.createDatum(java.lang.String)
,AbstractAuthorityFactory.createEllipsoid(java.lang.String)
,AbstractAuthorityFactory.createUnit(java.lang.String)
-
getAuthority
public Citation getAuthority()
Description copied from class:AbstractAuthorityFactory
Returns the organization or party responsible for definition and maintenance of the database.- Specified by:
getAuthority
in interfaceAuthorityFactory
- Specified by:
getAuthority
in classAbstractAuthorityFactory
- Returns:
- The organization reponsible for definition of the database.
-
getAuthorityCodes
public Set<String> getAuthorityCodes(Class<? extends IdentifiedObject> type) throws FactoryException
Description copied from interface:AuthorityFactory
Returns the set of authority codes of the given type. Thetype
argument specify the base class. For example if this factory is an instance ofCRSAuthorityFactory
, then:CoordinateReferenceSystem.class
asks for all authority codes accepted by one ofcreateGeographicCRS
,createProjectedCRS
,createVerticalCRS
,createTemporalCRS
and their friends.ProjectedCRS.class
asks only for authority codes accepted bycreateProjectedCRS
.
- Specified by:
getAuthorityCodes
in interfaceAuthorityFactory
- 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 {@linkplain java.util.Collections.emptySet() empty set}.
- Throws:
FactoryException
- if access to the underlying database failed.
-
getDescriptionText
public InternationalString getDescriptionText(String code) throws FactoryException
Description copied from interface:AuthorityFactory
Gets a description of the object corresponding to a code.- Specified by:
getDescriptionText
in interfaceAuthorityFactory
- Parameters:
code
- Value allocated by authority.- Returns:
- A description of the object, or
null
if the object corresponding to the specifiedcode
has no description. - Throws:
NoSuchAuthorityCodeException
- if the specifiedcode
was not found.FactoryException
- if the query failed for some other reason.
-
createCompoundCRS
public CompoundCRS createCompoundCRS(String code) throws FactoryException
Description copied from class:AbstractAuthorityFactory
Creates a 3D coordinate reference system from a code.- Specified by:
createCompoundCRS
in interfaceCRSAuthorityFactory
- Overrides:
createCompoundCRS
in classAbstractAuthorityFactory
- Parameters:
code
- Value allocated by authority.- Returns:
- The coordinate reference system for the given code.
- Throws:
NoSuchAuthorityCodeException
- if the specifiedcode
was not found.FactoryException
- if the object creation failed for some other reason.
-
createCoordinateReferenceSystem
public CoordinateReferenceSystem createCoordinateReferenceSystem(String code) throws FactoryException
Description copied from class:AbstractAuthorityFactory
Returns an arbitrary coordinate reference system from a code. If the coordinate reference system type is know at compile time, it is recommended to invoke the most precise method instead of this one (for examplecreateGeographicCRS(code)
instead ofcreateCoordinateReferenceSystem(code)
if the caller know he is asking for a geographic coordinate reference system).- Specified by:
createCoordinateReferenceSystem
in interfaceCRSAuthorityFactory
- Overrides:
createCoordinateReferenceSystem
in classAbstractAuthorityFactory
- Parameters:
code
- Value allocated by authority.- Returns:
- The coordinate reference system for the given code.
- Throws:
NoSuchAuthorityCodeException
- if the specifiedcode
was not found.FactoryException
- if the object creation failed for some other reason.- See Also:
AbstractAuthorityFactory.createGeographicCRS(java.lang.String)
,AbstractAuthorityFactory.createProjectedCRS(java.lang.String)
,AbstractAuthorityFactory.createVerticalCRS(java.lang.String)
,AbstractAuthorityFactory.createTemporalCRS(java.lang.String)
,AbstractAuthorityFactory.createCompoundCRS(java.lang.String)
-
createDerivedCRS
public DerivedCRS createDerivedCRS(String code) throws FactoryException
Description copied from class:AbstractAuthorityFactory
Creates a derived coordinate reference system from a code.- Specified by:
createDerivedCRS
in interfaceCRSAuthorityFactory
- Overrides:
createDerivedCRS
in classAbstractAuthorityFactory
- Parameters:
code
- Value allocated by authority.- Returns:
- The coordinate reference system for the given code.
- Throws:
NoSuchAuthorityCodeException
- if the specifiedcode
was not found.FactoryException
- if the object creation failed for some other reason.
-
createEngineeringCRS
public EngineeringCRS createEngineeringCRS(String code) throws FactoryException
Description copied from class:AbstractAuthorityFactory
Creates a engineering coordinate reference system from a code.- Specified by:
createEngineeringCRS
in interfaceCRSAuthorityFactory
- Overrides:
createEngineeringCRS
in classAbstractAuthorityFactory
- Parameters:
code
- Value allocated by authority.- Returns:
- The coordinate reference system for the given code.
- Throws:
NoSuchAuthorityCodeException
- if the specifiedcode
was not found.FactoryException
- if the object creation failed for some other reason.
-
createGeocentricCRS
public GeocentricCRS createGeocentricCRS(String code) throws FactoryException
Description copied from class:AbstractAuthorityFactory
Returns a geocentric coordinate reference system from a code.- Specified by:
createGeocentricCRS
in interfaceCRSAuthorityFactory
- Overrides:
createGeocentricCRS
in classAbstractAuthorityFactory
- Parameters:
code
- Value allocated by authority.- Returns:
- The coordinate reference system for the given code.
- Throws:
NoSuchAuthorityCodeException
- if the specifiedcode
was not found.FactoryException
- if the object creation failed.- See Also:
AbstractAuthorityFactory.createGeodeticDatum(java.lang.String)
-
createGeographicCRS
public GeographicCRS createGeographicCRS(String code) throws FactoryException
Description copied from class:AbstractAuthorityFactory
Returns a geographic coordinate reference system from a code.- Specified by:
createGeographicCRS
in interfaceCRSAuthorityFactory
- Overrides:
createGeographicCRS
in classAbstractAuthorityFactory
- Parameters:
code
- Value allocated by authority.- Returns:
- The coordinate reference system for the given code.
- Throws:
NoSuchAuthorityCodeException
- if the specifiedcode
was not found.FactoryException
- if the object creation failed for some other reason.- See Also:
AbstractAuthorityFactory.createGeodeticDatum(java.lang.String)
-
createImageCRS
public ImageCRS createImageCRS(String code) throws FactoryException
Description copied from class:AbstractAuthorityFactory
Creates a image coordinate reference system from a code.- Specified by:
createImageCRS
in interfaceCRSAuthorityFactory
- Overrides:
createImageCRS
in classAbstractAuthorityFactory
- Parameters:
code
- Value allocated by authority.- Returns:
- The coordinate reference system for the given code.
- Throws:
NoSuchAuthorityCodeException
- if the specifiedcode
was not found.FactoryException
- if the object creation failed for some other reason.
-
createProjectedCRS
public ProjectedCRS createProjectedCRS(String code) throws FactoryException
Description copied from class:AbstractAuthorityFactory
Returns a projected coordinate reference system from a code.- Specified by:
createProjectedCRS
in interfaceCRSAuthorityFactory
- Overrides:
createProjectedCRS
in classAbstractAuthorityFactory
- Parameters:
code
- Value allocated by authority.- Returns:
- The coordinate reference system for the given code.
- Throws:
NoSuchAuthorityCodeException
- if the specifiedcode
was not found.FactoryException
- if the object creation failed for some other reason.- See Also:
AbstractAuthorityFactory.createGeodeticDatum(java.lang.String)
-
createTemporalCRS
public TemporalCRS createTemporalCRS(String code) throws FactoryException
Description copied from class:AbstractAuthorityFactory
Creates a temporal coordinate reference system from a code.- Specified by:
createTemporalCRS
in interfaceCRSAuthorityFactory
- Overrides:
createTemporalCRS
in classAbstractAuthorityFactory
- Parameters:
code
- Value allocated by authority.- Returns:
- The coordinate reference system for the given code.
- Throws:
NoSuchAuthorityCodeException
- if the specifiedcode
was not found.FactoryException
- if the object creation failed for some other reason.- See Also:
AbstractAuthorityFactory.createTemporalDatum(java.lang.String)
-
createVerticalCRS
public VerticalCRS createVerticalCRS(String code) throws FactoryException
Description copied from class:AbstractAuthorityFactory
Creates a vertical coordinate reference system from a code.- Specified by:
createVerticalCRS
in interfaceCRSAuthorityFactory
- Overrides:
createVerticalCRS
in classAbstractAuthorityFactory
- Parameters:
code
- Value allocated by authority.- Returns:
- The coordinate reference system for the given code.
- Throws:
NoSuchAuthorityCodeException
- if the specifiedcode
was not found.FactoryException
- if the object creation failed for some other reason.- See Also:
AbstractAuthorityFactory.createVerticalDatum(java.lang.String)
-
dispose
public void dispose() throws FactoryException
Description copied from class:AbstractAuthorityFactory
Releases resources immediately instead of waiting for the garbage collector. Once a factory has been disposed, furthercreate(...)
invocations may throw aFactoryException
. Disposing a previously-disposed factory, however, has no effect.- Overrides:
dispose
in classAbstractAuthorityFactory
- Throws:
FactoryException
- if an error occured while disposing the factory.
-
getBackingStoreDescription
public String getBackingStoreDescription() throws FactoryException
Description copied from class:AbstractAuthorityFactory
Returns a description of the underlying backing store, ornull
if unknown. This is for example the database software used for storing the data. The default implementation returns alwaysnull
.- Overrides:
getBackingStoreDescription
in classAbstractAuthorityFactory
- Returns:
- The description of the underlying backing store, or
null
. - Throws:
FactoryException
- if a failure occurs while fetching the engine description.
-
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 classAbstractAuthorityFactory
- Parameters:
type
- The type of objects to look for. Should be a GeoAPI interface likeGeographicCRS.class
, but this method accepts also implementation class. If the type is unknown, useIdentifiedObject.class
. A more accurate type may help to speed up the search, since it reduces the amount of tables to scan in some implementations like the factories backed by EPSG database.- Returns:
- A finder to use for looking up unidentified objects.
- Throws:
FactoryException
- if the finder can not be created.- Since:
- 2.4
-
-