001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2004-2006, GeoTools Project Managment Committee (PMC)
005: * (C) 2004, Institut de Recherche pour le Développement
006: *
007: * This library is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU Lesser General Public
009: * License as published by the Free Software Foundation;
010: * version 2.1 of the License.
011: *
012: * This library is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * This package contains documentation from OpenGIS specifications.
018: * OpenGIS consortium's work is fully acknowledged here.
019: */
020: package org.geotools.referencing;
021:
022: // J2SE dependencies
023: import java.util.HashMap;
024: import java.util.Map;
025:
026: // OpenGIS dependencies
027: import org.opengis.metadata.extent.Extent;
028: import org.opengis.util.InternationalString;
029: import org.opengis.referencing.ReferenceSystem;
030:
031: // Geotools dependencies
032: import org.geotools.resources.Utilities;
033:
034: /**
035: * Description of a spatial and temporal reference system used by a dataset.
036: * <p>
037: * This class is conceptually <cite>abstract</cite>, even if it is technically possible to
038: * instantiate it. Typical applications should create instances of the most specific subclass with
039: * {@code Default} prefix instead. An exception to this rule may occurs when it is not possible to
040: * identify the exact type.
041: *
042: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/referencing/src/main/java/org/geotools/referencing/AbstractReferenceSystem.java $
043: * @version $Id: AbstractReferenceSystem.java 28264 2007-12-05 21:53:08Z desruisseaux $
044: * @author Martin Desruisseaux
045: *
046: * @since 2.1
047: */
048: public class AbstractReferenceSystem extends AbstractIdentifiedObject
049: implements ReferenceSystem {
050: /**
051: * Serial number for interoperability with different versions.
052: */
053: private static final long serialVersionUID = 3337659819553899435L;
054:
055: /**
056: * List of localizable properties. To be given to {@link AbstractIdentifiedObject} constructor.
057: */
058: private static final String[] LOCALIZABLES = { SCOPE_KEY };
059:
060: /**
061: * Area for which the (coordinate) reference system is valid.
062: */
063: private final Extent domainOfValidity;
064:
065: /**
066: * Description of domain of usage, or limitations of usage, for which this
067: * (coordinate) reference system object is valid.
068: */
069: private final InternationalString scope;
070:
071: /**
072: * Constructs a new reference system with the same values than the specified one.
073: * This copy constructor provides a way to wrap an arbitrary implementation into a
074: * Geotools one or a user-defined one (as a subclass), usually in order to leverage
075: * some implementation-specific API. This constructor performs a shallow copy,
076: * i.e. the properties are not cloned.
077: *
078: * @since 2.2
079: */
080: public AbstractReferenceSystem(final ReferenceSystem object) {
081: super (object);
082: domainOfValidity = object.getDomainOfValidity();
083: scope = object.getScope();
084: }
085:
086: /**
087: * Constructs a reference system from a set of properties.
088: * The properties given in argument follow the same rules than for the
089: * {@linkplain AbstractIdentifiedObject#AbstractIdentifiedObject(Map) super-class constructor}.
090: * Additionally, the following properties are understood by this construtor:
091: * <p>
092: * <table border='1'>
093: * <tr bgcolor="#CCCCFF" class="TableHeadingColor">
094: * <th nowrap>Property name</th>
095: * <th nowrap>Value type</th>
096: * <th nowrap>Value given to</th>
097: * </tr>
098: * <tr>
099: * <td nowrap> {@link #DOMAIN_OF_VALIDITY_KEY "domainOfValidity"} </td>
100: * <td nowrap> {@link Extent} </td>
101: * <td nowrap> {@link #getDomainOfValidity}</td>
102: * </tr>
103: * <tr>
104: * <td nowrap> {@link #SCOPE_KEY "scope"} </td>
105: * <td nowrap> {@link String} or {@link InternationalString} </td>
106: * <td nowrap> {@link #getScope}</td>
107: * </tr>
108: * </table>
109: */
110: public AbstractReferenceSystem(final Map properties) {
111: this (properties, new HashMap());
112: }
113:
114: /**
115: * Work around for RFE #4093999 in Sun's bug database
116: * ("Relax constraint on placement of this()/super() call in constructors").
117: */
118: private AbstractReferenceSystem(final Map properties,
119: final Map subProperties) {
120: super (properties, subProperties, LOCALIZABLES);
121: domainOfValidity = (Extent) subProperties
122: .get(DOMAIN_OF_VALIDITY_KEY);
123: scope = (InternationalString) subProperties.get(SCOPE_KEY);
124: }
125:
126: /**
127: * Area or region or timeframe in which this (coordinate) reference system is valid.
128: * Returns {@code null} if not available.
129: *
130: * @since 2.4
131: */
132: public Extent getDomainOfValidity() {
133: return domainOfValidity;
134: }
135:
136: /**
137: * Area for which the (coordinate) reference system is valid.
138: * Returns {@code null} if not available.
139: *
140: * @deprecated Renamed {@link #getDomainOfValidity}.
141: */
142: public Extent getValidArea() {
143: return domainOfValidity;
144: }
145:
146: /**
147: * Description of domain of usage, or limitations of usage, for which this
148: * (coordinate) reference system object is valid.
149: * Returns {@code null} if not available.
150: */
151: public InternationalString getScope() {
152: return scope;
153: }
154:
155: /**
156: * Compare this reference system with the specified object for equality.
157: * If {@code compareMetadata} is {@code true}, then all available properties are
158: * compared including {@linkplain #getValidArea valid area} and {@linkplain #getScope scope}.
159: *
160: * @param object The object to compare to {@code this}.
161: * @param compareMetadata {@code true} for performing a strict comparaison, or
162: * {@code false} for comparing only properties relevant to transformations.
163: * @return {@code true} if both objects are equal.
164: */
165: public boolean equals(final AbstractIdentifiedObject object,
166: final boolean compareMetadata) {
167: if (super .equals(object, compareMetadata)) {
168: if (!compareMetadata) {
169: return true;
170: }
171: final AbstractReferenceSystem that = (AbstractReferenceSystem) object;
172: return Utilities.equals(domainOfValidity,
173: that.domainOfValidity)
174: && Utilities.equals(scope, that.scope);
175: }
176: return false;
177: }
178: }
|