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