public abstract class AbstractAuthorityMediator extends AbstractAuthorityFactory implements AuthorityFactory, CRSAuthorityFactory, CSAuthorityFactory, DatumAuthorityFactory, CoordinateOperationAuthorityFactory, BufferedFactory
createFoo(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 createFoo
method of the factory, which will cache the result for next time.
This object is responsible for maintaining an {{ObjectCache}} of "workers" based on the following:
Modifier and Type | Class and Description |
---|---|
protected class |
AbstractAuthorityMediator.WorkerSafeRunnable
An interface describing a portion of work for which a worker is needed.
|
Modifier and Type | Field and Description |
---|---|
protected ReferencingFactoryContainer |
factories
A container of the "real factories" actually used to construct objects.
|
LOGGER
hints, MAXIMUM_PRIORITY, MINIMUM_PRIORITY, NORMAL_PRIORITY, priority
Modifier | Constructor and Description |
---|---|
protected |
AbstractAuthorityMediator()
Constructs an instance making use of the default cache and priority level.
|
protected |
AbstractAuthorityMediator(Hints hints)
Constructs an instance based on the provided Hints
|
protected |
AbstractAuthorityMediator(int priority)
Constructs an instance making use of the default cache.
|
protected |
AbstractAuthorityMediator(int priority,
Hints hints)
Constructs an instance making use of the default cache.
|
protected |
AbstractAuthorityMediator(int priority,
ObjectCache cache,
ReferencingFactoryContainer container)
Constructs an instance making use of the indicated cache.
|
Modifier and Type | Method and Description |
---|---|
protected abstract void |
activateWorker(AbstractCachedAuthorityFactory worker)
Reinitialize an instance to be returned by the pool.
|
protected void |
completeHints() |
CartesianCS |
createCartesianCS(String code)
Creates a cartesian coordinate system from a code.
|
CompoundCRS |
createCompoundCRS(String code)
Creates a 3D coordinate reference system from a code.
|
CoordinateOperation |
createCoordinateOperation(String code)
Creates 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)
Creates a cylindrical coordinate system from a code.
|
Datum |
createDatum(String code)
Returns an arbitrary datum from a code.
|
DerivedCRS |
createDerivedCRS(String code)
Creates a derived coordinate reference system from a code.
|
Ellipsoid |
createEllipsoid(String code)
Returns an ellipsoid from a code.
|
EllipsoidalCS |
createEllipsoidalCS(String code)
Creates an ellipsoidal coordinate system from a code.
|
EngineeringDatum |
createEngineeringDatum(String code)
Creates a engineering datum from a code.
|
Set |
createFromCoordinateReferenceSystemCodes(String sourceCode,
String targetCode)
Creates 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)
Creates a image coordinate reference system from a code.
|
ImageDatum |
createImageDatum(String code)
Creates a image datum from a code.
|
IdentifiedObject |
createObject(String code)
Returns an arbitrary object from a code.
|
PolarCS |
createPolarCS(String code)
Creates 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)
Creates a spherical coordinate system from a code.
|
TemporalCRS |
createTemporalCRS(String code)
Creates a temporal coordinate reference system from a code.
|
TemporalDatum |
createTemporalDatum(String code)
Creates a temporal datum from a code.
|
TimeCS |
createTimeCS(String code)
Creates a temporal coordinate system from a code.
|
Unit<?> |
createUnit(String code)
Returns an unit from a code.
|
VerticalCRS |
createVerticalCRS(String code)
Creates a vertical coordinate reference system from a code.
|
VerticalCS |
createVerticalCS(String code)
Creates a vertical coordinate system from a code.
|
VerticalDatum |
createVerticalDatum(String code)
Creates a vertical datum from a code.
|
protected <T> T |
createWith(Object key,
AbstractAuthorityMediator.WorkerSafeRunnable runner)
This method is used to cut down the amount of try/catch/finally code needed when working with
the cache and workers.
|
protected abstract void |
destroyWorker(AbstractCachedAuthorityFactory worker)
Destroys an instance no longer needed by the pool.
|
void |
dispose()
Clean up the object pool of workers (since we are shutting down).
|
abstract Citation |
getAuthority()
The authority body of the objects this factory provides.
|
Set |
getAuthorityCodes(Class 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. |
abstract InternationalString |
getDescriptionText(String code)
Gets a description of the object corresponding to a code.
|
IdentifiedObjectFinder |
getIdentifiedObjectFinder(Class type)
Returns a finder which can be used for looking up unidentified objects.
|
boolean |
isConnected()
True if this mediator is currently connected to one or more workers.
|
protected abstract AbstractCachedAuthorityFactory |
makeWorker()
Creates an instance that can be returned by the pool.
|
protected abstract void |
passivateWorker(AbstractCachedAuthorityFactory worker)
Un-initialize an instance to be returned to the pool.
|
protected String |
toKey(String code) |
protected String |
trimAuthority(String code)
Trims the authority scope, if present.
|
protected abstract boolean |
validateWorker(AbstractCachedAuthorityFactory worker)
Ensures that the instance is safe to be returned by the pool.
|
createEngineeringCRS, createExtent, createOperationMethod, createParameterDescriptor, noSuchAuthorityCode
ensureNonNull, getVendor
addImplementationHints, equals, getImplementationHints, getPriority, hashCode, onDeregistration, onRegistration, toString
createEngineeringCRS
getImplementationHints
protected final ReferencingFactoryContainer factories
protected AbstractAuthorityMediator()
protected AbstractAuthorityMediator(Hints hints)
factory
- The factory to cache. Can not be null
.protected AbstractAuthorityMediator(int priority)
factory
- The factory to cache. Can not be null
.protected AbstractAuthorityMediator(int priority, Hints hints)
factory
- The factory to cache. Can not be null
.protected AbstractAuthorityMediator(int priority, ObjectCache cache, ReferencingFactoryContainer container)
This constructor is protected because subclasses must declare which of the DatumAuthorityFactory
, CSAuthorityFactory
, CRSAuthorityFactory
and CoordinateOperationAuthorityFactory
interfaces they choose to implement.
factory
- The factory to cache. Can not be null
.maxStrongReferences
- The maximum number of objects to keep by strong reference.protected void completeHints()
public boolean isConnected()
protected String trimAuthority(String code)
trimAuthority
in class AbstractAuthorityFactory
code
- The code to trim.public abstract Citation getAuthority()
getAuthority
in interface AuthorityFactory
getAuthority
in class AbstractAuthorityFactory
public Set getAuthorityCodes(Class type) throws FactoryException
AuthorityFactory
type
argument specify the
base class. For example if this factory is an instance of CRSAuthorityFactory
, then:
CoordinateReferenceSystem.class
asks for all authority codes accepted by one of createGeographicCRS
, createProjectedCRS
,
createVerticalCRS
, createTemporalCRS
and their friends.
ProjectedCRS.class
asks only for authority codes accepted by createProjectedCRS
.
getAuthorityCodes
in interface AuthorityFactory
type
- The spatial reference objects type.FactoryException
- if access to the underlying database failed.public abstract InternationalString getDescriptionText(String code) throws FactoryException
AuthorityFactory
getDescriptionText
in interface AuthorityFactory
code
- Value allocated by authority.null
if the object corresponding to the
specified code
has no description.NoSuchAuthorityCodeException
- if the specified code
was not found.FactoryException
- if the query failed for some other reason.public IdentifiedObject createObject(String code) throws FactoryException
AbstractAuthorityFactory
Datum
, CoordinateSystem
, CoordinateReferenceSystem
or CoordinateOperation
. 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.createObject
in interface AuthorityFactory
createObject
in class AbstractAuthorityFactory
code
- Value allocated by authority.NoSuchAuthorityCodeException
- if the specified code
was not found.FactoryException
- if the object creation failed for some other reason.AbstractAuthorityFactory.createCoordinateReferenceSystem(java.lang.String)
,
AbstractAuthorityFactory.createDatum(java.lang.String)
,
AbstractAuthorityFactory.createEllipsoid(java.lang.String)
,
AbstractAuthorityFactory.createUnit(java.lang.String)
public CompoundCRS createCompoundCRS(String code) throws FactoryException
AbstractAuthorityFactory
createCompoundCRS
in interface CRSAuthorityFactory
createCompoundCRS
in class AbstractAuthorityFactory
code
- Value allocated by authority.NoSuchAuthorityCodeException
- if the specified code
was not found.FactoryException
- if the object creation failed for some other reason.public CoordinateReferenceSystem createCoordinateReferenceSystem(String code) throws FactoryException
AbstractAuthorityFactory
createGeographicCRS(code)
instead of
createCoordinateReferenceSystem(code)
if the caller know he is
asking for a geographic coordinate reference system).createCoordinateReferenceSystem
in interface CRSAuthorityFactory
createCoordinateReferenceSystem
in class AbstractAuthorityFactory
code
- Value allocated by authority.NoSuchAuthorityCodeException
- if the specified code
was not found.FactoryException
- if the object creation failed for some other reason.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)
public DerivedCRS createDerivedCRS(String code) throws FactoryException
AbstractAuthorityFactory
createDerivedCRS
in interface CRSAuthorityFactory
createDerivedCRS
in class AbstractAuthorityFactory
code
- Value allocated by authority.NoSuchAuthorityCodeException
- if the specified code
was not found.FactoryException
- if the object creation failed for some other reason.public GeocentricCRS createGeocentricCRS(String code) throws FactoryException
AbstractAuthorityFactory
createGeocentricCRS
in interface CRSAuthorityFactory
createGeocentricCRS
in class AbstractAuthorityFactory
code
- Value allocated by authority.NoSuchAuthorityCodeException
- if the specified code
was not found.FactoryException
- if the object creation failed.AbstractAuthorityFactory.createGeodeticDatum(java.lang.String)
public GeographicCRS createGeographicCRS(String code) throws FactoryException
AbstractAuthorityFactory
createGeographicCRS
in interface CRSAuthorityFactory
createGeographicCRS
in class AbstractAuthorityFactory
code
- Value allocated by authority.NoSuchAuthorityCodeException
- if the specified code
was not found.FactoryException
- if the object creation failed for some other reason.AbstractAuthorityFactory.createGeodeticDatum(java.lang.String)
public ImageCRS createImageCRS(String code) throws FactoryException
AbstractAuthorityFactory
createImageCRS
in interface CRSAuthorityFactory
createImageCRS
in class AbstractAuthorityFactory
code
- Value allocated by authority.NoSuchAuthorityCodeException
- if the specified code
was not found.FactoryException
- if the object creation failed for some other reason.public ProjectedCRS createProjectedCRS(String code) throws FactoryException
AbstractAuthorityFactory
createProjectedCRS
in interface CRSAuthorityFactory
createProjectedCRS
in class AbstractAuthorityFactory
code
- Value allocated by authority.NoSuchAuthorityCodeException
- if the specified code
was not found.FactoryException
- if the object creation failed for some other reason.AbstractAuthorityFactory.createGeodeticDatum(java.lang.String)
public TemporalCRS createTemporalCRS(String code) throws FactoryException
AbstractAuthorityFactory
createTemporalCRS
in interface CRSAuthorityFactory
createTemporalCRS
in class AbstractAuthorityFactory
code
- Value allocated by authority.NoSuchAuthorityCodeException
- if the specified code
was not found.FactoryException
- if the object creation failed for some other reason.AbstractAuthorityFactory.createTemporalDatum(java.lang.String)
public VerticalCRS createVerticalCRS(String code) throws FactoryException
AbstractAuthorityFactory
createVerticalCRS
in interface CRSAuthorityFactory
createVerticalCRS
in class AbstractAuthorityFactory
code
- Value allocated by authority.NoSuchAuthorityCodeException
- if the specified code
was not found.FactoryException
- if the object creation failed for some other reason.AbstractAuthorityFactory.createVerticalDatum(java.lang.String)
public CartesianCS createCartesianCS(String code) throws FactoryException
AbstractAuthorityFactory
createCoordinateSystem(code)
.createCartesianCS
in interface CSAuthorityFactory
createCartesianCS
in class AbstractAuthorityFactory
code
- Value allocated by authority.NoSuchAuthorityCodeException
- if the specified code
was not found.FactoryException
- if the object creation failed for some other reason.public CoordinateSystem createCoordinateSystem(String code) throws FactoryException
AbstractAuthorityFactory
createObject(code)
.createCoordinateSystem
in interface CSAuthorityFactory
createCoordinateSystem
in class AbstractAuthorityFactory
code
- Value allocated by authority.NoSuchAuthorityCodeException
- if the specified code
was not found.FactoryException
- if the object creation failed for some other reason.public CoordinateSystemAxis createCoordinateSystemAxis(String code) throws FactoryException
AbstractAuthorityFactory
createObject(code)
.createCoordinateSystemAxis
in interface CSAuthorityFactory
createCoordinateSystemAxis
in class AbstractAuthorityFactory
code
- Value allocated by authority.NoSuchAuthorityCodeException
- if the specified code
was not found.FactoryException
- if the object creation failed for some other reason.public CylindricalCS createCylindricalCS(String code) throws FactoryException
AbstractAuthorityFactory
createCoordinateSystem(code)
.createCylindricalCS
in interface CSAuthorityFactory
createCylindricalCS
in class AbstractAuthorityFactory
code
- Value allocated by authority.NoSuchAuthorityCodeException
- if the specified code
was not found.FactoryException
- if the object creation failed for some other reason.public EllipsoidalCS createEllipsoidalCS(String code) throws FactoryException
AbstractAuthorityFactory
createCoordinateSystem(code)
.createEllipsoidalCS
in interface CSAuthorityFactory
createEllipsoidalCS
in class AbstractAuthorityFactory
code
- Value allocated by authority.NoSuchAuthorityCodeException
- if the specified code
was not found.FactoryException
- if the object creation failed for some other reason.public PolarCS createPolarCS(String code) throws FactoryException
AbstractAuthorityFactory
createCoordinateSystem(code)
.createPolarCS
in interface CSAuthorityFactory
createPolarCS
in class AbstractAuthorityFactory
code
- Value allocated by authority.NoSuchAuthorityCodeException
- if the specified code
was not found.FactoryException
- if the object creation failed for some other reason.public SphericalCS createSphericalCS(String code) throws FactoryException
AbstractAuthorityFactory
createCoordinateSystem(code)
.createSphericalCS
in interface CSAuthorityFactory
createSphericalCS
in class AbstractAuthorityFactory
code
- Value allocated by authority.NoSuchAuthorityCodeException
- if the specified code
was not found.FactoryException
- if the object creation failed for some other reason.public TimeCS createTimeCS(String code) throws FactoryException
AbstractAuthorityFactory
createCoordinateSystem(code)
.createTimeCS
in interface CSAuthorityFactory
createTimeCS
in class AbstractAuthorityFactory
code
- Value allocated by authority.NoSuchAuthorityCodeException
- if the specified code
was not found.FactoryException
- if the object creation failed for some other reason.public Unit<?> createUnit(String code) throws FactoryException
AbstractAuthorityFactory
createObject(code)
.createUnit
in interface CSAuthorityFactory
createUnit
in class AbstractAuthorityFactory
code
- Value allocated by authority.NoSuchAuthorityCodeException
- if the specified code
was not found.FactoryException
- if the object creation failed for some other reason.public VerticalCS createVerticalCS(String code) throws FactoryException
AbstractAuthorityFactory
createCoordinateSystem(code)
.createVerticalCS
in interface CSAuthorityFactory
createVerticalCS
in class AbstractAuthorityFactory
code
- Value allocated by authority.NoSuchAuthorityCodeException
- if the specified code
was not found.FactoryException
- if the object creation failed for some other reason.public Datum createDatum(String code) throws FactoryException
AbstractAuthorityFactory
createObject(code)
.createDatum
in interface DatumAuthorityFactory
createDatum
in class AbstractAuthorityFactory
code
- Value allocated by authority.NoSuchAuthorityCodeException
- if the specified code
was not found.FactoryException
- if the object creation failed for some other reason.AbstractAuthorityFactory.createGeodeticDatum(java.lang.String)
,
AbstractAuthorityFactory.createVerticalDatum(java.lang.String)
,
AbstractAuthorityFactory.createTemporalDatum(java.lang.String)
public Ellipsoid createEllipsoid(String code) throws FactoryException
AbstractAuthorityFactory
createObject(code)
.createEllipsoid
in interface DatumAuthorityFactory
createEllipsoid
in class AbstractAuthorityFactory
code
- Value allocated by authority.NoSuchAuthorityCodeException
- if the specified code
was not found.FactoryException
- if the object creation failed for some other reason.AbstractAuthorityFactory.createGeodeticDatum(java.lang.String)
public EngineeringDatum createEngineeringDatum(String code) throws FactoryException
AbstractAuthorityFactory
createDatum(code)
.createEngineeringDatum
in interface DatumAuthorityFactory
createEngineeringDatum
in class AbstractAuthorityFactory
code
- Value allocated by authority.NoSuchAuthorityCodeException
- if the specified code
was not found.FactoryException
- if the object creation failed for some other reason.AbstractAuthorityFactory.createEngineeringCRS(java.lang.String)
public GeodeticDatum createGeodeticDatum(String code) throws FactoryException
AbstractAuthorityFactory
createDatum(code)
.createGeodeticDatum
in interface DatumAuthorityFactory
createGeodeticDatum
in class AbstractAuthorityFactory
code
- Value allocated by authority.NoSuchAuthorityCodeException
- if the specified code
was not found.FactoryException
- if the object creation failed for some other reason.AbstractAuthorityFactory.createEllipsoid(java.lang.String)
,
AbstractAuthorityFactory.createPrimeMeridian(java.lang.String)
,
AbstractAuthorityFactory.createGeographicCRS(java.lang.String)
,
AbstractAuthorityFactory.createProjectedCRS(java.lang.String)
public ImageDatum createImageDatum(String code) throws FactoryException
AbstractAuthorityFactory
createDatum(code)
.createImageDatum
in interface DatumAuthorityFactory
createImageDatum
in class AbstractAuthorityFactory
code
- Value allocated by authority.NoSuchAuthorityCodeException
- if the specified code
was not found.FactoryException
- if the object creation failed for some other reason.AbstractAuthorityFactory.createImageCRS(java.lang.String)
public PrimeMeridian createPrimeMeridian(String code) throws FactoryException
AbstractAuthorityFactory
createObject(code)
.createPrimeMeridian
in interface DatumAuthorityFactory
createPrimeMeridian
in class AbstractAuthorityFactory
code
- Value allocated by authority.NoSuchAuthorityCodeException
- if the specified code
was not found.FactoryException
- if the object creation failed for some other reason.AbstractAuthorityFactory.createGeodeticDatum(java.lang.String)
public TemporalDatum createTemporalDatum(String code) throws FactoryException
AbstractAuthorityFactory
createDatum(code)
.createTemporalDatum
in interface DatumAuthorityFactory
createTemporalDatum
in class AbstractAuthorityFactory
code
- Value allocated by authority.NoSuchAuthorityCodeException
- if the specified code
was not found.FactoryException
- if the object creation failed for some other reason.AbstractAuthorityFactory.createTemporalCRS(java.lang.String)
public VerticalDatum createVerticalDatum(String code) throws FactoryException
AbstractAuthorityFactory
createDatum(code)
.createVerticalDatum
in interface DatumAuthorityFactory
createVerticalDatum
in class AbstractAuthorityFactory
code
- Value allocated by authority.NoSuchAuthorityCodeException
- if the specified code
was not found.FactoryException
- if the object creation failed for some other reason.AbstractAuthorityFactory.createVerticalCRS(java.lang.String)
public CoordinateOperation createCoordinateOperation(String code) throws FactoryException
AbstractAuthorityFactory
createCoordinateOperation
in interface CoordinateOperationAuthorityFactory
createCoordinateOperation
in class AbstractAuthorityFactory
code
- Value allocated by authority.NoSuchAuthorityCodeException
- if the specified code
was not found.FactoryException
- if the object creation failed for some other reason.public Set createFromCoordinateReferenceSystemCodes(String sourceCode, String targetCode) throws FactoryException
AbstractAuthorityFactory
Rational: Coordinate operation factory backed by an authority will invoke this method. If this method invoked the coordinate operation factory in turn, the application could be trapped in infinite recursive calls.
createFromCoordinateReferenceSystemCodes
in interface CoordinateOperationAuthorityFactory
createFromCoordinateReferenceSystemCodes
in class AbstractAuthorityFactory
sourceCode
- Coded value of source coordinate reference system.targetCode
- Coded value of target coordinate reference system.sourceCRS
to targetCRS
.NoSuchAuthorityCodeException
- if a specified code was not found.FactoryException
- if the object creation failed for some other reason.protected <T> T createWith(Object key, AbstractAuthorityMediator.WorkerSafeRunnable runner) throws FactoryException
This code brings together two try/catch/finally blocks.
For cache management:
T value = (T) cache.get(key);
if (value == null) {
try {
cache.writeLock(key);
value = (T) cache.peek(key);
if (value == null) {
....generate value....
cache.put( key, value );
}
} finally {
cache.writeUnLock(key);
}
}
And worker management when generating values:
AbstractCachedAuthorityFactory worker = null;
try {
worker = (AbstractCachedAuthorityFactory) getPool().borrowObject();
value = (T) runner.run( worker );
} catch (FactoryException e) {
throw e;
} catch (Exception e) {
throw new FactoryException(e);
} finally {
try {
getPool().returnObject(worker);
} catch (Exception e) {
LOGGER.log(Level.WARNING, "Unable to return worker " + e, e);
}
}
key
- Used to look in the cacherunner
- Used to generate a value in the case of a cache missFactoryException
public String getBackingStoreDescription() throws FactoryException
AbstractAuthorityFactory
null
if unknown. This is
for example the database software used for storing the data. The default implementation
returns always null
.getBackingStoreDescription
in class AbstractAuthorityFactory
null
.FactoryException
- if a failure occurs while fetching the engine description.public void dispose() throws FactoryException
Subclasses may wish to override this method if they have their own resources to clean up (like a database connection). If you do this please remember to call super.dispose().
dispose
in class AbstractAuthorityFactory
FactoryException
- if an error occured while disposing the factory.protected abstract void activateWorker(AbstractCachedAuthorityFactory worker) throws Exception
Please note that BEFORE this method has been called AbstractAuthorityMediator has already:
cache
findCache
Exception
protected abstract void destroyWorker(AbstractCachedAuthorityFactory worker) throws Exception
Exception
protected abstract AbstractCachedAuthorityFactory makeWorker() throws Exception
Exception
protected abstract void passivateWorker(AbstractCachedAuthorityFactory worker) throws Exception
Exception
protected abstract boolean validateWorker(AbstractCachedAuthorityFactory worker)
public IdentifiedObjectFinder getIdentifiedObjectFinder(Class type) throws FactoryException
The returned implementation will make use of workers as needed.
getIdentifiedObjectFinder
in class AbstractAuthorityFactory
type
- The type of objects to look for.FactoryException
- if the finder can not be created.Copyright © 1996–2019 Geotools. All rights reserved.