public class MetadataStandard extends Object implements 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:
get*()
methods with arbitrary return type;is*()
methods with boolean return type.set*(…)
method is defined
in the implementation class for the corresponding getter method.
The setter method doesn't need to be defined in the interface.MetadataStandard
is associated to every AbstractMetadata
objects.
The AbstractMetadata
base class usually form the basis of ISO 19115 implementations but
can also be used for other standards.
MetadataStandard
instancesMetadataStandard
can be instantiated directly.
Only getter methods will be used and all operations that modify the metadata properties
will throw an UnmodifiableMetadataException
.getImplementation(Class)
method must be overridden in a MetadataStandard
subclass.MetadataStandard
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 amount of ModifiableMetadata
.AbstractMetadata
,
Serialized FormDefined in the sis-metadata
module
Modifier and Type | Field and Description |
---|---|
static MetadataStandard |
ISO_19111
An instance working on ISO 19111 standard as defined by GeoAPI interfaces
in the
org.opengis.referencing package and sub-packages. |
static MetadataStandard |
ISO_19115
An instance working on ISO 19115 standard as defined by GeoAPI interfaces
in the
org.opengis.metadata package and sub-packages. |
static MetadataStandard |
ISO_19119
An instance working on ISO 19119 standard as defined by GeoAPI interfaces
in the
org.opengis.service package and sub-packages. |
static MetadataStandard |
ISO_19123
An instance working on ISO 19123 standard as defined by GeoAPI interfaces
in the
org.opengis.coverage package and sub-packages. |
Constructor and Description |
---|
MetadataStandard(Citation citation,
Package interfacePackage)
Creates a new instance working on implementation of interfaces defined in the specified package.
|
Modifier and Type | Method and Description |
---|---|
Map<String,ExtendedElementInformation> |
asInformationMap(Class<?> type,
KeyNamePolicy keyPolicy)
Returns information about all properties defined in the given metadata type.
|
Map<String,String> |
asNameMap(Class<?> type,
KeyNamePolicy keyPolicy,
KeyNamePolicy valuePolicy)
Returns the names of all properties defined in the given metadata type.
|
TreeTable |
asTreeTable(Object metadata,
ValueExistencePolicy valuePolicy)
Returns the specified metadata object as a tree table.
|
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.
|
Map<String,Object> |
asValueMap(Object metadata,
KeyNamePolicy keyPolicy,
ValueExistencePolicy valuePolicy)
Returns a view of the specified metadata object as a
Map . |
boolean |
equals(Object metadata1,
Object metadata2,
ComparisonMode mode)
Compares the two specified metadata objects.
|
static MetadataStandard |
forClass(Class<?> type)
Returns the metadata standard for the given class.
|
Citation |
getCitation()
Returns a bibliographical reference to the international standard.
|
Class<?> |
getImplementation(Class<?> type)
Returns the implementation class for the given interface, or
null if none. |
Class<?> |
getInterface(Class<?> type)
Returns the metadata interface implemented by the specified implementation class.
|
int |
hashCode(Object metadata)
Computes a hash code for the specified metadata.
|
boolean |
isMetadata(Class<?> type)
Returns
true if the given type is assignable to a type from this standard. |
String |
toString()
Returns a string representation of this metadata standard.
|
public static final MetadataStandard ISO_19111
org.opengis.referencing
package and sub-packages.public static final MetadataStandard ISO_19115
org.opengis.metadata
package and sub-packages.public static final MetadataStandard ISO_19119
org.opengis.service
package and sub-packages.public static final MetadataStandard ISO_19123
org.opengis.coverage
package and sub-packages.public MetadataStandard(Citation citation, Package interfacePackage)
Example:: For the ISO 19115 standard reflected by GeoAPI interfaces,
interfacePackage
shall be the org.opengis.metadata
package.
citation
- Bibliographical reference to the international standard.interfacePackage
- The root package for metadata interfaces.public static MetadataStandard forClass(Class<?> type)
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.
type
- The metadata standard interface, or an implementation class.null
if not found.public Citation getCitation()
public boolean isMetadata(Class<?> type)
true
if the given type is assignable to a type from this standard.
If this method returns true
, then invoking getInterface(Class)
is
guaranteed to succeed without throwing an exception.type
- The implementation class (can be null
).true
if the given class is an interface of this standard,
or implements an interface of this standard.public Class<?> getInterface(Class<?> type) throws ClassCastException
type
- The implementation class.ClassCastException
- if the specified implementation class does
not implement an interface of this standard.AbstractMetadata.getInterface()
public Class<?> getImplementation(Class<?> type)
null
if none.
The default implementation returns null
if every cases. Subclasses shall
override this method in order to map GeoAPI interfaces to their implementation.type
- The interface, typically from the org.opengis.metadata
package.null
if none.public Map<String,String> asNameMap(Class<?> type, KeyNamePolicy keyPolicy, KeyNamePolicy valuePolicy) throws ClassCastException
"alternateTitles"
(note the plural):
MetadataStandard 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); // alternateTitles
keyPolicy
argument specify only the string representation of keys returned by the iterators.
No matter the key name policy, the key
argument given to any Map
method can be any of the
above-cited forms of property names.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.ClassCastException
- if the specified interface or implementation class does
not extend or implement a metadata interface of the expected package.public Map<String,Class<?>> asTypeMap(Class<?> type, KeyNamePolicy keyPolicy, TypeValuePolicy valuePolicy) throws ClassCastException
valuePolicy
argument, which can be element type or the
declaring interface among others.
Example: the following code prints the
InternationalString
class 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
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.ClassCastException
- if the specified interface or implementation class does
not extend or implement a metadata interface of the expected package.public Map<String,ExtendedElementInformation> asInformationMap(Class<?> type, KeyNamePolicy keyPolicy) throws ClassCastException
Obligation
enumeration and the
ValueRange
annotations.
In the particular case of Apache SIS implementation, all values in the information map additionally implement the following interfaces:
ReferenceIdentifier
with the following properties:
CheckedContainer
with the following properties:
TypeValuePolicy.ELEMENT_TYPE
.CheckedContainer
is to consider each ExtendedElementInformation
instance as the set of all possible values for the property. If the information had a contains(E)
method,
it would return true
if the given value is valid for that property.ExtendedElementInformation.getDomainValue()
may optionally be an instance of any of the following classes:
NumberRange
if the valid values are constrained to some specific range.type
- The metadata interface or implementation class.keyPolicy
- Determines the string representation of map keys.ClassCastException
- if the given type doesn't implement a metadata
interface of the expected package.DefaultExtendedElementInformation
public Map<String,Object> asValueMap(Object metadata, KeyNamePolicy keyPolicy, ValueExistencePolicy valuePolicy) throws ClassCastException
Map
.
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: metadata
determines the set of
keys, keyPolicy
determines their String
representations of those keys and
valuePolicy
determines whether entries having a null value or an empty collection
shall be included in the map.
put(…)
and remove(…)
operations if the underlying metadata object contains setter methods.
The remove(…)
method is implemented by a call to put(…, null)
.
Note that whether the entry appears as effectively removed from the map or just cleared
(i.e. associated to a null value) depends on the valuePolicy
argument.
put(…)
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.
put(…)
replace the previous value, with one noticeable exception: if the metadata
property associated to the given key is a Collection
but 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 intend 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.metadata
- The metadata object to view as a map.keyPolicy
- Determines the string representation of map keys.valuePolicy
- Whether the entries having null value or empty collection shall be
included in the map.ClassCastException
- if the metadata object doesn't implement a metadata
interface of the expected package.AbstractMetadata.asMap()
public TreeTable asTreeTable(Object metadata, ValueExistencePolicy valuePolicy) throws ClassCastException
The returned TreeTable
instance contains the following columns:
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 of DefaultCitation
,
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.
Otherwise null
. For example in a tree table view of DefaultCitation
, if the
"alternateTitle"
collection contains two elements, then there is a node with index 0
for the first element and an other node with index 1 for the second element.
(IDENTIFIER, INDEX)
pair 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.NAME
A human-readable name for the node, derived from the identifier and the index.
This is the column shown in the default toString()
implementation and
may be localizable.
TableColumn.TYPE
The base type of the value (usually an interface).
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.
VALUE
column may be writable, with one exception: newly created children need
to have their IDENTIFIER
set 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 to a null value) depends on the valuePolicy
argument.metadata
- The metadata object to view as a tree table.valuePolicy
- Whether the property having null value or empty collection shall be
included in the tree.ClassCastException
- if the metadata object doesn't implement a metadata
interface of the expected package.AbstractMetadata.asTreeTable()
public boolean equals(Object metadata1, Object metadata2, ComparisonMode mode) throws ClassCastException
MetadataStandard
, otherwise an exception will be thrown. However the two
arguments do not need to be the same implementation class.
properties.equals(…)
method without explicit recursive call
to this standard.equals(…)
method for children metadata. However the comparison will
do implicit recursive calls if the properties.equals(…)
implementations
delegate their work to this standard.equals(…)
method, as AbstractMetadata
does.
In the later case, the final result is a deep comparison.metadata1
- The first metadata object to compare.metadata2
- The second metadata object to compare.mode
- The strictness level of the comparison.true
if the given metadata objects are equals.ClassCastException
- if at least one metadata object don't
implements a metadata interface of the expected package.AbstractMetadata.equals(Object, ComparisonMode)
public int hashCode(Object metadata) throws ClassCastException
Set.hashCode()
(except for the interface)
and ensures that the hash code value is insensitive to the ordering of properties.metadata
- The metadata object to compute hash code.ClassCastException
- if the metadata object doesn't implement a metadata
interface of the expected package.AbstractMetadata.hashCode()
Copyright © 2010–2014 The Apache Software Foundation. All rights reserved.