Class MetadataStandard


  • public final class MetadataStandard
    extends Object
    Enumeration of some metadata standards. A standard is defined by a set of Java interfaces in a specific package or subpackages. For example the ISO 19115 standard is defined by GeoAPI interfaces in the org.geotools.api.metadata package and subpackages.

    This class provides some methods operating on metadata instances through Java reflection. The following rules are assumed:

    • Properties (or metadata attributes) are defined by the set of get*() (arbitrary return type) or is*() (boolean return type) methods found in the interface. Getters declared in the implementation only are ignored.
    • A property is writable if a set*(...) method is defined in the implementation class for the corresponding get*() method. The setter don't need to be defined in the interface.
    Since:
    2.4
    Author:
    Martin Desruisseaux (Geomatys)
    • Constructor Detail

      • MetadataStandard

        public MetadataStandard​(String interfacePackage)
        Creates a new instance working on implementation of interfaces defined in the specified package. For the ISO 19115 standard reflected by GeoAPI interfaces, it should be the org.geotools.api.metadata package.
        Parameters:
        interfacePackage - The root package for metadata interfaces.
    • Method Detail

      • getInterface

        public Class<?> getInterface​(Class<?> implementation)
                              throws ClassCastException
        Returns the metadata interface implemented by the specified implementation class.
        Parameters:
        implementation - The implementation class.
        Returns:
        The interface implemented by the given implementation class.
        Throws:
        ClassCastException - if the specified implementation class do not implements a metadata interface of the expected package.
        See Also:
        AbstractMap#getInterface
      • asMap

        public Map<String,​Object> asMap​(Object metadata)
                                       throws ClassCastException
        Returns a view of the specified metadata object as a 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. The keys are the property names as determined by the list of get*() methods declared in the metadata interface.

        The map supports the put operations if the underlying metadata object contains {@link #set*(...)} methods.

        Parameters:
        metadata - The metadata object to view as a map.
        Returns:
        A map view over the metadata object.
        Throws:
        ClassCastException - if at the metadata object don't implements a metadata interface of the expected package.
        See Also:
        AbstractMap#asMap
      • asTree

        public TreeModel asTree​(Object metadata)
                         throws ClassCastException
        Returns a view of the specified metadata as a tree. Note that while TreeModel is defined in the javax.swing.tree package, it can be seen as a data structure independent of Swing. It will not force class loading of Swing framework.

        In current implementation, the tree is not live (i.e. changes in metadata are not reflected in the tree). However it may be improved in a future Geotools implementation.

        Parameters:
        metadata - The metadata object to formats as a string.
        Returns:
        A tree representation of the specified metadata.
        Throws:
        ClassCastException - if at the metadata object don't implements a metadata interface of the expected package.
        See Also:
        AbstractMap#asTree
      • shallowCopy

        public void shallowCopy​(Object source,
                                Object target,
                                boolean skipNulls)
                         throws ClassCastException,
                                UnmodifiableMetadataException
        Copies all metadata from source to target. The source must implements the same metadata interface than the target.
        Parameters:
        source - The metadata to copy.
        target - The target metadata.
        skipNulls - If true, only non-null values will be copied.
        Throws:
        ClassCastException - if the source or target object don't implements a metadata interface of the expected package.
        UnmodifiableMetadataException - if the target metadata is unmodifiable, or if at least one setter method was required but not found.
        See Also:
        AbstractMap#AbstractMap(Object)
      • shallowEquals

        public boolean shallowEquals​(Object metadata1,
                                     Object metadata2,
                                     boolean skipNulls)
                              throws ClassCastException
        Compares the two specified metadata objects. The comparaison is shallow, i.e. all metadata attributes are compared using the Object.equals(java.lang.Object) method without recursive call to this shallowEquals(...) method for child metadata.

        This method can optionaly excludes null values from the comparaison. In metadata, null value often means "don't know", so in some occasion we want to consider two metadata as different only if an attribute value is know for sure to be different.

        The first arguments must be an implementation of a metadata interface, otherwise an exception will be thrown. The two argument do not need to be the same implementation however.

        Parameters:
        metadata1 - The first metadata object to compare.
        metadata2 - The second metadata object to compare.
        skipNulls - If true, only non-null values will be compared.
        Returns:
        true if the given metadata objects are equals.
        Throws:
        ClassCastException - if at least one metadata object don't implements a metadata interface of the expected package.
        See Also:
        AbstractMetadata.equals(java.lang.Object)
      • hashCode

        public int hashCode​(Object metadata)
                     throws ClassCastException
        Computes a hash code for the specified metadata. The hash code is defined as the sum of hash code values of all non-null properties. This is the same contract than Set.hashCode() and ensure 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.
        Throws:
        ClassCastException - if at the metadata object don't implements a metadata interface of the expected package.
        See Also:
        AbstractMap#hashCode
      • toString

        public String toString​(Object metadata)
                        throws ClassCastException
        Returns a string representation of the specified metadata.
        Parameters:
        metadata - The metadata object to formats as a string.
        Returns:
        A string representation of the specified metadata.
        Throws:
        ClassCastException - if at the metadata object don't implements a metadata interface of the expected package.
        See Also:
        AbstractMap#toString