org.geotoolkit.referencing.factory
Class MultiAuthoritiesFactory

Object
  extended by Factory
      extended by ReferencingFactory
          extended by AbstractAuthorityFactory
              extended by AuthorityFactoryAdapter
                  extended by MultiAuthoritiesFactory
All Implemented Interfaces:
AuthorityFactory, CRSAuthorityFactory, CSAuthorityFactory, DatumAuthorityFactory, CoordinateOperationAuthorityFactory, Factory
Direct Known Subclasses:
AllAuthoritiesFactory

@ThreadSafe
public class MultiAuthoritiesFactory
extends AuthorityFactoryAdapter
implements CRSAuthorityFactory, CSAuthorityFactory, DatumAuthorityFactory, CoordinateOperationAuthorityFactory

An authority factory that delegates the object creation to an other factory determined from the authority part in "authority:code" arguments. The set of factories to use as delegates shall be specified at construction time. This is different than AllAuthoritiesFactory, which get its delegates from the AuthorityFactoryFinder.

This factory requires that every codes given to a createXXX(String) method are prefixed by the authority name, for example "EPSG:4326". When a createXXX(String) method is invoked, this class extracts the authority name from the "authority:code" argument and searches for a factory for that authority in the list of factories given at construction time. If a factory is found, then the work is delegated to that factory. Otherwise a NoSuchAuthorityCodeException is thrown.

This class is not registered in AuthorityFactoryFinder, because it is not a real authority factory. There is not a single authority name associated to this factory, but rather a set of names determined from all available authority factories. If an instance of this class is desired, it must be created explicitly.

Since:
2.4
Version:
3.02
Author:
Martin Desruisseaux (IRD)
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
MultiAuthoritiesFactory(Collection<? extends AuthorityFactory> factories)
          Creates a new factory using the specified set of user factories.
 
Method Summary
 IdentifiedObject createObject(String code)
          Returns an arbitrary object from a code.
 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.
protected
<T extends AuthorityFactory>
T
getAuthorityFactory(Class<T> type, String code)
          Searches for a factory of the given type.
protected  AuthorityFactory getAuthorityFactory(String code)
          Returns an arbitrary object authority factory for the specified "AUTHORITY:NUMBER" code.
 Set<String> getAuthorityNames()
          Returns the authority names of every factories given at construction time.
 String getBackingStoreDescription()
          Returns a description of the underlying backing store, or null if unknown.
protected  CoordinateOperationAuthorityFactory getCoordinateOperationAuthorityFactory(String code)
          Returns the operation authority factory for the specified "AUTHORITY:NUMBER" code.
protected  CRSAuthorityFactory getCRSAuthorityFactory(String code)
          Returns the CRS authority factory for the specified "AUTHORITY:NUMBER" code.
protected  CSAuthorityFactory getCSAuthorityFactory(String code)
          Returns the CS authority factory for the specified "AUTHORITY:NUMBER" code.
protected  DatumAuthorityFactory getDatumAuthorityFactory(String code)
          Returns the datum authority factory for the specified "AUTHORITY:NUMBER" code.
 InternationalString getDescriptionText(String code)
          Gets a description of the object corresponding to a code.
 List<AuthorityFactory> getFactories()
          Returns the factories on which to delegate object creations.
 IdentifiedObjectFinder getIdentifiedObjectFinder(Class<? extends IdentifiedObject> type)
          Returns a finder which can be used for looking up unidentified objects.
protected  char getSeparator(String code)
          Returns the character separator for the specified code.
 Citation getVendor()
          Returns the vendor responsible for creating this factory implementation.
 
Methods inherited from class AuthorityFactoryAdapter
availability, createCartesianCS, createCompoundCRS, createCoordinateOperation, createCoordinateReferenceSystem, createCoordinateSystem, createCoordinateSystemAxis, createCylindricalCS, createDatum, createDerivedCRS, createEllipsoid, createEllipsoidalCS, createEngineeringCRS, createEngineeringDatum, createExtent, createFromCoordinateReferenceSystemCodes, createGeocentricCRS, createGeodeticDatum, createGeographicCRS, createImageCRS, createImageDatum, createOperationMethod, createParameterDescriptor, createPolarCS, createPrimeMeridian, createProjectedCRS, createSphericalCS, createTemporalCRS, createTemporalDatum, createTimeCS, createUnit, createVerticalCRS, createVerticalCS, createVerticalDatum, getImplementationHints, toBackingFactoryCode
 
