Class MetadataStandard
- All Implemented Interfaces:
Serializable
org.opengis.metadata package and sub-packages.
This class provides some methods operating on metadata instances through Java reflection. The following rules are assumed:
- Metadata properties are defined by the collection of following getter methods found
in the interface, ignoring implementation methods:
get*()methods with arbitrary return type;- or
is*()methods with boolean return type.
- All properties are readable.
- A property is also writable if a
set*(…)method is defined in the implementation class for the corresponding getter method. The setter method does not need to be defined in the interface.
MetadataStandard is associated with every AbstractMetadata objects.
The AbstractMetadata base class usually form the basis of ISO 19115 implementations but
can also be used for other standards.
Defining new MetadataStandard instances
Users should use the predefined constants when applicable.
However if new instances need to be defined, then there is a choice:
- For read-only metadata,
MetadataStandardcan be instantiated directly. Only getter methods will be used and all operations that modify the metadata properties will throw anUnmodifiableMetadataException. - For read/write metadata, the
getImplementation(Class)method must be overridden in aMetadataStandardsubclass.
Thread safety
The sameMetadataStandard instance can be safely used by many threads without synchronization
on the part of the caller. Subclasses shall make sure that any overridden methods remain safe to call
from multiple threads, because the same MetadataStandard instances are typically referenced
by a large number of ModifiableMetadata instances.- Since:
- 0.3
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final MetadataStandardAn instance working on ISO 19111 standard as defined by GeoAPI interfaces in theorg.opengis.referencingpackage and sub-packages.static final MetadataStandardAn instance working on ISO 19115 standard as defined by GeoAPI interfaces in theorg.opengis.metadatapackage and sub-packages, exceptquality.static final MetadataStandardAn instance working on ISO 19123 standard as defined by GeoAPI interfaces in theorg.opengis.coveragepackage and sub-packages.static final MetadataStandardAn instance working on ISO 19157 standard as defined by GeoAPI interfaces in theorg.opengis.metadata.qualitypackage. -
Constructor Summary
ConstructorsConstructorDescriptionMetadataStandard(Citation citation, Package interfacePackage, MetadataStandard... dependencies) Creates a new instance working on implementation of interfaces defined in the specified package. -
Method Summary
Modifier and TypeMethodDescriptionasIndexMap(Class<?> type, KeyNamePolicy keyPolicy) Returns indices for all properties defined in the given metadata type.asInformationMap(Class<?> type, KeyNamePolicy keyPolicy) Returns information about all properties defined in the given metadata type.asNameMap(Class<?> type, KeyNamePolicy keyPolicy, KeyNamePolicy valuePolicy) Returns the names of all properties defined in the given metadata type.asNilReasonMap(Object metadata, Class<?> baseType, KeyNamePolicy keyPolicy) Returns the reasons for all missing values of mandatory properties.asTreeTable(Object metadata, Class<?> baseType, ValueExistencePolicy valuePolicy) Returns the specified metadata object as a tree table.asTypeMap(Class<?> type, KeyNamePolicy keyPolicy, TypeValuePolicy valuePolicy) Returns the type of all properties, or their declaring type, defined in the given metadata type.asValueMap(Object metadata, Class<?> baseType, KeyNamePolicy keyPolicy, ValueExistencePolicy valuePolicy) Returns a view of the specified metadata object as aMap.equals(Object metadata1, Object metadata2, Class<?> baseType, ComparisonMode criteria) Compares the two specified metadata instances for equality.booleanequals(Object metadata1, Object metadata2, ComparisonMode mode) Deprecated, for removal: This API element is subject to removal in a future version.static MetadataStandardReturns the metadata standard for the given class.Returns a bibliographical reference to the international standard.<T> Class<? extends T> getImplementation(Class<T> type) Returns the implementation class for the given interface, ornullif none.<T> Class<? super T> getInterface(Class<T> type) Returns the metadata interface implemented by the specified implementation class.<T> Class<? super T> getInterface(Class<T> type, Class<?> baseType) Returns the metadata interface by choosing in a subset of the interfaces implemented by the given class.Returns the value of the property that summarizes the given metadata object.intComputes a hash code for the specified metadata.booleanisMetadata(Class<?> type) Returnstrueif the given type is assignable to a type from this standard or one of its dependencies.Returns a string representation of this metadata standard.
-
Field Details
-
ISO_19115
An instance working on ISO 19115 standard as defined by GeoAPI interfaces in theorg.opengis.metadatapackage and sub-packages, exceptquality. -
ISO_19157
An instance working on ISO 19157 standard as defined by GeoAPI interfaces in theorg.opengis.metadata.qualitypackage.- Since:
- 1.3
-
ISO_19111
An instance working on ISO 19111 standard as defined by GeoAPI interfaces in theorg.opengis.referencingpackage and sub-packages. -
ISO_19123
An instance working on ISO 19123 standard as defined by GeoAPI interfaces in theorg.opengis.coveragepackage and sub-packages.
-
-
Constructor Details
-
MetadataStandard
public MetadataStandard(Citation citation, Package interfacePackage, MetadataStandard... dependencies) Creates a new instance working on implementation of interfaces defined in the specified package. If thisMetadataStandarddoes not support a given class, then the dependencies will be tested in the order declared to this constructor. Consequently, ifisMetadata(Class)may returntruefor two or more dependencies, then the dependency which should have precedence should be declared first.Example
For the ISO 19157 standard reflected by GeoAPI interfaces,interfacePackageshall be theorg.opengis.metadata.qualitypackage. Its dependency isISO_19115in theorg.opengis.metadatapackage.- Parameters:
citation- bibliographical reference to the international standard.interfacePackage- the root package for metadata interfaces.dependencies- the dependencies to other metadata standards.
-
-
Method Details
-
forClass
Returns the metadata standard for the given class. The argument given to this method can be either an interface defined by the standard, or a class implementing such interface. If the class implements more than one interface, then the first interface recognized by this method, in declaration order, will be retained.The current implementation recognizes only the standards defined by the public static constants defined in this class. A future SIS version may recognize user-defined constants.
- Parameters:
type- the metadata standard interface, or an implementation class.- Returns:
- the metadata standard for the given type, or
nullif not found.
-
getCitation
Returns a bibliographical reference to the international standard. The default implementation return the citation given at construction time.- Returns:
- bibliographical reference to the international standard.
-
isMetadata
Returnstrueif the given type is assignable to a type from this standard or one of its dependencies. If this method returnstrue, then a call togetInterface(Class)with the same argument will not throwClassCastException. Note however thatgetInterface(type)may throwIllegalArgumentExceptionif the given type is ambiguous.- Parameters:
type- the implementation class (can benull).- Returns:
trueif the given class is an interface of this standard, or is a subtype of at least one interface of this standard.
-
getInterface
Returns the metadata interface implemented by the specified implementation class. If the given type is already an interface from this standard, then that type is returned directly. If the given type does not implement an interface from this standard, then aClassCastExceptionis thrown. If the given type implements more than one interface from this standard, then anIllegalArgumentExceptionis thrown because of the ambiguity.Note: in this context, "interface" should be understood as "the type which is defining the public API". This is usually an interface in the Java sense, but not always.- Type Parameters:
T- the compile-timetype.- Parameters:
type- the implementation class.- Returns:
- the interface implemented by the given implementation class.
- Throws:
ClassCastException- if the given type does not implement an interface of this standard.IllegalArgumentException- if the given type implements more than one interface of this standard.- See Also:
-
getInterface
Returns the metadata interface by choosing in a subset of the interfaces implemented by the given class. This method does the same work asgetInterface(Class)except that it ignores all interfaces that are not assignable tobaseType. This filtering can avoid some ambiguities when the same class implements many interfaces.- Type Parameters:
T- the compile-timetype.- Parameters:
type- the implementation class.baseType- base type of the metadata of interest, ornullif unspecified.- Returns:
- the interface implemented by the given implementation class.
- Throws:
ClassCastException- iftypeis not assignable tobaseType.NoSuchElementException- if the given type does not implement a standard subtype ofbaseType.IllegalArgumentException- if the given type implements more than one standard subtype ofbaseType.- Since:
- 1.7
-
getImplementation
Returns the implementation class for the given interface, ornullif none. If non-null, the returned class must have a public no-argument constructor and the metadata instance created by that constructor must be initially empty (no default value). That no-argument constructor should never throw any checked exception.The default implementation returns
nullin every cases. Subclasses shall override this method in order to map GeoAPI interfaces to their implementation.- Type Parameters:
T- the compile-timetype.- Parameters:
type- the interface, typically from theorg.opengis.metadatapackage.- Returns:
- the implementation class, or
nullif none.
-
getTitle
Returns the value of the property that summarizes the given metadata object. The property is specified by theTitlePropertyannotation on the implementation class. This method first searches forTitlePropertyin the implementation class of the givenmetadata. If the implementation class is not annotated, then this method searches in the implementation class managed by this standard.If the property value is itself another metadata annotated with
TitleProperty, then the search for a title continues recursively in the other metadata. If a cyclic graph is detected, this method returns the last value before the cycle.- Parameters:
metadata- the metadata for which to get the title property, ornull.- Returns:
- the title property value of the given metadata, or empty if none.
- Since:
- 1.7
- See Also:
-
asNameMap
public Map<String,String> asNameMap(Class<?> type, KeyNamePolicy keyPolicy, KeyNamePolicy valuePolicy) Returns the names of all properties defined in the given metadata type. The property names appears both as keys and as values, but may be written differently. The names may be standard identifiers (e.g. as defined by ISO 19115), JavaBeans names, method names or sentences (usually in English).Example
The following code prints"alternateTitles"(note the plural):TheMetadataStandard standard = MetadataStandard.ISO_19115; Map<String, String> names = standard.asNameMap(Citation.class, UML_IDENTIFIER, JAVABEANS_PROPERTY); String value = names.get("alternateTitle"); System.out.println(value); // alternateTitleskeyPolicyargument specify only the string representation of keys returned by the iterators. No matter the key name policy, thekeyargument given to anyMapmethod can be any of the above-cited forms of property names.- Parameters:
type- the interface or implementation class of a metadata.keyPolicy- determines the string representation of map keys.valuePolicy- determines the string representation of map values.- Returns:
- the names of all properties defined by the given metadata type.
- Throws:
ClassCastException- if the metadata class does not implement a metadata interface of this standard.IllegalArgumentException- if the metadata class implements more than one metadata interface of this standard.
-
asTypeMap
public Map<String,Class<?>> asTypeMap(Class<?> type, KeyNamePolicy keyPolicy, TypeValuePolicy valuePolicy) Returns the type of all properties, or their declaring type, defined in the given metadata type. The keys in the returned map are the same as the keys in the above name map. The values are determined by thevaluePolicyargument, which can be element type or the declaring interface among others.Example
the following code prints theInternationalStringclass name:MetadataStandard standard = MetadataStandard.ISO_19115; Map<String, Class<?>> types = standard.asTypeMap(Citation.class, UML_IDENTIFIER, ELEMENT_TYPE); Class<?> value = types.get("alternateTitle"); System.out.println(value); // class org.opengis.util.InternationalString- Parameters:
type- the interface or implementation class of a metadata.keyPolicy- determines the string representation of map keys.valuePolicy- whether the values shall be property types, the element types (same as property types except for collections) or the declaring interface or class.- Returns:
- the types or declaring type of all properties defined in the given metadata type.
- Throws:
ClassCastException- if the metadata class does not implement a metadata interface of this standard.IllegalArgumentException- if the metadata class implements more than one metadata interface of this standard.
-
asInformationMap
public Map<String, ExtendedElementInformation> asInformationMap(Class<?> type, KeyNamePolicy keyPolicy) Returns information about all properties defined in the given metadata type. The keys in the returned map are the same as the keys in the above name map. The values contain information inferred from the ISO names, theObligationenumeration and theValueRangeannotations.In the particular case of Apache SIS implementation, all values in the information map additionally implement the following interfaces:
ReferenceIdentifierwith the following properties:CheckedContainerwith the following properties:- The element type is the type of property values
as defined by
TypeValuePolicy.ELEMENT_TYPE.
- The element type is the type of property values
as defined by
Note: the rational for implementingIn addition, for each map entry the value returned byCheckedContaineris to consider eachExtendedElementInformationinstance as the set of all possible values for the property. If the information had acontains(E)method, it would returntrueif the given value is valid for that property.ExtendedElementInformation.getDomainValue()may optionally be an instance of any of the following classes:NumberRangeif the valid values are constrained to some specific range.
- Parameters:
type- the metadata interface or implementation class.keyPolicy- determines the string representation of map keys.- Returns:
- information about all properties defined in the given metadata type.
- Throws:
ClassCastException- if the metadata class does not implement a metadata interface of this standard.IllegalArgumentException- if the metadata class implements more than one metadata interface of this standard.- See Also:
-
asIndexMap
Returns indices for all properties defined in the given metadata type. The keys in the returned map are the same as the keys in the above name map. The values are arbitrary indices numbered from 0 inclusive to n exclusive, where n is the number of properties declared in the given metadata type.Property indices may be used as an alternative to property names by some applications doing their own storage. Such index usages are fine for temporary storage during the Java Virtual Machine lifetime, but indices should not be used in permanent storage. The indices are stable as long as the metadata implementation does not change, but may change when the implementation is upgraded to a newer version.
- Parameters:
type- the interface or implementation class of a metadata.keyPolicy- determines the string representation of map keys.- Returns:
- indices of all properties defined by the given metadata type.
- Throws:
ClassCastException- if the metadata class does not implement a metadata interface of this standard.IllegalArgumentException- if the metadata class implements more than one metadata interface of this standard.
-
asValueMap
public Map<String,Object> asValueMap(Object metadata, Class<?> baseType, KeyNamePolicy keyPolicy, ValueExistencePolicy valuePolicy) Returns a view of the specified metadata object as aMap. The map is backed by the metadata object using Java reflection, so changes in the underlying metadata object are immediately reflected in the map and conversely.The map content is determined by the arguments:
metadatadetermines the set of keys,keyPolicydetermines theirStringrepresentations of those keys andvaluePolicydetermines whether entries having a null value or an empty collection shall be included in the map.Supported operations
The map supports theput(…)andremove(…)operations if the underlying metadata object contains setter methods. Theremove(…)method is implemented by a call toput(…, null). Note that whether the entry appears as effectively removed from the map or just cleared (i.e. associated with a null value) depends on thevaluePolicyargument.Keys and values
The keys are case-insensitive and can be either the JavaBeans property name, the getter method name or the UML identifier. The value given to a call to theput(…)method shall be an instance of the type expected by the corresponding setter method, or an instance of a type convertible to the expected type.Multi-values entries
Calls toput(…)replace the previous value, with one noticeable exception: if the metadata property associated with the given key is aCollectionbut the given value is a single element (not a collection), then the given value is added to the existing collection. In other words, the returned map behaves as a multi-values map for the properties that allow multiple values. If the intent is to unconditionally discard all previous values, then make sure that the given value is a collection when the associated metadata property expects such collection.Disambiguating instances that implement more than one metadata interface
It is some time convenient to implement more than one interface by the same class. For example, an implementation interested only in extents defined by geographic bounding boxes could implementExtentandGeographicBoundingBoxby the same class. In such case, it is necessary to tell to this method which one of those two interfaces shall be reflected in the returned map. This information can be provided by thebaseTypeargument. That argument needs to be non-null only in situations where an ambiguity can arise;baseTypecan be null if the given metadata implements only one interface recognized by thisMetadataStandardinstance.- Parameters:
metadata- the metadata object to view as a map.baseType- base type of the metadata of interest, ornullif unspecified.keyPolicy- determines the string representation of map keys.valuePolicy- whether the entries having null value or empty collection shall be included in the map.- Returns:
- a map view over the metadata object.
- Throws:
ClassCastException- if the metadata object does not implement a metadata interface of this standard.IllegalArgumentException- if the metadata object implements more than one metadata interface of this standard.- Since:
- 0.8
- See Also:
-
asNilReasonMap
public Map<String, NilReason> asNilReasonMap(Object metadata, Class<?> baseType, KeyNamePolicy keyPolicy) Returns the reasons for all missing values of mandatory properties. The map is backed by the metadata object using Java reflection, so changes in the underlying metadata object are immediately reflected in the map and conversely. Nil reasons are determined by calls toNilReason.forObject(Object), potentially completed by an internal storage for.invalid reference
unsupported value types
Mandatory and optional properties
If a mandatory property has no value, then the property will have an entry in the map even if the associatedNilReasonis null. By contrast, optional properties have entries in the map only if they have a non-nullNilReason.Supported operations
The map supports theput(…)andremove(…)operations if the underlying metadata object contains setter methods. Theremove(…)method is implemented by a call toput(…, null).- Parameters:
metadata- the metadata object to view as a map.baseType- base type of the metadata of interest, ornullif unspecified.keyPolicy- determines the string representation of map keys.- Returns:
- a map view over the metadata object.
- Throws:
ClassCastException- if the metadata object does not implement a metadata interface of this standard.IllegalArgumentException- if the metadata object implements more than one metadata interface of this standard.- Since:
- 1.5
- See Also:
-
asTreeTable
Returns the specified metadata object as a tree table. The tree table is backed by the metadata object using Java reflection, so changes in the underlying metadata object are immediately reflected in the tree table and conversely.The returned
TreeTableinstance contains the columns listed below. The(IDENTIFIER, INDEX)pair of columns can be used as a primary key for uniquely identifying a node in a list of children. That uniqueness is guaranteed only for the children of a given node. The same keys may appear in the children of any other nodes.TableColumn.IDENTIFIER
The UML identifier if any, or the Java Beans property name otherwise, of a metadata property. For example in a tree table view ofDefaultCitation, there is a node having the"title"identifier.TableColumn.INDEX
If the metadata property is a collection, then the zero-based index of the element in that collection. Otherwisenull. For example, in a tree table view ofDefaultCitation, if the"alternateTitle"collection contains two elements, then there is a node with index 0 for the first element and another node with index 1 for the second element.TableColumn.NAME
A human-readable name for the node, derived from the identifier and the index. This is the column shown in the defaulttoString()implementation and may be localizable.TableColumn.TYPE
The base type of the value (usually an interface).TableColumn.OBLIGATION
Whether the property is mandatory, optional or conditional.TableColumn.VALUE
The metadata value for the node. Values in this column are writable if the underlying metadata class have a setter method for the property represented by the node.NIL_REASON
If the property is mandatory and nevertheless absent, the reason why. This column is included only ifvaluePolicyaccepts nil values. Values are instances ofNilReason.TableColumn.REMARKS
Remarks or warning on the property value. This is rarely present. It is provided when the value may look surprising, for example the longitude values in a geographic bounding box crossing the anti-meridian.
Write operations
Only theVALUEcolumn may be writable, with one exception: newly created children need to have theirIDENTIFIERset before any other operation. For example, the following code adds a title to a citation:Nodes can be removed by invoking theTreeTable.Node node = ...; // The node for a DefaultCitation. TreeTable.Node child = node.newChild(); child.setValue(TableColumn.IDENTIFIER, "title"); child.setValue(TableColumn.VALUE, "Le petit prince"); // Nothing else to do - the child node has been added.Iterator.remove()method on the children iterator. Note that whether the child appears as effectively removed from the node or just cleared (i.e. associated with a null value) depends on thevaluePolicyargument.Disambiguating instances that implement more than one metadata interface
If the givenmetadatainstance implements more than one interface recognized by thisMetadataStandard, then thebaseTypeargument need to be non-null in order to specify which interface to reflect in the tree.- Parameters:
metadata- the metadata object to view as a tree table.baseType- base type of the metadata of interest, ornullif unspecified.valuePolicy- whether the property having null value or empty collection shall be included in the tree.- Returns:
- a tree table representation of the specified metadata.
- Throws:
ClassCastException- if the metadata object does not implement a metadata interface of this standard.IllegalArgumentException- if the metadata object implements more than one metadata interface of this standard.- Since:
- 0.8
- See Also:
-
equals
@Deprecated(since="1.7", forRemoval=true) public boolean equals(Object metadata1, Object metadata2, ComparisonMode mode) Deprecated, for removal: This API element is subject to removal in a future version.Replaced byequals(Object, Object, Class, ComparisonMode)because this method is ambiguous when one of the given metadata instances implements more than one metadata interface.Compares the two specified metadata objects for equality. The two metadata arguments shall be implementations of a metadata interface defined by thisMetadataStandard, otherwise an exception will be thrown. However, the two arguments do not need to be instances of the same implementation class except forComparisonMode.STRICT.- Parameters:
metadata1- the first metadata object to compare, ornull.metadata2- the second metadata object to compare, ornull.mode- the strictness level of the comparison.- Returns:
trueif the given metadata objects are equal or if the two arguments arenull.
-
equals
public Boolean equals(Object metadata1, Object metadata2, Class<?> baseType, ComparisonMode criteria) Compares the two specified metadata instances for equality. The two metadata arguments should be implementations of a metadata interface defined by thisMetadataStandard. However, they do not need to be of the exact same class unlesscriteriaisComparisonMode.STRICT. If the equality cannot be determined in a non-ambiguous way, for example because the given metadata instances do not implement exactly one interface assignable tobaseType, then this method returnsnull.Resolution of type ambiguity
Because some metadata standards define hundreds of interfaces, some metadata classes may implement many interfaces at once for convenience. For avoiding ambiguity, the interface of interest, or a non-ambiguous super-type of the interface of interest, should be specified in thebaseTypeargument. This information can be obtained, for example, from the return type of the method that provided the metadata. Only properties inherited from interfaces that are assignable tobaseTypewill be compared. IfbaseTypeisnull, then this method tries to find the base type automatically. The latter is not always equivalent to specifyingObject.classas the base type.- Parameters:
metadata1- the first metadata object to compare, ornull.metadata2- the second metadata object to compare, ornull.baseType- base type of the metadata of interest, ornullif unspecified.criteria- the strictness level of the comparison.- Returns:
- whether the given metadata objects are equal, or
nullif undetermined. - Throws:
ClassCastException- ifmetadata1is non-null and not an instance ofbaseType.- Since:
- 1.7
- See Also:
-
hashCode
Computes a hash code for the specified metadata. The hash code is defined as the sum of hash code values of all non-empty properties, plus the hash code of the interface. This is a similar contract thanSet.hashCode()(except for the interface) and ensures that the hash code value is insensitive to the ordering of properties.- Parameters:
metadata- the metadata object to compute hash code.- Returns:
- a hash code value for the specified metadata, or 0 if the given metadata is null.
- Throws:
ClassCastException- if the metadata object does not implement a metadata interface of this standard.IllegalArgumentException- if the metadata object implements more than one metadata interface of this standard.- See Also:
-
toString
-
equals(Object, Object, Class, ComparisonMode)because this method is ambiguous when one of the given metadata instances implements more than one metadata interface.