001    //$HeadURL: https://svn.wald.intevation.org/svn/deegree/base/branches/2.3_testing/src/org/deegree/owscommon/com110/OWSDomainType110.java $
002    /*----------------------------------------------------------------------------
003     This file is part of deegree, http://deegree.org/
004     Copyright (C) 2001-2009 by:
005       Department of Geography, University of Bonn
006     and
007       lat/lon GmbH
008    
009     This library is free software; you can redistribute it and/or modify it under
010     the terms of the GNU Lesser General Public License as published by the Free
011     Software Foundation; either version 2.1 of the License, or (at your option)
012     any later version.
013     This library is distributed in the hope that it will be useful, but WITHOUT
014     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
015     FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
016     details.
017     You should have received a copy of the GNU Lesser General Public License
018     along with this library; if not, write to the Free Software Foundation, Inc.,
019     59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020    
021     Contact information:
022    
023     lat/lon GmbH
024     Aennchenstr. 19, 53177 Bonn
025     Germany
026     http://lat-lon.de/
027    
028     Department of Geography, University of Bonn
029     Prof. Dr. Klaus Greve
030     Postfach 1147, 53001 Bonn
031     Germany
032     http://www.geographie.uni-bonn.de/deegree/
033    
034     e-mail: info@deegree.org
035    ----------------------------------------------------------------------------*/
036    
037    package org.deegree.owscommon.com110;
038    
039    import org.deegree.datatypes.values.TypedLiteral;
040    import org.deegree.owscommon.OWSMetadata;
041    
042    /**
043     * FIXME should be renamed.
044     *
045     * @author <a href="mailto:mays@lat-lon.de">Judit Mays</a>
046     * @author last edited by: $Author: mschneider $
047     *
048     * @version 2.0, $Revision: 18195 $, $Date: 2009-06-18 17:55:39 +0200 (Do, 18. Jun 2009) $
049     *
050     * @since 2.0
051     */
052    public class OWSDomainType110 {
053    
054        /*
055         * FIXME When this class OWSDomainType110 gets integrated properly, the class OWSMetadata should
056         * be provided with an identifier (private String name), to enable identification of the kind of
057         * OWSMetadata. With this handle, the implemented String 'measurementType' becomes obsolete,
058         * because its content could be moved into the String 'name' within the OWSMetadata object.
059         */
060    
061        public static final String REFERENCE_SYSTEM = "REFERENCE_SYSTEM";
062    
063        public static final String UOM = "UOM";
064    
065        // the choice of one of these four elements is mandatory:
066        private OWSAllowedValues allowedValues;
067    
068        private boolean anyValue;
069    
070        private boolean noValues;
071    
072        private OWSMetadata valuesListReference;
073    
074        // these elements are optional:
075        private TypedLiteral defaultValue;
076    
077        private OWSMetadata meaning;
078    
079        private OWSMetadata owsDataType;
080    
081        private String measurementType; // choice between REFERENCE_SYSTEM and UOM
082    
083        private OWSMetadata measurement;
084    
085        private OWSMetadata[] metadata;
086    
087        // mandatory attribute:
088        public String name;
089    
090        /**
091         * Creates a new <code>DomainType110</code> object. This is the basic constructor, which is
092         * called from any other public constructor.
093         *
094         * @param allowedValues
095         * @param anyValue
096         * @param noValues
097         * @param valuesListReference
098         * @param defaultValue
099         * @param meaning
100         * @param dataType
101         * @param measurementType
102         * @param measurement
103         * @param metadata
104         * @param name
105         */
106        private OWSDomainType110( OWSAllowedValues allowedValues, boolean anyValue, boolean noValues,
107                                  OWSMetadata valuesListReference, String defaultValue, OWSMetadata meaning,
108                                  OWSMetadata dataType, String measurementType, OWSMetadata measurement,
109                                  OWSMetadata[] metadata, String name ) {
110    
111            if ( anyValue == true && noValues == true ) {
112                throw new IllegalArgumentException( "anyValue and noValues cannot both be true." );
113            }
114    
115            if ( measurement != null ) {
116    
117                if ( measurementType == null ) {
118                    throw new NullPointerException( "measurementType cannot be null." );
119                }
120                if ( REFERENCE_SYSTEM.equals( measurementType ) || UOM.equals( measurementType ) ) {
121                    this.measurementType = measurementType;
122                } else {
123                    throw new IllegalArgumentException( "measurementType must be either " + getClass().getName()
124                                                        + ".REFERENCE_SYSTEM or " + getClass().getName() + ".UOM" );
125                }
126                this.measurement = measurement;
127            }
128    
129            this.allowedValues = allowedValues;
130            this.anyValue = anyValue;
131            this.noValues = noValues;
132            this.valuesListReference = valuesListReference;
133            setDefaultValue( defaultValue );
134            this.meaning = meaning;
135            this.owsDataType = dataType;
136            if ( metadata == null ) {
137                this.metadata = new OWSMetadata[0];
138            } else {
139                this.metadata = metadata;
140            }
141            this.name = name;
142    
143        }
144    
145        /**
146         * Creates a new <code>DomainType110</code> object.
147         *
148         * Use this constructor to create the <code>DomainType110</code> object with an
149         * <code>OWSAllowedValues</code> object.
150         *
151         * @param allowedValues
152         * @param defaultValue
153         * @param meaning
154         * @param dataType
155         * @param measurementType
156         *            Must be either "REFERENCE_SYSTEM" or "UOM".
157         * @param measurement
158         * @param metadata
159         * @param name
160         *            mandatory attribute
161         */
162        public OWSDomainType110( OWSAllowedValues allowedValues, String defaultValue, OWSMetadata meaning,
163                                 OWSMetadata dataType, String measurementType, OWSMetadata measurement,
164                                 OWSMetadata[] metadata, String name ) {
165    
166            this( allowedValues, false, false, null, defaultValue, meaning, dataType, measurementType, measurement,
167                  metadata, name );
168        }
169    
170        /**
171         * Creates a new <code>DomainType110</code> object.
172         *
173         * Use this constructor to create the <code>DomainType110</code> object when
174         * <code>anyValue</code> OR <code>noValues</code> is true.
175         *
176         * @param anyValue
177         *            Cannot be true if noValues is true.
178         * @param noValues
179         *            Cannot be true if anyValue is true.
180         * @param defaultValue
181         * @param meaning
182         * @param dataType
183         * @param measurementType
184         *            Must be either "REFERENCE_SYSTEM" or "UOM".
185         * @param measurement
186         * @param metadata
187         * @param name
188         *            mandatory attribute
189         */
190        public OWSDomainType110( boolean anyValue, boolean noValues, String defaultValue, OWSMetadata meaning,
191                                 OWSMetadata dataType, String measurementType, OWSMetadata measurement,
192                                 OWSMetadata[] metadata, String name ) {
193    
194            this( null, anyValue, noValues, null, defaultValue, meaning, dataType, measurementType, measurement, metadata,
195                  name );
196        }
197    
198        /**
199         * Creates a new <code>DomainType110</code> object.
200         *
201         * Use this constructor to create the <code>DomainType110</code> object with an
202         * <code>OWSMetadata</code> object of valuesListReference.
203         *
204         * @param valuesListReference
205         * @param defaultValue
206         * @param meaning
207         * @param dataType
208         * @param measurementType
209         *            Must be either "REFERENCE_SYSTEM" or "UOM".
210         * @param measurement
211         * @param metadata
212         * @param name
213         *            mandatory attribute
214         */
215        public OWSDomainType110( OWSMetadata valuesListReference, String defaultValue, OWSMetadata meaning,
216                                 OWSMetadata dataType, String measurementType, OWSMetadata measurement,
217                                 OWSMetadata[] metadata, String name ) {
218    
219            this( null, false, false, valuesListReference, defaultValue, meaning, dataType, measurementType, measurement,
220                  metadata, name );
221        }
222    
223        /**
224         * @return Returns the allowedValues.
225         */
226        public OWSAllowedValues getAllowedValues() {
227            return allowedValues;
228        }
229    
230        /**
231         * @return Returns the anyValue.
232         */
233        public boolean isAnyValue() {
234            return anyValue;
235        }
236    
237        /**
238         * @return Returns the noValues.
239         */
240        public boolean hasNoValues() {
241            return noValues;
242        }
243    
244        /**
245         * @return Returns the valuesListReference.
246         */
247        public OWSMetadata getValuesListReference() {
248            return valuesListReference;
249        }
250    
251        /**
252         * @return Returns the defaultValue.
253         */
254        public TypedLiteral getDefaultValue() {
255            return defaultValue;
256        }
257    
258        /**
259         * @return Returns the meaning.
260         */
261        public OWSMetadata getMeaning() {
262            return meaning;
263        }
264    
265        /**
266         * @return Returns the owsDataType.
267         */
268        public OWSMetadata getOwsDataType() {
269            return owsDataType;
270        }
271    
272        /**
273         * Returns the measurementType, or null if the measurement object is null.
274         *
275         * @return Returns the measurementType.
276         */
277        public String getMeasurementType() {
278            return measurementType;
279        }
280    
281        /**
282         * @return Returns the measurement.
283         */
284        public OWSMetadata getMeasurement() {
285            return measurement;
286        }
287    
288        /**
289         * Returns an array of OWSMetadata objects. If metadata is null, an array of size 0 is returned.
290         *
291         * @return Returns the metadata.
292         */
293        public OWSMetadata[] getMetadata() {
294            return metadata;
295        }
296    
297        /**
298         * @return Returns the name.
299         */
300        public String getName() {
301            return name;
302        }
303    
304        /**
305         * @param defaultValue
306         *            The defaultValue to set.
307         */
308        public void setDefaultValue( TypedLiteral defaultValue ) {
309            this.defaultValue = defaultValue;
310        }
311    
312        /**
313         * Sets the defaultValue to a new TypedLiteral with the given value.
314         *
315         * @param defaultURI
316         */
317        private void setDefaultValue( String value ) {
318            this.defaultValue = new TypedLiteral( value, null );
319        }
320    
321    }