org.geotoolkit.metadata
Class AbstractMetadata

Object
  extended by AbstractMetadata
All Implemented Interfaces:
LenientComparable
Direct Known Subclasses:
ModifiableMetadata

@ThreadSafe
public abstract class AbstractMetadata
extends Object
implements LenientComparable

Base class for metadata implementations. Subclasses must implement the interfaces of some metadata standard. This class uses Java reflection in order to provide default implementation of copy constructor, equals(Object) and hashCode() methods.

Since:
2.4
Version:
3.20
Author:
Martin Desruisseaux (Geomatys)
Module:
metadata/geotk-metadata (download)    View source code for this class

Field Summary
protected static Logger LOGGER
          The logger for metadata implementation.
 
Constructor Summary
protected AbstractMetadata()
          Creates an initially empty metadata.
protected AbstractMetadata(Object source)
          Constructs a metadata entity initialized with the values from the specified metadata.
 
Method Summary
 Map<String,Object> asMap()
          Returns a view of this metadata object as a map.
 TreeModel asTree()
          Returns a view of this metadata as a tree.
 TreeTableNode asTreeTable()
          Returns a view of this metadata as a tree table.
 boolean equals(Object object)
          Performs a strict comparison of this metadata with the given object.
 boolean equals(Object object, ComparisonMode mode)
          Compares this metadata with the specified object for equality.
 Class<?> getInterface()
          Returns the metadata interface implemented by this class.
abstract  MetadataStandard getStandard()
          Returns the metadata standard implemented by subclasses.
 int hashCode()
          Computes a hash code value for this metadata using Java reflection.
 boolean isEmpty()
          Returns true if this metadata contains only null or empty properties.
 void parse(TreeModel tree)
          Fetches values from every nodes of the given tree except the root, and puts them in this metadata object.
 String toString()
          Returns a string representation of this metadata.
 
Methods inherited from class Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

LOGGER

protected static final Logger LOGGER
The logger for metadata implementation.

Constructor Detail

AbstractMetadata

protected AbstractMetadata()
Creates an initially empty metadata.


AbstractMetadata

protected AbstractMetadata(Object source)
                    throws ClassCastException,
                           UnmodifiableMetadataException
Constructs a metadata entity initialized with the values from the specified metadata. The source metadata must implements the same metadata interface (defined by the standard) than this class, but don't need to be the same implementation class. The copy is performed using Java reflections.

Parameters:
source - The metadata to copy values from, or null if none.
Throws:
ClassCastException - if the specified metadata don't implements the expected metadata interface.
UnmodifiableMetadataException - if this class don't define set methods corresponding to the get methods found in the implemented interface, or if this instance is not modifiable for some other reason.
Method Detail

getStandard

public abstract MetadataStandard getStandard()
Returns the metadata standard implemented by subclasses.

Returns:
The metadata standard implemented.

getInterface

public Class<?> getInterface()
Returns the metadata interface implemented by this class. It should be one of the interfaces defined in the metadata standard implemented by this class.

Returns:
The standard interface implemented by this implementation class.

isEmpty

public boolean isEmpty()
Returns true if this metadata contains only null or empty properties. A property is considered empty in any of the following cases:

Note that empty properties can be removed by calling the ModifiableMetadata.prune() method.

Note for implementors
The default implementation uses Java reflection indirectly, by iterating over all entries returned by asMap(). Subclasses that override this method should usually not invoke super.isEmpty(), because the Java reflection will discover and process the properties defined in the sub-classes - which is usually not the intend when overriding a method.

Returns:
true if this metadata is empty.
Since:
3.20
See Also:
DefaultGeographicBoundingBox.isEmpty()

asMap

public Map<String,Object> asMap()
Returns a view of this metadata object as a map. The map is backed by this 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 getFoo() methods declared in the metadata interface.

The map supports the put and remove operations if the underlying metadata object contains setFoo(...) methods.

Returns:
A view of this metadata object as a map.
See Also:
MetadataStandard.asMap(Object), MetadataStandard#asMap(Object, NullValuePolicy, KeyNamePolicy), MetadataStandard.asNameMap(Class, KeyNamePolicy, KeyNamePolicy), MetadataStandard.asTypeMap(Class, TypeValuePolicy, KeyNamePolicy), MetadataStandard#asRestrictionMap(Object, NullValuePolicy, KeyNamePolicy), MetadataStandard.asDescriptionMap(Class, Locale, KeyNamePolicy)

asTreeTable

public TreeTableNode asTreeTable()
Returns a view of this metadata as a tree table. Note that while TreeTableNode is defined in a org.geotoolkit.gui.swing sub-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 Geotk implementation.

Returns:
A view of this metadata object as a tree table.
Since:
3.19
See Also:
MetadataStandard.asTreeTable(Object)

asTree

public TreeModel asTree()
Returns a view of this 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 Geotk implementation.

Returns:
A view of this metadata object as a tree.
See Also:
MetadataStandard.asTree(Object)

parse

public void parse(TreeModel tree)
           throws ParseException
Fetches values from every nodes of the given tree except the root, and puts them in this metadata object. The value of the root node is ignored (it is typically just the name of this metadata class).

If the given metadata object already contains property values, then the parsing will be merged with the existing values: attributes not defined in the tree will be left unchanged, and collections will be augmented with new entries without change in the previously existing entries.

This method can parse the tree created by asTree().

Note: The current implementation expects the tree root to be an instance of javax.swing.tree.TreeNode.

Parameters:
tree - The tree from which to fetch the values.
Throws:
ParseException - If a value can not be stored in this metadata object.
Since:
3.00

equals

public boolean equals(Object object,
                      ComparisonMode mode)
Compares this metadata with the specified object for equality. The default implementation uses Java reflection. Subclasses may override this method for better performances, or for comparing "hidden" attributes not specified by the GeoAPI (or other standard) interface.

This method performs a deep comparison (i.e. if this metadata contains other metadata, the comparison will walk through the other metadata content as well) providing that every children implement the Object.equals(Object) method as well. This is the case by default if every children are subclasses of AbstractMetadata.

Specified by:
equals in interface LenientComparable
Parameters:
object - The object to compare with this metadata.
mode - The strictness level of the comparison.
Returns:
true if the given object is equal to this metadata.
Since:
3.18
See Also:
Utilities.deepEquals(Object, Object, ComparisonMode)

equals

public final boolean equals(Object object)
Performs a strict comparison of this metadata with the given object.

Specified by:
equals in interface LenientComparable
Overrides:
equals in class Object
Parameters:
object - The object to compare with this metadata for equality.
Returns:
true if both objects are strictly equal.
See Also:
ComparisonMode.STRICT

hashCode

public int hashCode()
Computes a hash code value for this metadata using Java reflection. 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.

Overrides:
hashCode in class Object

toString

public String toString()
Returns a string representation of this metadata.

Overrides:
toString in class Object


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