001: //$HeadURL: https://svn.wald.intevation.org/svn/deegree/base/trunk/src/org/deegree/model/filterencoding/OperationDefines.java $
002: /*---------------- FILE HEADER ------------------------------------------
003:
004: This file is part of deegree.
005: Copyright (C) 2001-2008 by:
006: EXSE, Department of Geography, University of Bonn
007: http://www.giub.uni-bonn.de/deegree/
008: lat/lon GmbH
009: http://www.lat-lon.de
010:
011: This library is free software; you can redistribute it and/or
012: modify it under the terms of the GNU Lesser General Public
013: License as published by the Free Software Foundation; either
014: version 2.1 of the License, or (at your option) any later version.
015:
016: This library is distributed in the hope that it will be useful,
017: but WITHOUT ANY WARRANTY; without even the implied warranty of
018: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
019: Lesser General Public License for more details.
020:
021: You should have received a copy of the GNU Lesser General Public
022: License along with this library; if not, write to the Free Software
023: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
024:
025: Contact:
026:
027: Andreas Poth
028: lat/lon GmbH
029: Aennchenstr. 19
030: 53115 Bonn
031: Germany
032: E-Mail: poth@lat-lon.de
033:
034: Prof. Dr. Klaus Greve
035: Department of Geography
036: University of Bonn
037: Meckenheimer Allee 166
038: 53115 Bonn
039: Germany
040: E-Mail: greve@giub.uni-bonn.de
041:
042:
043: ---------------------------------------------------------------------------*/
044: package org.deegree.model.filterencoding;
045:
046: import java.util.HashMap;
047: import java.util.Map;
048:
049: /**
050: * Defines codes and constants for easy coping with the different kinds of OperationsMetadata (both
051: * XML-Entities & JavaObjects).
052: *
053: * @author Markus Schneider
054: * @version 06.08.2002
055: */
056: public class OperationDefines {
057:
058: // used to associate names with the OperationInfos
059: private static Map<String, OperationInfo> names = null;
060:
061: // used to associate ids (Integers) with the OperationInfos
062: private static Map<Integer, OperationInfo> ids = null;
063:
064: // different types of operations
065: public static final int TYPE_SPATIAL = 0;
066:
067: public static final int TYPE_COMPARISON = 1;
068:
069: public static final int TYPE_LOGICAL = 2;
070:
071: public static final int TYPE_UNKNOWN = -1;
072:
073: // spatial operations
074: public static final int EQUALS = 0;
075:
076: public static final int DISJOINT = 1;
077:
078: public static final int INTERSECTS = 2;
079:
080: public static final int TOUCHES = 3;
081:
082: public static final int CROSSES = 4;
083:
084: public static final int WITHIN = 5;
085:
086: public static final int CONTAINS = 6;
087:
088: public static final int OVERLAPS = 7;
089:
090: public static final int BEYOND = 8;
091:
092: public static final int BBOX = 9;
093:
094: // calvin added on 10/21/2003
095: public static final int DWITHIN = 10;
096:
097: // comparison operations
098: public static final int PROPERTYISEQUALTO = 100;
099:
100: public static final int PROPERTYISLESSTHAN = 101;
101:
102: public static final int PROPERTYISGREATERTHAN = 102;
103:
104: public static final int PROPERTYISLESSTHANOREQUALTO = 103;
105:
106: public static final int PROPERTYISGREATERTHANOREQUALTO = 104;
107:
108: public static final int PROPERTYISLIKE = 105;
109:
110: public static final int PROPERTYISNULL = 106;
111:
112: public static final int PROPERTYISBETWEEN = 107;
113:
114: public static final int PROPERTYISINSTANCEOF = 150;
115:
116: // logical operations
117: public static final int AND = 200;
118:
119: public static final int OR = 201;
120:
121: public static final int NOT = 202;
122:
123: public static final int UNKNOWN = -1;
124:
125: static {
126: if (names == null)
127: buildHashMaps();
128: }
129:
130: /**
131: * Returns the type of an operation for a given name.
132: *
133: * @return TYPE_SPATIAL / TYPE_COMPARISON / TYPE_LOGICAL / TYPE_UNKNOWN
134: */
135: public static int getTypeByName(String name) {
136: OperationInfo operationInfo = names.get(name);
137: if (operationInfo == null)
138: return TYPE_UNKNOWN;
139: return operationInfo.type;
140: }
141:
142: /**
143: * Returns the id of an operation for a given name.
144: *
145: * @return BBOX / PROPERTYISEQUAL / AND / ...
146: */
147: public static int getIdByName(String name) {
148: OperationInfo operationInfo = names.get(name.toLowerCase());
149: if (operationInfo == null)
150: return UNKNOWN;
151: return operationInfo.id;
152: }
153:
154: /**
155: * Returns the type of an operation for a given id.
156: *
157: * @return TYPE_SPATIAL / TYPE_COMPARISON / TYPE_LOGICAL / TYPE_UNKNOWN
158: */
159: public static int getTypeById(int id) {
160: OperationInfo operationInfo = ids.get(new Integer(id));
161: if (operationInfo == null)
162: return TYPE_UNKNOWN;
163: return operationInfo.type;
164: }
165:
166: /**
167: * Returns the name of an operation for a given id.
168: *
169: * @return null / Name of operation
170: */
171: public static String getNameById(int id) {
172:
173: OperationInfo operationInfo = ids.get(new Integer(id));
174: if (operationInfo == null)
175: return null;
176: return operationInfo.name;
177: }
178:
179: private static void addOperationInfo(int id, String name, int type) {
180: OperationInfo operationInfo = new OperationInfo(id, type, name);
181: names.put(name, operationInfo);
182: names.put(name.toLowerCase(), operationInfo);
183: names.put(name.toUpperCase(), operationInfo);
184: ids.put(new Integer(id), operationInfo);
185: }
186:
187: private static void buildHashMaps() {
188: names = new HashMap<String, OperationInfo>(25);
189: ids = new HashMap<Integer, OperationInfo>(25);
190:
191: addOperationInfo(BBOX, "BBOX", TYPE_SPATIAL);
192: addOperationInfo(EQUALS, "Equals", TYPE_SPATIAL);
193: addOperationInfo(DISJOINT, "Disjoint", TYPE_SPATIAL);
194: addOperationInfo(INTERSECTS, "Intersects", TYPE_SPATIAL);
195: addOperationInfo(TOUCHES, "Touches", TYPE_SPATIAL);
196: addOperationInfo(CROSSES, "Crosses", TYPE_SPATIAL);
197: addOperationInfo(WITHIN, "Within", TYPE_SPATIAL);
198: addOperationInfo(CONTAINS, "Contains", TYPE_SPATIAL);
199: addOperationInfo(OVERLAPS, "Overlaps", TYPE_SPATIAL);
200: addOperationInfo(BEYOND, "Beyond", TYPE_SPATIAL);
201: addOperationInfo(DWITHIN, "DWithin", TYPE_SPATIAL);
202:
203: addOperationInfo(PROPERTYISEQUALTO, "PropertyIsEqualTo",
204: TYPE_COMPARISON);
205: addOperationInfo(PROPERTYISLESSTHAN, "PropertyIsLessThan",
206: TYPE_COMPARISON);
207: addOperationInfo(PROPERTYISGREATERTHAN,
208: "PropertyIsGreaterThan", TYPE_COMPARISON);
209: addOperationInfo(PROPERTYISLESSTHANOREQUALTO,
210: "PropertyIsLessThanOrEqualTo", TYPE_COMPARISON);
211: addOperationInfo(PROPERTYISGREATERTHANOREQUALTO,
212: "PropertyIsGreaterThanOrEqualTo", TYPE_COMPARISON);
213: addOperationInfo(PROPERTYISLIKE, "PropertyIsLike",
214: TYPE_COMPARISON);
215: addOperationInfo(PROPERTYISNULL, "PropertyIsNull",
216: TYPE_COMPARISON);
217: addOperationInfo(PROPERTYISBETWEEN, "PropertyIsBetween",
218: TYPE_COMPARISON);
219: addOperationInfo(PROPERTYISINSTANCEOF, "PropertyIsInstanceOf",
220: TYPE_COMPARISON);
221:
222: addOperationInfo(AND, "And", TYPE_LOGICAL);
223: addOperationInfo(OR, "Or", TYPE_LOGICAL);
224: addOperationInfo(NOT, "Not", TYPE_LOGICAL);
225: }
226: }
227:
228: class OperationInfo {
229: int id;
230:
231: int type;
232:
233: String name;
234:
235: OperationInfo(int id, int type, String name) {
236: this.id = id;
237: this.type = type;
238: this.name = name;
239: }
240: }
|