Methods inherited from class AbstractAuthorityFactory
dispose, noSuchAuthorityCode, trimAuthority
 
Methods inherited from class ReferencingFactory
ensureNonNull
 
Methods inherited from class Factory
equals, hasCompatibleHints, hashCode, setOrdering, toString
 
Methods inherited from class Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface CRSAuthorityFactory
createCompoundCRS, createCoordinateReferenceSystem, createDerivedCRS, createEngineeringCRS, createGeocentricCRS, createGeographicCRS, createImageCRS, createProjectedCRS, createTemporalCRS, createVerticalCRS
 
Methods inherited from interface CSAuthorityFactory
createCartesianCS, createCoordinateSystem, createCoordinateSystemAxis, createCylindricalCS, createEllipsoidalCS, createPolarCS, createSphericalCS, createTimeCS, createUnit, createVerticalCS
 
Methods inherited from interface DatumAuthorityFactory
createDatum, createEllipsoid, createEngineeringDatum, createGeodeticDatum, createImageDatum, createPrimeMeridian, createTemporalDatum, createVerticalDatum
 
Methods inherited from interface CoordinateOperationAuthorityFactory
createCoordinateOperation, createFromCoordinateReferenceSystemCodes, createOperationMethod
 

Constructor Detail

MultiAuthoritiesFactory

public MultiAuthoritiesFactory(Collection<? extends AuthorityFactory> factories)
Creates a new factory using the specified set of user factories. Any call to a createFoo(code) method will scan the supplied factories in their iteration order. The first factory implementing the appropriate interface and having the expected authority name will be used.

If the factories collection contains more than one factory for the same authority and interface, then all additional factories will be fallbacks, to be tried in iteration order only if the first acceptable factory failed to create the requested object.

Parameters:
factories - A set of user-specified factories to try.
Method Detail

getFactories

public List<AuthorityFactory> getFactories()
Returns the factories on which to delegate object creations. For any given "AUTHORITY:CODE" string, this MultiAuthoritiesFactory will delegate the object creation to the first factory from the list having an authority name equals to the "AUTHORITY" part of the above string.

This factory list is determined from the collection given at construction time, but may not be identical.

Returns:
The factories on which this MultiAuthoritiesFactory will delegate object creations, in iteration order.
Since:
3.00

getSeparator

protected char getSeparator(String code)
Returns the character separator for the specified code. The default implementation returns the default name separator ':', except if the code looks like a URL (e.g. "http://www.opengis.net/"), in which case this method returns '/'.

In the current implementation, "looks like a URL" means that the first non-aplhanumeric characters are "://". But this heuristic rule may change in future implementations.

Parameters:
code - The code for which to returns the separator character.
Returns:
The separator character for the given code.

getVendor

public Citation getVendor()
Returns the vendor responsible for creating this factory implementation. The default implementation returns Geotoolkit.org.

Specified by:
getVendor in interface Factory
Overrides:
getVendor in class AuthorityFactoryAdapter
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 database. The default implementation returns a citation with title "All".

Specified by:
getAuthority in interface AuthorityFactory
Overrides:
getAuthority in class AuthorityFactoryAdapter

getAuthorityNames

public Set<String> getAuthorityNames()
Returns the authority names of every factories given at construction time.

Returns:
The authority names of every factories known to this class.

getBackingStoreDescription

public String getBackingStoreDescription()
                                  throws FactoryException
Returns a description of the underlying backing store, or null if unknown.

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

getAuthorityFactory

protected <T extends AuthorityFactory> T getAuthorityFactory(Class<T> type,
                                                             String code)
                                                  throws NoSuchAuthorityCodeException
Searches for a factory of the given type. This method first searches in user-supplied factories. If no user factory is found and this object is an instance of AllAuthoritiesFactory, then this method request for a factory using AuthorityFactoryFinder. The authority name is inferred from the specified code.

Overrides:
getAuthorityFactory in class AuthorityFactoryAdapter
Type Parameters:
T - The type of the authority factory to find.
Parameters:
type - The interface to be implemented.
code - The code of the object to create.
Returns:
The factory.
Throws:
NoSuchAuthorityCodeException - if no suitable factory were found.

