Class AbstractIdentifiedObject
- All Implemented Interfaces:
Serializable
,Formattable
,Deprecable
,LenientComparable
,org.opengis.referencing.IdentifiedObject
- Direct Known Subclasses:
AbstractCoordinateOperation
,AbstractCS
,AbstractDatum
,AbstractParameterDescriptor
,AbstractReferenceSystem
,DefaultCoordinateSystemAxis
,DefaultEllipsoid
,DefaultOperationMethod
,DefaultPrimeMeridian
"EPSG:3395"
), can be used for fetching an object from a database.
However, it is not sufficient to know the object name. We also need to know who define that name
(the authority) since the same objects are often named differently
depending on the providers, or conversely the same name is used for different objects depending on the provider.
The main information stored in an IdentifiedObject
are:
- a primary name, considered by the object creator as the preferred name,
- an arbitrary number of aliases, for example a list of names used by other providers,
- an arbitrary number of identifiers, typically primary keys in the provider database,
- optional remarks.
Instantiation
This class is conceptually abstract, even if it is technically possible to instantiate it. Applications should instead instantiate the most specific subclass having a name starting byDefault
.
However, exceptions to this rule may occur when it is not possible to identify the exact type.
LOCAL_CS
element.
In such exceptional situation, a plain AbstractCS
object may be instantiated.IdentifiedObject
instances are created in two main ways:
- Using an
ObjectFactory
, in which case all properties can be explicitly specified. - Using an
AuthorityFactory
, in which case only a code (typically a primary key) is specified. The authority and authority code values are set to the authority name of the factory object, and the authority code supplied by the client, respectively. All other information are fetched from the database.
Immutability and thread safety
This base class is immutable if theCitation
, ReferenceIdentifier
, GenericName
and
InternationalString
instances given to the constructor are also immutable. Most SIS subclasses and
related classes are immutable under similar conditions. This means that unless otherwise noted in the javadoc,
IdentifiedObject
instances created using only SIS factories and static constants can be shared by many
objects and passed between threads without synchronization.- Since:
- 0.4
- Version:
- 1.1
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate final class
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Collection
<org.opengis.util.GenericName> An alternative name by which this object is identified, ornull
if none.private final boolean
true
if this object is deprecated.static final String
Optional key which can be given to the constructor for specifying the object is deprecated.private int
The cached hash code value, or 0 if not yet computed.private Set
<org.opengis.referencing.ReferenceIdentifier> An identifier which references elsewhere the object's defining information.static final String
Optional key which can be given to the constructor for specifying the locale to use for producing error messages.private org.opengis.referencing.ReferenceIdentifier
The name for this object or code.private org.opengis.util.InternationalString
Comments on or information about this object, ornull
if none.private static final long
Serial number for inter-operability with different versions.Fields inherited from interface org.opengis.referencing.IdentifiedObject
ALIAS_KEY, IDENTIFIERS_KEY, NAME_KEY, REMARKS_KEY
-
Constructor Summary
ConstructorsModifierConstructorDescription(package private)
Constructs a new object in which every attributes are set to a null value.AbstractIdentifiedObject
(Map<String, ?> properties) Constructs an object from the given properties.protected
AbstractIdentifiedObject
(org.opengis.referencing.IdentifiedObject object) Constructs a new identified object with the same values than the specified one. -
Method Summary
Modifier and TypeMethodDescriptionstatic AbstractIdentifiedObject
castOrCopy
(org.opengis.referencing.IdentifiedObject object) Returns a SIS identified object implementation with the values of the given arbitrary implementation.protected long
Invoked byhashCode()
for computing the hash code when first needed.final boolean
Compares the specified object with this object for equality.boolean
equals
(Object object, ComparisonMode mode) Compares this object with the given object for equality.void
Formats the name or identifier of this object using the provider formatter.protected String
Formats the inner part of the Well Known Text (WKT) representation for this object.Collection
<org.opengis.util.GenericName> getAlias()
Returns alternative names by which this object is identified.org.opengis.util.InternationalString
Returns a narrative explanation of the role of this object.(package private) final String
getID()
Thegml:id
, which is mandatory.(package private) final Code
Returns a single element from theSet<Identifier>
collection, ornull
if none.Set
<org.opengis.referencing.ReferenceIdentifier> Returns identifiers which references elsewhere the object's defining information.Class
<? extends org.opengis.referencing.IdentifiedObject> Returns the GeoAPI interface implemented by this class.org.opengis.referencing.ReferenceIdentifier
getName()
Returns the primary name by which this object is identified.(package private) final Collection
<org.opengis.referencing.ReferenceIdentifier> getNames()
Returns thename
and all aliases which are also instance ofIdentifier
.org.opengis.util.InternationalString
Returns comments on or information about this object, including data source information.final int
hashCode()
Returns a hash value for this identified object.private static IllegalArgumentException
illegalPropertyType
(Map<String, ?> properties, String key, Object value) Returns the exception to be thrown when a property is of illegal type.private boolean
implementsSameInterface
(Object object) Returnstrue
if the given object implements the same GeoAPI interface than this object.boolean
Returnstrue
if this object is deprecated.boolean
Returnstrue
if either the primary name or at least one alias matches the given string according heuristic rules.private void
Invoked by JAXB at unmarhalling time for specifying the value of thegml:id
attribute.private void
setIdentifier
(Code identifier) Invoked by JAXB at unmarshalling time for setting the identifier.private void
setRemarks
(org.opengis.util.InternationalString value) Invoked by JAXB for setting the remarks.Methods inherited from class org.apache.sis.io.wkt.FormattableObject
print, toString, toString, toWKT
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.opengis.referencing.IdentifiedObject
toWKT
-
Field Details
-
serialVersionUID
private static final long serialVersionUIDSerial number for inter-operability with different versions.- See Also:
-
LOCALE_KEY
Optional key which can be given to the constructor for specifying the locale to use for producing error messages. Notes:- The locale is not stored in any
AbstractIdentifiedObject
property; its value is ignored if no error occurred at construction time. - The locale is used on a best effort basis; not all error messages may be localized.
- See Also:
- The locale is not stored in any
-
DEPRECATED_KEY
Optional key which can be given to the constructor for specifying the object is deprecated. If deprecated, then the replacement should be specified in the remarks.Example: "superseded by code XYZ".- Since:
- 0.6
- See Also:
-
name
private org.opengis.referencing.ReferenceIdentifier nameThe name for this object or code. Shall never benull
.Consider this field as final! This field is modified only at unmarshalling time by
Names.add(Identifier)
.- See Also:
-
alias
An alternative name by which this object is identified, ornull
if none. We must be prepared to handle either null or an empty set for "no alias" because we may get both on unmarshalling.Consider this field as final! This field is modified only at unmarshalling time by
Names.add(Identifier)
. -
identifiers
An identifier which references elsewhere the object's defining information. Alternatively, an identifier by which this object can be referenced.Consider this field as final! This field is modified only at unmarshalling time by
setIdentifier(Code)
- See Also:
-
remarks
private org.opengis.util.InternationalString remarksComments on or information about this object, ornull
if none.Consider this field as final! This field is modified only at unmarshalling time by
setRemarks(InternationalString)
- See Also:
-
deprecated
private final boolean deprecatedtrue
if this object is deprecated.- Since:
- 0.6
-
hashCode
private transient int hashCodeThe cached hash code value, or 0 if not yet computed. This field is calculated only when first needed. We do not declare itvolatile
because it is not a big deal if this field is calculated many time, and the same value should be produced by all computations. The only possible outdated value is 0, which is okay.
-
-
Constructor Details
-
AbstractIdentifiedObject
Constructs an object from the given properties. Keys are strings from the table below. The map given in argument shall contain an entry at least for the "name" or "code" key. Other properties listed in the table below are optional. In particular,"authority"
,"code"
,"codespace"
and"version"
are convenience properties for building a name, and are ignored if the"name"
property is already aReferenceIdentifier
object instead of aString
.Recognized properties (non exhaustive list) Property name Value type Returned by "name" ReferenceIdentifier
orString
getName()
"authority" String
orCitation
ImmutableIdentifier.getAuthority()
on the name"code" String
ImmutableIdentifier.getCode()
on the name"codespace" String
ImmutableIdentifier.getCodeSpace()
on the name"version" String
ImmutableIdentifier.getVersion()
on the name"description" String
ImmutableIdentifier.getDescription()
on the name"alias" GenericName
orCharSequence
(optionally as array)getAlias()
"identifiers" ReferenceIdentifier
(optionally as array)getIdentifiers()
"remarks" InternationalString
orString
getRemarks()
"deprecated" Boolean
isDeprecated()
"locale" Locale
(none) Localization
All localizable attributes like"remarks"
may have a language and country code suffix. For example, the"remarks_fr"
property stands for remarks in French and the"remarks_fr_CA"
property stands for remarks in French Canadian. They are convenience properties for building theInternationalString
value.The
"locale"
property applies only in case of exception for formatting the error message, and is used only on a best effort basis. The locale is discarded after successful construction since localizations are applied by theInternationalString.toString(Locale)
method.Properties map versus explicit arguments
Generally speaking, information provided in theproperties
map are considered ignorable metadata while information provided in explicit arguments to the sub-class constructors have an impact on coordinate transformation results. Seeequals(Object, ComparisonMode)
for more information.- Parameters:
properties
- the properties to be given to this identified object.- Throws:
IllegalArgumentException
- if a property has an invalid value.
-
AbstractIdentifiedObject
protected AbstractIdentifiedObject(org.opengis.referencing.IdentifiedObject object) Constructs a new identified object with the same values than the specified one. This copy constructor provides a way to convert an arbitrary implementation into a SIS one or a user-defined one (as a subclass), usually in order to leverage some implementation-specific API.This constructor performs a shallow copy, i.e. the properties are not cloned.
- Parameters:
object
- the object to shallow copy.
-
AbstractIdentifiedObject
AbstractIdentifiedObject()Constructs a new object in which every attributes are set to a null value. This is not a valid object. This constructor is strictly reserved to JAXB, which will assign values to the fields using reflection.
-
-
Method Details
-
illegalPropertyType
private static IllegalArgumentException illegalPropertyType(Map<String, ?> properties, String key, Object value) Returns the exception to be thrown when a property is of illegal type. -
castOrCopy
Returns a SIS identified object implementation with the values of the given arbitrary implementation. This method performs the first applicable action in the following choices:- If the given object is
null
, then this method returnsnull
. - Otherwise if the given object is an instance of
CoordinateReferenceSystem
,CoordinateSystem
,CoordinateSystemAxis
,Datum
,Ellipsoid
,PrimeMeridian
,OperationMethod
,CoordinateOperation
,ParameterDescriptor
orParameterDescriptorGroup
, then this method delegates to thecastOrCopy(…)
method of the corresponding SIS subclass. Note that if the given object implements more than one of the above-cited interfaces, then thecastOrCopy(…)
method to be used is unspecified. - Otherwise if the given object is already an instance of
AbstractIdentifiedObject
, then it is returned unchanged. - Otherwise a new
AbstractIdentifiedObject
instance is created using the copy constructor and returned. Note that this is a shallow copy operation, because the other properties contained in the given object are not recursively copied.
- Parameters:
object
- the object to get as a SIS implementation, ornull
if none.- Returns:
- a SIS implementation containing the values of the given object (may be the
given object itself), or
null
if the argument was null.
- If the given object is
-
getInterface
Returns the GeoAPI interface implemented by this class. This information is part of the data compared byequals(Object, ComparisonMode)
.The default implementation returns
IdentifiedObject.class
. Subclasses implementing a more specific GeoAPI interface shall override this method.Invariants
The following invariants must hold for allAbstractIdentifiedObject
instances:getInterface().isInstance(this)
shall returntrue
.- If
A.getClass() == B.getClass()
istrue
, thenA.getInterface() == B.getInterface()
shall betrue
. Note that the converse does not need to hold.
- Returns:
- the GeoAPI interface implemented by this class.
-
getName
public org.opengis.referencing.ReferenceIdentifier getName()Returns the primary name by which this object is identified.- Specified by:
getName
in interfaceorg.opengis.referencing.IdentifiedObject
- Returns:
- the primary name.
- See Also:
-
getAlias
Returns alternative names by which this object is identified.- Specified by:
getAlias
in interfaceorg.opengis.referencing.IdentifiedObject
- Returns:
- the aliases, or an empty collection if there is none.
- See Also:
-
getIdentifiers
Returns identifiers which references elsewhere the object's defining information. Alternatively, identifiers by which this object can be referenced.- Specified by:
getIdentifiers
in interfaceorg.opengis.referencing.IdentifiedObject
- Returns:
- this object identifiers, or an empty set if there is none.
- See Also:
-
getDescription
public org.opengis.util.InternationalString getDescription()Returns a narrative explanation of the role of this object.Default value
The default implementation returns the description provided by this object's name.- Returns:
- a narrative explanation of the role of this object, or
null
if none. - Since:
- 0.6
- See Also:
-
getRemarks
public org.opengis.util.InternationalString getRemarks()Returns comments on or information about this object, including data source information. If this object is deprecated, then the remarks should give indication about the replacement (e.g. "superceded by …").- Specified by:
getRemarks
in interfaceDeprecable
- Specified by:
getRemarks
in interfaceorg.opengis.referencing.IdentifiedObject
- Returns:
- the remarks, or
null
if none.
-
isDeprecated
public boolean isDeprecated()Returnstrue
if this object is deprecated. Deprecated objects exist in some authority factories like the EPSG database. If this method returnstrue
, then the remarks should give indication about the replacement (e.g. "superceded by …").- Specified by:
isDeprecated
in interfaceDeprecable
- Returns:
true
if this object is deprecated.
-
isHeuristicMatchForName
Returnstrue
if either the primary name or at least one alias matches the given string according heuristic rules. The default implementation returnstrue
if the givenname
is equal, ignoring aspects documented below, to one of the following names: The comparison ignores the following aspects:- Lower/upper cases.
- Some Latin diacritical signs (e.g.
"Réunion"
and"Reunion"
are considered equal). - All characters that are not letters or digits
(e.g.
"Mercator (1SP)"
and"Mercator_1SP"
are considered equal). - Namespaces or scopes, because this method is typically invoked with either the value of another
IdentifiedObject.getName().getCode()
or with the Well Known Text (WKT) projection or parameter name.
Usage
This method is invoked by SIS when comparing inIGNORE_METADATA
mode two objects that can be differentiated only by some identifier (name or alias), like coordinate system axes, datum, parameters and operation methods. Seeequals(Object, ComparisonMode)
for more information.This method is also invoked when searching a parameter or operation method for a given name. For example, the same projection is known as
"Mercator (variant A)"
(the primary name according EPSG) and"Mercator (1SP)"
(the legacy name prior EPSG 7.6). Since the latter is still in frequent use, SIS accepts it as an alias of the Mercator (variant A) projection.Overriding by subclasses
Some subclasses add more flexibility to the comparisons:- Comparisons of coordinate system axis names consider
"Lat"
,"Latitude"
and"Geodetic latitude"
as synonymous, and likewise for longitude. - Comparisons of datum names ignore the
"D_"
prefix, if any. This prefix appears in ESRI datum name (e.g."D_WGS_1984"
). - Comparisons of geodetic datum names may ignore the prime meridian name, if any. Example: "(Paris)" in "Nouvelle Triangulation Française (Paris)".
Future evolutions
This method implements recommendations from the WKT 2 specification §B.5.2, together with heuristic rules learned from experience while trying to provide inter-operability with different data producers. Those rules may be adjusted in any future SIS version according experience gained while working with more data producers.- Parameters:
name
- the name to compare with the object name or aliases.- Returns:
true
if the primary name or at least one alias matches the specifiedname
.- See Also:
-
equals
Compares this object with the given object for equality. The strictness level is controlled by the second argument, from stricter to more permissive values:Description of comparison modes Mode Description STRICT
:Verifies if the two objects are of the same class and compares all public properties, including SIS-specific (non standard) properties. BY_CONTRACT
:Verifies if the two objects implement the same GeoAPI interface and compares all properties defined by that interface (name, identifiers, remarks, etc). The two objects do not need to be instances of the same implementation class and SIS-specific properties are ignored. IGNORE_METADATA
:Compares only the properties relevant to coordinate transformations. Generally speaking, the content of the properties
map given at construction time is considered ignorable metadata while the explicit arguments given to the constructor (if any) are considered non-ignorable. Note that there is some exceptions to this rule of thumb — see When object name matter below.APPROXIMATE
:Same as IGNORE_METADATA
, with some tolerance threshold on numerical values.ALLOW_VARIANT
:Same as APPROXIMATE
, but ignores coordinate system axes.DEBUG
:Special mode for figuring out why two objects expected to be equal are not. sourceCRS.equals(targetCRS, IGNORE_METADATA)
returnstrue
, then the transformation fromsourceCRS
totargetCRS
should be the identity transform even if the two CRS do not have the same name.When object name matter
Some subclasses (especiallyDefaultCoordinateSystemAxis
,AbstractDatum
andDefaultParameterDescriptor
) will compare the name even inIGNORE_METADATA
mode, because objects of those types with different names have completely different meaning. For example, nothing differentiate the"semi_major"
and"semi_minor"
parameters except the name. The name comparison may be lenient however, i.e. the rules may accept a name matching an alias. SeeisHeuristicMatchForName(String)
for more information.Conformance to the
equals(Object)
method contractComparisonMode.STRICT
is the only mode compliant with theObject.equals(Object)
contract. For all other modes, the comparison is not guaranteed to be symmetric neither transitive. SeeLenientComparable
for more information.- Specified by:
equals
in interfaceLenientComparable
- Parameters:
object
- the object to compare tothis
.mode
- the strictness level of the comparison.- Returns:
true
if both objects are equal according the given comparison mode.- See Also:
-
implementsSameInterface
Returnstrue
if the given object implements the same GeoAPI interface than this object. -
equals
Compares the specified object with this object for equality. This method is implemented as below (omitting assertions): Subclasses shall overrideequals(Object, ComparisonMode)
instead of this method.- Specified by:
equals
in interfaceLenientComparable
- Overrides:
equals
in classObject
- Parameters:
object
- the other object (may benull
).- Returns:
true
if both objects are equal.- See Also:
-
hashCode
public final int hashCode()Returns a hash value for this identified object. TwoAbstractIdentifiedObject
instances for whichequals(Object)
returnstrue
shall have the same hash code value, if the hash codes are computed on the same JVM instance for both objects. The hash code value is not guaranteed to be stable between different versions of the Apache SIS library, or between libraries running on different JVM.Implementation note
This method invokescomputeHashCode()
when first needed, then caches the result. Subclasses shall overridecomputeHashCode()
instead of this method. -
computeHashCode
protected long computeHashCode()Invoked byhashCode()
for computing the hash code when first needed. This method is invoked at most once in normal execution, or an arbitrary number of times if Java assertions are enabled. The hash code value shall never change during the whole lifetime of this object in a JVM. The hash code value does not need to be the same in two different executions of the JVM.Overriding
Subclasses can override this method for using more properties in hash code calculation. AllcomputeHashCode()
methods shall invokesuper.computeHashCode()
, nothashCode()
. Example:- Returns:
- the hash code value. This value may change in any future Apache SIS version.
-
formatTo
Formats the inner part of the Well Known Text (WKT) representation for this object. The default implementation writes the following elements:- The object name.
GeodeticCRS[…]
element, then subclasses shall write the content starting at the insertion point shown below:WKT example
Java code example
Formatting non-standard WKT
If the implementation cannot represent this object without violating some WKT constraints, it can uses its own (non-standard) keywords but shall declare that it did so by invoking one of theFormatter.setInvalidWKT(…)
methods.Alternatively, the implementation may also have no WKT keyword for this object. In such case, this method shall return
null
.- Specified by:
formatTo
in classFormattableObject
- Parameters:
formatter
- the formatter where to format the inner content of this WKT element.- Returns:
- the CamelCase keyword
for the WKT element, or
null
if unknown. - See Also:
-
formatTo
Formats the name or identifier of this object using the provider formatter. This method is invoked when anIdentifiedObject
object is formatted using the"%s"
conversion specifier ofFormatter
. Users don't need to invoke this method explicitly.If the alternate flags is present (as in
"%#s"
), then this method will format the identifier (if present) instead of the object name.- Specified by:
formatTo
in interfaceFormattable
- Parameters:
formatter
- the formatter in which to format this identified object.flags
- whether to apply left alignment, use upper-case letters and/or use alternate form.width
- minimal number of characters to write, padding with' '
if necessary.precision
- maximal number of characters to write, or -1 if no limit.- Since:
- 1.1
- See Also:
-
getID
Thegml:id
, which is mandatory. The current implementation searches for the first identifier, regardless its authority. If no identifier is found, then the name or aliases are used. If none of the above is found (which should not occur for valid objects), then this method returnsnull
.If an identifier or a name has been found, this method returns the concatenation of the following elements separated by hyphens:
- The code space in lower case, retaining only characters that are valid for Unicode identifiers.
- The object type as defined in OGC's URN (see
DefinitionURI
) - The object code, retaining only characters that are valid for Unicode identifiers.
"epsg-crs-4326"
.The returned ID needs to be unique only in the XML document being marshalled. Consecutive invocations of this method do not need to return the same value, since it may depends on the marshalling context.
-
setID
Invoked by JAXB at unmarhalling time for specifying the value of thegml:id
attribute. That GML identifier is not actually stored in thisAbstractIdentifiedObject
since we rather generate it dynamically from the ISO 19111 identifiers. But we still need to declare that identifier to our unmarshaller context, in case it is referenced from elsewhere in the XML document. -
getIdentifier
Returns a single element from theSet<Identifier>
collection, ornull
if none. We have to define this method because ISO 19111 defines theidentifiers
property as a collection while GML 3.2 defines it as a singleton.This method searches for the following identifiers, in preference order:
- The first identifier having a code that begin with
"urn:"
. - The first identifier having a code that begin with
"http:"
. - The first identifier, converted to the
"urn:
syntax if possible.
- The first identifier having a code that begin with
-
setIdentifier
Invoked by JAXB at unmarshalling time for setting the identifier. -
getNames
Returns thename
and all aliases which are also instance ofIdentifier
. The latter happen often in SIS implementation since many aliases are instance ofNamedIdentifier
.The returned collection is live: adding elements in that collection will modify this
AbstractIdentifiedObject
instance. This is needed for unmarshalling with JAXB and should not be used in other context.Why there is no
Some JAXB implementations never invoke setter method for collections. Instead, they invoke the getter and add directly the identifiers in the returned collection. Whether JAXB will perform or not a final call tosetNames(…)
methodsetNames(…)
is JAXB-implementation dependent (JDK7 does but JDK6 and JDK8 early access do not). It seems a more portable approach (at least for JAXB reference implementations) to design our class without setter method, in order to have the same behavior on all supported JDK versions.- See Also:
-
setRemarks
private void setRemarks(org.opengis.util.InternationalString value) Invoked by JAXB for setting the remarks.- See Also:
-