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