svn-gvsig-desktop / branches / v02_desarrollo / libraries / sld / temp / org.gvsig.sldsupport.lib.api / oldcode / filterencoding / FLogicOperator.java @ 40799
History | View | Annotate | Download (5.98 KB)
1 | 40781 | jldominguez | /* gvSIG. Sistema de Informaci�n Geogr�fica de la Generalitat Valenciana
|
---|---|---|---|
2 | *
|
||
3 | * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
||
4 | *
|
||
5 | * This program is free software; you can redistribute it and/or
|
||
6 | * modify it under the terms of the GNU General Public License
|
||
7 | * as published by the Free Software Foundation; either version 2
|
||
8 | * of the License, or (at your option) any later version.
|
||
9 | *
|
||
10 | * This program is distributed in the hope that it will be useful,
|
||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
13 | * GNU General Public License for more details.
|
||
14 | *
|
||
15 | * You should have received a copy of the GNU General Public License
|
||
16 | * along with this program; if not, write to the Free Software
|
||
17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
||
18 | *
|
||
19 | * For more information, contact:
|
||
20 | *
|
||
21 | * Generalitat Valenciana
|
||
22 | * Conselleria d'Infraestructures i Transport
|
||
23 | * Av. Blasco Ib��ez, 50
|
||
24 | * 46010 VALENCIA
|
||
25 | * SPAIN
|
||
26 | *
|
||
27 | * +34 963862235
|
||
28 | * gvsig@gva.es
|
||
29 | * www.gvsig.gva.es
|
||
30 | *
|
||
31 | * or
|
||
32 | *
|
||
33 | * IVER T.I. S.A
|
||
34 | * Salamanca 50
|
||
35 | * 46005 Valencia
|
||
36 | * Spain
|
||
37 | *
|
||
38 | * +34 963163400
|
||
39 | * dac@iver.es
|
||
40 | */
|
||
41 | package org.gvsig.sldsupport.filterencoding; |
||
42 | |||
43 | import java.io.IOException; |
||
44 | import java.util.ArrayList; |
||
45 | import java.util.HashSet; |
||
46 | import java.util.Set; |
||
47 | |||
48 | import org.gvsig.sldsupport.exception.SLDReadException; |
||
49 | import org.xmlpull.v1.XmlPullParser; |
||
50 | import org.xmlpull.v1.XmlPullParserException; |
||
51 | |||
52 | /**
|
||
53 | * Implements the main functionalities to parse a logical operator
|
||
54 | * of a Filter Encoding expression<br>
|
||
55 | *
|
||
56 | * A logical operator can be used to combine one or more conditional
|
||
57 | * expressions. The logical operator AND evaluates to TRUE if all the
|
||
58 | * combined expressions evaluate to TRUE. The operator OR evaluates to
|
||
59 | * TRUE if is any of the combined expressions evaluate to TRUE. The NOT
|
||
60 | * operator reverses the logical value of an expression.
|
||
61 | *
|
||
62 | * @see http://www.opengeospatial.org/standards/filter
|
||
63 | * @author pepe vidal salvador - jose.vidal.salvador@iver.es
|
||
64 | */
|
||
65 | public class FLogicOperator { |
||
66 | |||
67 | String logicType;
|
||
68 | |||
69 | ArrayList<FComparisonOperator> compOperator = new ArrayList<FComparisonOperator>(); |
||
70 | ArrayList<FLogicOperator> logicOperators = new ArrayList<FLogicOperator>(); |
||
71 | ArrayList<FLogicOperatorNot> logicNotOperators = new ArrayList<FLogicOperatorNot>(); |
||
72 | Set <String> fieldNames = new HashSet <String>(); |
||
73 | int numOperators = 0; |
||
74 | protected String opExpressionStr = ""; |
||
75 | |||
76 | public void parse(XmlPullParser parser, String tag) |
||
77 | throws XmlPullParserException, IOException, SLDReadException { |
||
78 | |||
79 | int currentTag;
|
||
80 | boolean end = false; |
||
81 | |||
82 | this.logicType = tag;
|
||
83 | |||
84 | |||
85 | parser.require(XmlPullParser.START_TAG, null, tag);
|
||
86 | currentTag = parser.next(); |
||
87 | |||
88 | while (!end)
|
||
89 | { |
||
90 | switch(currentTag)
|
||
91 | { |
||
92 | case XmlPullParser.START_TAG:
|
||
93 | if (parser.getName().compareTo(FilterUtils.remNameSpace(FilterTags.PROPERTYISEQUALTO))==0 || |
||
94 | parser.getName().compareTo(FilterUtils.remNameSpace(FilterTags.PROPERTYISNOTEQUALTO))==0 ||
|
||
95 | parser.getName().compareTo(FilterUtils.remNameSpace(FilterTags.PROPERTYISLESSTHAN))==0 ||
|
||
96 | parser.getName().compareTo(FilterUtils.remNameSpace(FilterTags.PROPERTYISGREATERTHAN))==0 ||
|
||
97 | parser.getName().compareTo(FilterUtils.remNameSpace(FilterTags.PROPERTYISLESSOREQUALTHAN))==0 ||
|
||
98 | parser.getName().compareTo(FilterUtils.remNameSpace(FilterTags.PROPERTYISGREATEROREQUALTHAN))==0) {
|
||
99 | |||
100 | FComparisonOperator compOp = new FComparisonOperator();
|
||
101 | |||
102 | if(numOperators >= 1) |
||
103 | opExpressionStr += FilterUtils.getSymbol4Expression("ogc:"+logicType)+" "; |
||
104 | opExpressionStr += "( ";
|
||
105 | compOp.parse(parser , parser.getName()); |
||
106 | opExpressionStr += compOp.getOpExpressionStr(); |
||
107 | opExpressionStr += ") ";
|
||
108 | |||
109 | fieldNames.addAll(compOp.getFieldNames()); |
||
110 | compOperator.add(compOp); |
||
111 | numOperators++; |
||
112 | } |
||
113 | |||
114 | |||
115 | else if (parser.getName().compareTo(FilterUtils.remNameSpace(FilterTags.AND)) ==0 || |
||
116 | parser.getName().compareTo(FilterUtils.remNameSpace(FilterTags.OR)) ==0) {
|
||
117 | |||
118 | FLogicOperator propLog = new FLogicOperator();
|
||
119 | |||
120 | if(numOperators >= 1) |
||
121 | opExpressionStr += FilterUtils.getSymbol4Expression("ogc:"+logicType)+" "; |
||
122 | opExpressionStr += "( ";
|
||
123 | propLog.parse(parser , parser.getName()); |
||
124 | opExpressionStr += propLog.getOpExpressionStr(); |
||
125 | opExpressionStr += ") ";
|
||
126 | |||
127 | fieldNames.addAll(propLog.getFieldNames()); |
||
128 | logicOperators.add(propLog); |
||
129 | numOperators++; |
||
130 | if (propLog.getNumOperators() < 2) { |
||
131 | throw new SLDReadException(new Exception( |
||
132 | "Found " + propLog.getNumOperators() + " operators, expected 2.")); |
||
133 | } |
||
134 | |||
135 | |||
136 | } |
||
137 | else if (parser.getName().compareTo(FilterUtils.remNameSpace(FilterTags.NOT)) ==0) { |
||
138 | FLogicOperatorNot notlogicOperators = new FLogicOperatorNot();
|
||
139 | |||
140 | if(numOperators >= 1) |
||
141 | opExpressionStr += FilterUtils.getSymbol4Expression("ogc:"+logicType)+" "; |
||
142 | opExpressionStr += "( "+"! "; |
||
143 | notlogicOperators.parse(parser,parser.getName()); |
||
144 | opExpressionStr += notlogicOperators.getOpExpressionStr(); |
||
145 | opExpressionStr += ") ";
|
||
146 | |||
147 | fieldNames.addAll(notlogicOperators.getFieldNames()); |
||
148 | logicNotOperators.add(notlogicOperators); |
||
149 | numOperators++; |
||
150 | |||
151 | } |
||
152 | |||
153 | break;
|
||
154 | case XmlPullParser.END_TAG:
|
||
155 | if (parser.getName().compareTo(tag) == 0) |
||
156 | end = true;
|
||
157 | break;
|
||
158 | case XmlPullParser.TEXT:
|
||
159 | break;
|
||
160 | } |
||
161 | if (!end)
|
||
162 | currentTag = parser.next(); |
||
163 | } |
||
164 | |||
165 | parser.require(XmlPullParser.END_TAG, null, tag);
|
||
166 | |||
167 | } |
||
168 | public int getNumOperators() { return numOperators; } |
||
169 | public void setNumOperators(int numOperators) {this.numOperators = numOperators; } |
||
170 | public Set<String> getFieldNames() { return fieldNames; } |
||
171 | |||
172 | |||
173 | public String getLogicType() {return logicType;} |
||
174 | public ArrayList<FComparisonOperator> getCompOperator() {return compOperator;} |
||
175 | public String getOpExpressionStr() { |
||
176 | return opExpressionStr;
|
||
177 | } |
||
178 | |||
179 | |||
180 | } |