001: //$HeadURL: https://svn.wald.intevation.org/svn/deegree/base/trunk/src/org/deegree/model/filterencoding/AbstractOperation.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 org.w3c.dom.Element;
047:
048: /**
049: * Abstract superclass representing spatial_ops, comparison_ops and logical_ops entities (as defined
050: * in the Filter DTD). The three different types are reflected in SpatialOperation,
051: * ComparisonOperation and LogicalOperation classes.
052: *
053: * @author <a href="mailto:schneider@lat-lon.de">Markus Schneider</a>
054: * @author last edited by: $Author: apoth $
055: *
056: * @version $Revision: 9343 $, $Date: 2007-12-27 05:30:32 -0800 (Thu, 27 Dec 2007) $
057: */
058: public abstract class AbstractOperation implements Operation {
059:
060: /**
061: * The underlying operator's id.
062: *
063: * @see OperationDefines
064: */
065: protected int operatorId;
066:
067: /**
068: *
069: * @param operatorId
070: */
071: AbstractOperation(int operatorId) {
072: this .operatorId = operatorId;
073: }
074:
075: /**
076: * Given a DOM-fragment, a corresponding Operation-object is built. This method recursively
077: * calls other buildFromDOM () - methods to validate the structure of the DOM-fragment.
078: *
079: * @param element
080: * @param useVersion_1_0_0
081: * true if the filter encoding 1.0.0 should be used.
082: * @return operation instance
083: * @throws FilterConstructionException
084: * if the structure of the DOM-fragment is invalid
085: * @deprecated use the 1.0.0 filter encoding aware method instead.
086: */
087: @Deprecated
088: public static Operation buildFromDOM(Element element)
089: throws FilterConstructionException {
090: return buildFromDOM(element, false);
091: }
092:
093: /**
094: * Given a DOM-fragment, a corresponding Operation-object is built. This method recursively
095: * calls other buildFromDOM () - methods to validate the structure of the DOM-fragment.
096: *
097: * @param element
098: * @param useVersion_1_0_0
099: * true if the filter encoding 1.0.0 should be used.
100: * @return operation instance
101: * @throws FilterConstructionException
102: * if the structure of the DOM-fragment is invalid
103: *
104: */
105: public static Operation buildFromDOM(Element element,
106: boolean useVersion_1_0_0)
107: throws FilterConstructionException {
108:
109: // check if root element's name is a known operator
110: String name = element.getLocalName();
111: int type = OperationDefines.getTypeByName(name);
112: Operation operation = null;
113:
114: switch (type) {
115: case OperationDefines.TYPE_SPATIAL: {
116: operation = SpatialOperation.buildFromDOM(element,
117: useVersion_1_0_0);
118: break;
119: }
120: case OperationDefines.TYPE_COMPARISON: {
121: operation = ComparisonOperation.buildFromDOM(element,
122: useVersion_1_0_0);
123: break;
124: }
125: case OperationDefines.TYPE_LOGICAL: {
126: operation = LogicalOperation.buildFromDOM(element,
127: useVersion_1_0_0);
128: break;
129: }
130: default: {
131: throw new FilterConstructionException("Unknown operator '"
132: + name + "'!");
133: }
134: }
135: return operation;
136: }
137:
138: /**
139: * Returns the name of the operator.
140: *
141: * @return operation name
142: */
143: public String getOperatorName() {
144: return OperationDefines.getNameById(operatorId);
145: }
146:
147: /**
148: * Returns the operator's id.
149: *
150: * @see OperationDefines
151: * @return operation id
152: */
153: public int getOperatorId() {
154: return operatorId;
155: }
156: }
|