Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libFMap_data_eval_SQLJEP / src-test / org / gvsig / fmap / data / feature / expressionevaluator / sqljep / VisitTreeTest.java @ 23098

History | View | Annotate | Download (7.29 KB)

1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22

    
23
/*
24
* AUTHORS (In addition to CIT):
25
* 2008 IVER T.I. S.A.   {{Task}}
26
*/
27

    
28
package org.gvsig.fmap.data.feature.expressionevaluator.sqljep;
29

    
30
import junit.framework.TestCase;
31

    
32
import org.gvsig.fmap.data.feature.AttributeDescriptor;
33
import org.gvsig.fmap.data.feature.DefaultFeatureType;
34
import org.gvsig.fmap.data.feature.FeatureAttributeDescriptor;
35
import org.gvsig.fmap.data.feature.FeatureType;
36
import org.gvsig.fmap.data.feature.IsNotAttributeSettingException;
37
import org.gvsig.fmap.geom.Geometry;
38
import org.medfoster.sqljep.ASTArray;
39
import org.medfoster.sqljep.ASTFunNode;
40
import org.medfoster.sqljep.ASTStart;
41
import org.medfoster.sqljep.ASTVarNode;
42
import org.medfoster.sqljep.Node;
43
import org.medfoster.sqljep.ParseException;
44
import org.medfoster.sqljep.SimpleNode;
45

    
46
public class VisitTreeTest extends TestCase {
47

    
48
        public void testParser() {
49
                FeatureType fType = newFeatureType();
50

    
51
                MyParser p = new MyParser(
52
                                "ID=1 and intersects(GeomFromText('xxx','23030'),GEOMETRY)",
53
                                fType);
54
                try {
55
                        p.myParseExpression();
56

    
57
                        assertTrue(p.isValid());
58
                        Node node = p.getTopNode();
59
                        System.out.println(node);
60

    
61
                        iterate(node);
62
                } catch (Exception e) {
63
                        e.printStackTrace();
64
                }
65

    
66
        }
67

    
68
        private void iterate(Node node) {
69
                if (node == null) {
70
                        return;
71
                }
72
                for (int i = 0; i < node.jjtGetNumChildren(); i++) {
73
                        Node n = node.jjtGetChild(i);
74
                        System.out.println(n.toString());
75
                        iterate(n);
76
                }
77
        }
78

    
79
        private FeatureType newFeatureType() {
80
                DefaultFeatureType fType = new DefaultFeatureType();
81

    
82
                try {
83
                        AttributeDescriptor descriptorID = (AttributeDescriptor) fType
84
                                        .createAttributeDescriptor();
85
                        descriptorID.loading();
86
                        descriptorID.setType(FeatureAttributeDescriptor.TYPE_INT);
87
                        descriptorID.setName("ID");
88
                        descriptorID.setDefaultValue(new Integer(0));
89
                        descriptorID.stopLoading();
90
                        fType.add(descriptorID);
91

    
92
                        AttributeDescriptor descriptorShape = (AttributeDescriptor) fType
93
                                        .createAttributeDescriptor();
94
                        descriptorShape.loading();
95
                        descriptorShape.setType(FeatureAttributeDescriptor.TYPE_GEOMETRY);
96
                        descriptorShape.setName("GEOMETRY");
97
                        descriptorShape.setDefaultValue(null);
98
                        descriptorShape.stopLoading();
99
                        fType.add(descriptorShape);
100
                        fType.setDefaultGeometry("GEOMETRY");
101

    
102
                        AttributeDescriptor descriptorEntity = (AttributeDescriptor) fType
103
                                        .createAttributeDescriptor();
104
                        descriptorEntity.loading();
105
                        descriptorEntity.setType(FeatureAttributeDescriptor.TYPE_STRING);
106
                        descriptorEntity.setName("Entity");
107
                        descriptorEntity.setDefaultValue("Entity");
108
                        descriptorEntity.stopLoading();
109
                        fType.add(descriptorEntity);
110

    
111
                        AttributeDescriptor descriptorLayer = (AttributeDescriptor) fType
112
                                        .createAttributeDescriptor();
113
                        descriptorLayer.loading();
114
                        descriptorLayer.setType(FeatureAttributeDescriptor.TYPE_STRING);
115
                        descriptorLayer.setName("Layer");
116
                        descriptorLayer.setDefaultValue("default");
117
                        descriptorLayer.stopLoading();
118
                        fType.add(descriptorLayer);
119

    
120
                        AttributeDescriptor descriptorColor = (AttributeDescriptor) fType
121
                                        .createAttributeDescriptor();
122
                        descriptorColor.loading();
123
                        descriptorColor.setType(FeatureAttributeDescriptor.TYPE_INT);
124
                        descriptorColor.setName("Color");
125
                        descriptorColor.setDefaultValue(new Integer(0));
126
                        descriptorColor.stopLoading();
127
                        fType.add(descriptorColor);
128

    
129
                        AttributeDescriptor descriptorElevation = (AttributeDescriptor) fType
130
                                        .createAttributeDescriptor();
131
                        descriptorElevation.loading();
132
                        descriptorElevation.setType(FeatureAttributeDescriptor.TYPE_DOUBLE);
133
                        descriptorElevation.setName("Elevation");
134
                        descriptorElevation.setDefaultValue(new Double(0));
135
                        descriptorElevation.stopLoading();
136
                        fType.add(descriptorElevation);
137

    
138
                        AttributeDescriptor descriptorThickness = (AttributeDescriptor) fType
139
                                        .createAttributeDescriptor();
140
                        descriptorThickness.loading();
141
                        descriptorThickness.setType(FeatureAttributeDescriptor.TYPE_DOUBLE);
142
                        descriptorThickness.setName("Thickness");
143
                        descriptorThickness.setDefaultValue(new Double(0));
144
                        descriptorThickness.stopLoading();
145
                        fType.add(descriptorThickness);
146

    
147
                        AttributeDescriptor descriptorText = (AttributeDescriptor) fType
148
                                        .createAttributeDescriptor();
149
                        descriptorText.loading();
150
                        descriptorText.setType(FeatureAttributeDescriptor.TYPE_STRING);
151
                        descriptorText.setName("Text");
152
                        descriptorText.setDefaultValue("");
153
                        descriptorText.stopLoading();
154
                        fType.add(descriptorText);
155

    
156
                        AttributeDescriptor descriptorHeightText = (AttributeDescriptor) fType
157
                                        .createAttributeDescriptor();
158
                        descriptorHeightText.loading();
159
                        descriptorHeightText.setType(FeatureAttributeDescriptor.TYPE_FLOAT);
160
                        descriptorHeightText.setName("HeightText");
161
                        descriptorHeightText.setDefaultValue(new Float(10));
162
                        descriptorHeightText.stopLoading();
163
                        fType.add(descriptorHeightText);
164

    
165
                        AttributeDescriptor descriptorRotationText = (AttributeDescriptor) fType
166
                                        .createAttributeDescriptor();
167
                        descriptorRotationText.loading();
168
                        descriptorRotationText
169
                                        .setType(FeatureAttributeDescriptor.TYPE_DOUBLE);
170
                        descriptorRotationText.setName("Rotation");
171
                        descriptorRotationText.setDefaultValue(new Double(10));
172
                        descriptorRotationText.stopLoading();
173
                        fType.add(descriptorRotationText);
174
                        fType.setDefaultGeometry("GEOMETRY");
175
                        fType.setGeometryTypes(new int[] { Geometry.TYPES.GEOMETRY });
176
                } catch (IsNotAttributeSettingException e) {
177
                        e.printStackTrace();
178
                }
179

    
180
                return fType;
181

    
182
        }
183

    
184
        class PVisitor /* implements ParserVisitor */{
185

    
186
                public Object visit(SimpleNode arg0, Object arg1) throws ParseException {
187
                        // TODO Auto-generated method stub
188
                        return null;
189
                }
190

    
191
                public Object visit(ASTStart arg0, Object arg1) throws ParseException {
192
                        // TODO Auto-generated method stub
193
                        return null;
194
                }
195

    
196
                public Object visit(ASTFunNode arg0, Object arg1) throws ParseException {
197
                        // TODO Auto-generated method stub
198
                        return null;
199
                }
200

    
201
                public Object visit(ASTVarNode arg0, Object arg1) throws ParseException {
202
                        // TODO Auto-generated method stub
203
                        return null;
204
                }
205

    
206
                public Object visit(ASTArray arg0, Object arg1) throws ParseException {
207
                        // TODO Auto-generated method stub
208
                        return null;
209
                }
210

    
211
                /*
212
                 * public Object visit(ASTConstant arg0, Object arg1) throws
213
                 * ParseException { // TODO Auto-generated method stub return null; }
214
                 */
215

    
216
        }
217

    
218
        private class MyParser extends ExpressionEvaluator {
219

    
220
                public MyParser(String expression, FeatureType featureType) {
221
                        super(expression, featureType);
222
                }
223

    
224
                public void myParseExpression() throws ParseException {
225
                        this.parseExpression();
226

    
227
                }
228

    
229
        }
230

    
231
}