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.parameter;
021:
022: // J2SE dependencies
023: import java.util.Map;
024:
025: // OpenGIS dependencies
026: import org.opengis.parameter.ParameterValue;
027: import org.opengis.parameter.GeneralParameterValue;
028: import org.opengis.parameter.GeneralParameterDescriptor;
029:
030: // Geotools dependencies
031: import org.geotools.referencing.AbstractIdentifiedObject;
032: import org.geotools.referencing.wkt.Formatter;
033: import org.geotools.resources.i18n.ErrorKeys;
034: import org.geotools.resources.i18n.Errors;
035:
036: /**
037: * Abstract definition of a parameter or group of parameters used by an operation method.
038: *
039: * @since 2.1
040: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/referencing/src/main/java/org/geotools/parameter/AbstractParameterDescriptor.java $
041: * @version $Id: AbstractParameterDescriptor.java 24607 2007-02-26 22:05:40Z desruisseaux $
042: * @author Martin Desruisseaux
043: *
044: * @see AbstractParameter
045: */
046: public abstract class AbstractParameterDescriptor extends
047: AbstractIdentifiedObject implements GeneralParameterDescriptor {
048: /**
049: * Serial number for interoperability with different versions.
050: */
051: private static final long serialVersionUID = -2630644278783845276L;
052:
053: /**
054: * The minimum number of times that values for this parameter group or
055: * parameter are required.
056: */
057: private final int minimumOccurs;
058:
059: /**
060: * Constructs a descriptor with the same values than the specified one. This copy constructor
061: * may be used in order to wraps an arbitrary implementation into a Geotools one.
062: *
063: * @since 2.2
064: */
065: protected AbstractParameterDescriptor(
066: final GeneralParameterDescriptor descriptor) {
067: super (descriptor);
068: minimumOccurs = descriptor.getMinimumOccurs();
069: }
070:
071: /**
072: * Constructs a parameter from a set of properties. The properties map is given unchanged to the
073: * {@linkplain AbstractIdentifiedObject#AbstractIdentifiedObject(Map) super-class constructor}.
074: *
075: * @param properties Set of properties. Should contains at least {@code "name"}.
076: * @param minimumOccurs The {@linkplain #getMinimumOccurs minimum number of times}
077: * that values for this parameter group or parameter are required.
078: * @param maximumOccurs The {@linkplain #getMaximumOccurs maximum number of times}
079: * that values for this parameter group or parameter are required. This value
080: * is used in order to check the range. For {@link ParameterValue}, it should
081: * always be 1.
082: */
083: protected AbstractParameterDescriptor(final Map properties,
084: final int minimumOccurs, final int maximumOccurs) {
085: super (properties);
086: this .minimumOccurs = minimumOccurs;
087: if (minimumOccurs < 0 || maximumOccurs < minimumOccurs) {
088: throw new IllegalArgumentException(Errors.format(
089: ErrorKeys.BAD_RANGE_$2, new Integer(minimumOccurs),
090: new Integer(maximumOccurs)));
091: }
092: }
093:
094: /**
095: * Creates a new instance of {@linkplain AbstractParameter parameter value or group} initialized
096: * with the {@linkplain DefaultParameterDescriptor#getDefaultValue default value(s)}.
097: * The {@linkplain AbstractParameter#getDescriptor parameter value descriptor} for the
098: * created parameter value(s) will be {@code this} object.
099: * <p>
100: * Example implementation:
101: * <pre>
102: * <b>return</b> new {@linkplain Parameter}(this);
103: * </pre>
104: */
105: public abstract GeneralParameterValue createValue();
106:
107: /**
108: * The minimum number of times that values for this parameter group or
109: * parameter are required. The default value is one. A value of 0 means
110: * an optional parameter.
111: *
112: * @see #getMaximumOccurs
113: */
114: public int getMinimumOccurs() {
115: return minimumOccurs;
116: }
117:
118: /**
119: * The maximum number of times that values for this parameter group or parameter
120: * can be included. For a {@linkplain DefaultParameterDescriptor single parameter},
121: * the value is always 1. For a {@linkplain DefaultParameterDescriptorGroup parameter group},
122: * it may vary.
123: *
124: * @see #getMinimumOccurs
125: */
126: public abstract int getMaximumOccurs();
127:
128: /**
129: * Compares the specified object with this parameter for equality.
130: *
131: * @param object The object to compare to {@code this}.
132: * @param compareMetadata {@code true} for performing a strict comparaison, or
133: * {@code false} for comparing only properties relevant to transformations.
134: * @return {@code true} if both objects are equal.
135: */
136: public boolean equals(final AbstractIdentifiedObject object,
137: final boolean compareMetadata) {
138: if (super .equals(object, compareMetadata)) {
139: final AbstractParameterDescriptor that = (AbstractParameterDescriptor) object;
140: return this .minimumOccurs == that.minimumOccurs;
141: }
142: return false;
143: }
144:
145: /**
146: * Returns a hash value for this parameter.
147: *
148: * @return The hash code value. This value doesn't need to be the same
149: * in past or future versions of this class.
150: */
151: public int hashCode() {
152: return (int) serialVersionUID ^ (int) minimumOccurs;
153: }
154:
155: /**
156: * Format the inner part of a
157: * <A HREF="http://geoapi.sourceforge.net/snapshot/javadoc/org/opengis/referencing/doc-files/WKT.html"><cite>Well
158: * Known Text</cite> (WKT)</A> element. Note that WKT is not yet defined for parameter descriptor.
159: * Current implementation print only the name.
160: *
161: * @param formatter The formatter to use.
162: * @return The WKT element name, which is "PARAMETER"
163: */
164: protected String formatWKT(final Formatter formatter) {
165: formatter.setInvalidWKT(GeneralParameterDescriptor.class);
166: return "PARAMETER";
167: }
168: }
|