001 //$HeadURL: https://svn.wald.intevation.org/svn/deegree/base/branches/2.4_testing/src/org/deegree/model/filterencoding/Expression.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.deegree.model.feature.Feature;
039 import org.w3c.dom.Element;
040
041 /**
042 * Abstract superclass representing expr-entities (as defined in the Expression DTD).
043 *
044 * @author <a href="mailto:schneider@lat-lon.de">Markus Schneider</a>
045 * @author last edited by: $Author: mschneider $
046 *
047 * @version $Revision: 18195 $, $Date: 2009-06-18 17:55:39 +0200 (Do, 18. Jun 2009) $
048 */
049 abstract public class Expression {
050
051 /**
052 * The underlying expression's id.
053 *
054 * @see ExpressionDefines
055 */
056 protected int id;
057
058 /**
059 * Given a DOM-fragment, a corresponding Expression-object is built. This method recursively calls other
060 * buildFromDOM () - methods to validate the structure of the DOM-fragment.
061 *
062 * @param element
063 * @return the Bean of the DOM
064 *
065 * @throws FilterConstructionException
066 * if the structure of the DOM-fragment is invalid
067 */
068 public static Expression buildFromDOM( Element element )
069 throws FilterConstructionException {
070
071 // check if root element's name is a known expression
072 String name = element.getLocalName();
073 int id = ExpressionDefines.getIdByName( name );
074 Expression expression = null;
075
076 switch ( id ) {
077 case ExpressionDefines.EXPRESSION: {
078 break;
079 }
080 case ExpressionDefines.PROPERTYNAME: {
081 expression = PropertyName.buildFromDOM( element );
082 break;
083 }
084 case ExpressionDefines.LITERAL: {
085 expression = Literal.buildFromDOM( element );
086 break;
087 }
088 case ExpressionDefines.FUNCTION: {
089 expression = Function.buildFromDOM( element );
090 break;
091 }
092 case ExpressionDefines.ADD:
093 case ExpressionDefines.SUB:
094 case ExpressionDefines.MUL:
095 case ExpressionDefines.DIV: {
096 expression = ArithmeticExpression.buildFromDOM( element );
097 break;
098 }
099 default: {
100 throw new FilterConstructionException( "Unknown expression '" + name + "'!" );
101 }
102 }
103 return expression;
104 }
105
106 /** @return the name of the expression. */
107 public String getExpressionName() {
108 return ExpressionDefines.getNameById( id );
109 }
110
111 /**
112 * @return the expression's id.
113 *
114 * @see ExpressionDefines
115 */
116 public int getExpressionId() {
117 return this.id;
118 }
119
120 /**
121 * Calculates the <tt>Expression</tt>'s value based on the certain property values of the given feature.
122 *
123 * @param feature
124 * that determines the values of <tt>PropertyNames</tt> in the expression
125 * @return the resulting Object
126 * @throws FilterEvaluationException
127 * if the evaluation fails
128 */
129 public abstract Object evaluate( Feature feature )
130 throws FilterEvaluationException;
131
132 /**
133 * Produces an XML representation of this object.
134 *
135 * @return an XML representation of this object
136 */
137 public abstract StringBuffer toXML();
138 }