001    /*
002     *    GeoAPI - Java interfaces for OGC/ISO standards
003     *    http://www.geoapi.org
004     *
005     *    Copyright (C) 2007-2012 Open Geospatial Consortium, Inc.
006     *    All Rights Reserved. http://www.opengeospatial.org/ogc/legal
007     *
008     *    Permission to use, copy, and modify this software and its documentation, with
009     *    or without modification, for any purpose and without fee or royalty is hereby
010     *    granted, provided that you include the following on ALL copies of the software
011     *    and documentation or portions thereof, including modifications, that you make:
012     *
013     *    1. The full text of this NOTICE in a location viewable to users of the
014     *       redistributed or derivative work.
015     *    2. Notice of any changes or modifications to the OGC files, including the
016     *       date changes were made.
017     *
018     *    THIS SOFTWARE AND DOCUMENTATION IS PROVIDED "AS IS," AND COPYRIGHT HOLDERS MAKE
019     *    NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
020     *    TO, WARRANTIES OF MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE OR THAT
021     *    THE USE OF THE SOFTWARE OR DOCUMENTATION WILL NOT INFRINGE ANY THIRD PARTY
022     *    PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS.
023     *
024     *    COPYRIGHT HOLDERS WILL NOT BE LIABLE FOR ANY DIRECT, INDIRECT, SPECIAL OR
025     *    CONSEQUENTIAL DAMAGES ARISING OUT OF ANY USE OF THE SOFTWARE OR DOCUMENTATION.
026     *
027     *    The name and trademarks of copyright holders may NOT be used in advertising or
028     *    publicity pertaining to the software without specific, written prior permission.
029     *    Title to copyright in this software and any associated documentation will at all
030     *    times remain with copyright holders.
031     */
032    package org.opengis.filter.capability;
033    
034    import java.io.ObjectStreamException;
035    import java.io.Serializable;
036    import java.util.HashMap;
037    import java.util.Map;
038    import org.opengis.feature.type.Name;
039    
040    
041    /**
042     * Enumeration of the different {@code GeometryOperand} types.
043     * <p>
044     * <pre>
045     *  &lt;xsd:simpleType name="GeometryOperandType">
046     *    &lt;xsd:restriction base="xsd:QName">
047     *        &lt;xsd:enumeration value="gml:Envelope"/>
048     *        &lt;xsd:enumeration value="gml:Point"/>
049     *        &lt;xsd:enumeration value="gml:LineString"/>
050     *        &lt;xsd:enumeration value="gml:Polygon"/>
051     *        &lt;xsd:enumeration value="gml:ArcByCenterPoint"/>
052     *        &lt;xsd:enumeration value="gml:CircleByCenterPoint"/>
053     *        &lt;xsd:enumeration value="gml:Arc"/>
054     *        &lt;xsd:enumeration value="gml:Circle"/>
055     *        &lt;xsd:enumeration value="gml:ArcByBulge"/>
056     *        &lt;xsd:enumeration value="gml:Bezier"/>
057     *        &lt;xsd:enumeration value="gml:Clothoid"/>
058     *        &lt;xsd:enumeration value="gml:CubicSpline"/>
059     *        &lt;xsd:enumeration value="gml:Geodesic"/>
060     *        &lt;xsd:enumeration value="gml:OffsetCurve"/>
061     *        &lt;xsd:enumeration value="gml:Triangle"/>
062     *        &lt;xsd:enumeration value="gml:PolyhedralSurface"/>
063     *        &lt;xsd:enumeration value="gml:TriangulatedSurface"/>
064     *        &lt;xsd:enumeration value="gml:Tin"/>
065     *        &lt;xsd:enumeration value="gml:Solid"/>
066     *     &lt;/xsd:restriction>
067     *  &lt;/xsd:simpleType>
068     *  </pre>
069     * </p>
070     *
071     * @author Justin Deoliveira (The Open Planning Project)
072     * @author Martin Desruisseaux (Geomatys)
073     */
074    public final class GeometryOperand implements Name, Serializable {
075        /**
076         * For cross-version compatibility.
077         */
078        private static final long serialVersionUID = -9006169053542932716L;
079    
080        /**
081         * The pool of operands created up to date.
082         */
083        private static final Map<GeometryOperand, GeometryOperand> POOL =
084                new HashMap<GeometryOperand, GeometryOperand>();
085    
086        /** {@code "http://www.opengis.net/gml/Envelope"} */
087        public static final GeometryOperand Envelope = new GeometryOperand("Envelope");
088    
089        /** {@code "http://www.opengis.net/gml/Point"} */
090        public static final GeometryOperand Point = new GeometryOperand("Point");
091    
092        /** {@code "http://www.opengis.net/gml/LineString"} */
093        public static final GeometryOperand LineString = new GeometryOperand("LineString");
094    
095        /** {@code "http://www.opengis.net/gml/Polygon"} */
096        public static final GeometryOperand Polygon = new GeometryOperand("Polygon");
097    
098        /** {@code "http://www.opengis.net/gml/ArcByCenterPoint"} */
099        public static final GeometryOperand ArcByCenterPoint = new GeometryOperand("ArcByCenterPoint");
100    
101        /** {@code "http://www.opengis.net/gml/CircleByCenterPoint"} */
102        public static final GeometryOperand CircleByCenterPoint = new GeometryOperand("CircleByCenterPoint");
103    
104        /** {@code "http://www.opengis.net/gml/Arc"} */
105        public static final GeometryOperand Arc = new GeometryOperand("Arc");
106    
107        /** {@code "http://www.opengis.net/gml/Circle"} */
108        public static final GeometryOperand Circle = new GeometryOperand("Circle");
109    
110        /** {@code "http://www.opengis.net/gml/ArcByBulge"} */
111        public static final GeometryOperand ArcByBulge = new GeometryOperand("ArcByBulge");
112    
113        /** {@code "http://www.opengis.net/gml/Bezier"} */
114        public static final GeometryOperand Bezier = new GeometryOperand("Bezier");
115    
116        /** {@code "http://www.opengis.net/gml/Clothoid"} */
117        public static final GeometryOperand Clothoid = new GeometryOperand("Clothoid");
118    
119        /** {@code "http://www.opengis.net/gml/CubicSpline"} */
120        public static final GeometryOperand CubicSpline = new GeometryOperand("CubicSpline");
121    
122        /** {@code "http://www.opengis.net/gml/Geodesic"} */
123        public static final GeometryOperand Geodesic = new GeometryOperand("Geodesic");
124    
125        /** {@code "http://www.opengis.net/gml/OffsetCurve"} */
126        public static final GeometryOperand OffsetCurve = new GeometryOperand("OffsetCurve");
127    
128        /** {@code "http://www.opengis.net/gml/Triangle"} */
129        public static final GeometryOperand Triangle = new GeometryOperand("Triangle");
130    
131        /** {@code "http://www.opengis.net/gml/PolyhedralSurface"} */
132        public static final GeometryOperand PolyhedralSurface = new GeometryOperand("PolyhedralSurface");
133    
134        /** {@code "http://www.opengis.net/gml/TriangulatedSurface"} */
135        public static final GeometryOperand TriangulatedSurface = new GeometryOperand("TriangulatedSurface");
136    
137        /** {@code "http://www.opengis.net/gml/Tin"} */
138        public static final GeometryOperand Tin = new GeometryOperand("Tin");
139    
140        /** {@code "http://www.opengis.net/gml/Solid"} */
141        public static final GeometryOperand Solid = new GeometryOperand("Solid");
142    
143        /**
144         * The namespace URI.
145         */
146        private final String namespaceURI;
147    
148        /**
149         * The name.
150         */
151        private final String name;
152    
153        /**
154         * Creates an operand in the {@code "http://www.opengis.net/gml"} namespace.
155         */
156        private GeometryOperand(final String name) {
157            this("http://www.opengis.net/gml", name);
158        }
159    
160        /**
161         * Creates an operand in the given namespace.
162         */
163        private GeometryOperand(final String namespaceURI, final String name) {
164            this.namespaceURI = namespaceURI;
165            this.name = name;
166            POOL.put(this, this);
167        }
168    
169        /**
170         * Returns the geometry operand for the given name.
171         *
172         * @param  namespaceURI The namespace URI, or {@code null} for the default one.
173         * @param  name The operand name.
174         * @return The geometry operand, or {@code null} if none was found.
175         */
176        public static GeometryOperand get(String namespaceURI, String name) {
177            if (namespaceURI == null || namespaceURI.trim().length() == 0) {
178                namespaceURI = "http://www.opengis.net/gml";
179            }
180            name = name.trim();
181            return POOL.get(new GeometryOperand(namespaceURI, name));
182        }
183    
184        /**
185         * Retrieve the Local name.
186         */
187        public String getLocalPart() {
188            return name;
189        }
190    
191        /**
192         * Returns the name space, which is usually {@code "http://www.opengis.net/gml"}.
193         */
194        public String getNamespaceURI() {
195            return namespaceURI;
196        }
197    
198        /**
199         * Convert this name to a complete URI.
200         */
201        public String getURI() {
202            return namespaceURI + '/' + name;
203        }
204    
205        /**
206         * Returns {@code false} since this name has a {@linkplain #getNamespaceURI namespace}.
207         */
208        public boolean isGlobal() {
209            return false;
210        }
211    
212        public String getSeparator() {
213            return "#";
214        }
215        
216        /**
217         * Returns a hash code value for this operand.
218         */
219        @Override
220        public int hashCode() {
221            return namespaceURI.hashCode() + 37*name.hashCode();
222        }
223    
224        /**
225         * Compares this operand with the specified value for equality.
226         */
227        @Override
228        public boolean equals(final Object other) {
229            if (other != null && other instanceof Name) {
230                final Name that = (Name) other;
231                return namespaceURI.equals(that.getNamespaceURI()) && name.equals(that.getLocalPart());
232            }
233            return false;
234        }
235    
236        /**
237         * Returns a string representation of this operand.
238         */
239        @Override
240        public String toString() {
241            return getURI();
242        }
243    
244        /**
245         * Returns the canonical instance on deserialization.
246         */
247        private Object readResolve() throws ObjectStreamException {
248            final GeometryOperand unique = POOL.get(this);
249            return (unique != null) ? unique : this;
250        }
251    }