getAuthorityFactory

protected final AuthorityFactory getAuthorityFactory(String code)
                                              throws NoSuchAuthorityCodeException
Returns an arbitrary object authority factory for the specified "AUTHORITY:NUMBER" code. This method delegates to getAuthorityFactory(AuthorityFactory.class, code).

Overrides:
getAuthorityFactory in class AuthorityFactoryAdapter
Parameters:
code - The code to parse.
Returns:
The authority factory.
Throws:
NoSuchAuthorityCodeException - if no authority name has been found.

getDatumAuthorityFactory

protected final DatumAuthorityFactory getDatumAuthorityFactory(String code)
                                                        throws NoSuchAuthorityCodeException
Returns the datum authority factory for the specified "AUTHORITY:NUMBER" code. This method delegates to getAuthorityFactory(DatumAuthorityFactory.class, code).

Overrides:
getDatumAuthorityFactory in class AuthorityFactoryAdapter
Parameters:
code - The code to parse.
Returns:
The authority factory.
Throws:
NoSuchAuthorityCodeException - if no authority name has been found.

getCSAuthorityFactory

protected final CSAuthorityFactory getCSAuthorityFactory(String code)
                                                  throws NoSuchAuthorityCodeException
Returns the CS authority factory for the specified "AUTHORITY:NUMBER" code. This method delegates to getAuthorityFactory(CSAuthorityFactory.class, code).

Overrides:
getCSAuthorityFactory in class AuthorityFactoryAdapter
Parameters:
code - The code to parse.
Returns:
The authority factory.
Throws:
NoSuchAuthorityCodeException - if no authority name has been found.

getCRSAuthorityFactory

protected final CRSAuthorityFactory getCRSAuthorityFactory(String code)
                                                    throws NoSuchAuthorityCodeException
Returns the CRS authority factory for the specified "AUTHORITY:NUMBER" code. This method delegates to getAuthorityFactory(CRSAuthorityFactory.class, code).

Overrides:
getCRSAuthorityFactory in class AuthorityFactoryAdapter
Parameters:
code - The code to parse.
Returns:
The authority factory.
Throws:
NoSuchAuthorityCodeException - if no authority name has been found.

getCoordinateOperationAuthorityFactory

protected final CoordinateOperationAuthorityFactory getCoordinateOperationAuthorityFactory(String code)
                                                                                    throws NoSuchAuthorityCodeException
Returns the operation authority factory for the specified "AUTHORITY:NUMBER" code. This method delegates to getAuthorityFactory(CoordinateOperationAuthorityFactory.class, code).

Overrides:
getCoordinateOperationAuthorityFactory in class AuthorityFactoryAdapter
Parameters:
code - The code to parse.
Returns:
The authority factory.
Throws:
NoSuchAuthorityCodeException - if no authority name has been found.

getAuthorityCodes

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

Specified by:
getAuthorityCodes in interface AuthorityFactory
Overrides:
getAuthorityCodes in class AuthorityFactoryAdapter
Parameters:
type - The spatial reference objects type (may be IdentifiedObject.class).
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 FactoryException
Gets a description of the object corresponding to a code.

Specified by:
getDescriptionText in interface AuthorityFactory
Overrides:
getDescriptionText in class AuthorityFactoryAdapter
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:
FactoryException - if the query failed.

createObject

public IdentifiedObject createObject(String code)
                              throws FactoryException
Returns an arbitrary object from a code. This method is the only one to be overridden in this class because it needs to try every kind of factories (datum, CS, CRS, etc.) instead than using a specific type known at compile time.

Specified by:
createObject in interface AuthorityFactory
Overrides:
createObject in class AuthorityFactoryAdapter
Parameters:
code - Value allocated by authority.
Throws:
FactoryException - if the object creation failed.
See Also:
AuthorityFactoryAdapter.createCoordinateReferenceSystem(java.lang.String), AuthorityFactoryAdapter.createDatum(java.lang.String), AuthorityFactoryAdapter.createEllipsoid(java.lang.String), AuthorityFactoryAdapter.createUnit(java.lang.String)

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 the lookups to the underlying factories.

Overrides:
getIdentifiedObjectFinder in class AuthorityFactoryAdapter
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.


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