001: //$HeadURL: https://svn.wald.intevation.org/svn/deegree/base/trunk/src/org/deegree/model/filterencoding/ComplexFilter.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.ArrayList;
047:
048: import org.deegree.model.feature.Feature;
049:
050: /**
051: * Encapsulates the information of a <Filter> element that contains an Operation (only) (as defined
052: * in the Filter DTD). Operation is one of the following types:
053: * <ul>
054: * <li>spatial_ops</li>
055: * <li>comparison_ops</li>
056: * <li>logical_ops</li>
057: * </ul>
058: *
059: * @author Markus Schneider
060: * @version 06.08.2002
061: */
062:
063: public class ComplexFilter extends AbstractFilter {
064:
065: /**
066: * Operation the ComplexFilter is based on
067: */
068: private Operation operation;
069:
070: /** Constructs a new ComplexFilter based on the given operation. */
071: public ComplexFilter(Operation operation) {
072: this .operation = operation;
073: }
074:
075: /**
076: * Constructs a new <tt>ComplexFilter<tt> that consists of an
077: * empty <tt>LogicalOperation</tt> of the given type.
078: * <p>
079: * @param operatorId OperationDefines.AND, OperationDefines.OR or
080: * OperationDefines.NOT
081: * @throws FilterConstructionException
082: */
083: public ComplexFilter(int operatorId) {
084: operation = new LogicalOperation(operatorId,
085: new ArrayList<Operation>());
086: }
087:
088: /**
089: * Constructs a new <tt>ComplexFilter<tt> that consists of a
090: * <tt>LogicalOperation</tt> with the given <tt>Filter</tt>.
091: * <p>
092: * @param filter1 first Filter to be used
093: * @param filter2 second Filter to be used
094: * null, if operatorId == OperationDefines.NOT
095: * @param operatorId OperationDefines.AND, OperationDefines.OR or
096: * OperationDefines.NOT
097: * @throws FilterConstructionException
098: */
099: public ComplexFilter(ComplexFilter filter1, ComplexFilter filter2,
100: int operatorId) {
101:
102: // extract the Operations from the Filters
103: ArrayList<Operation> arguments = new ArrayList<Operation>();
104: arguments.add(filter1.getOperation());
105: if (filter2 != null)
106: arguments.add(filter2.getOperation());
107:
108: operation = new LogicalOperation(operatorId, arguments);
109: }
110:
111: /**
112: * Returns the contained Operation.
113: *
114: */
115: public Operation getOperation() {
116: return operation;
117: }
118:
119: /**
120: * Calculates the <tt>Filter</tt>'s logical value based on the certain property values of the
121: * given feature.
122: *
123: * @param feature
124: * that determines the values of <tt>PropertyNames</tt> in the expression
125: * @return true, if the <tt>Filter</tt> evaluates to true, else false
126: * @throws FilterEvaluationException
127: * if the evaluation fails
128: */
129: public boolean evaluate(Feature feature)
130: throws FilterEvaluationException {
131: return operation.evaluate(feature);
132: }
133:
134: /** Produces an indented XML representation of this object. */
135: public StringBuffer toXML() {
136: StringBuffer sb = new StringBuffer(1000);
137: sb
138: .append("<ogc:Filter xmlns:ogc='http://www.opengis.net/ogc'>");
139: sb.append(operation.toXML());
140: sb.append("</ogc:Filter>\n");
141: return sb;
142: }
143: }
|