1
|
Index: src/org/ecoinformatics/ecogrid/EcogridQueryParser.java
|
2
|
===================================================================
|
3
|
RCS file: /cvs/seek/projects/ecogrid/src/org/ecoinformatics/ecogrid/EcogridQueryParser.java,v
|
4
|
retrieving revision 1.3
|
5
|
diff -u -r1.3 EcogridQueryParser.java
|
6
|
--- src/org/ecoinformatics/ecogrid/EcogridQueryParser.java 6 Oct 2004 18:21:41 -0000 1.3
|
7
|
+++ src/org/ecoinformatics/ecogrid/EcogridQueryParser.java 9 Dec 2004 21:02:26 -0000
|
8
|
@@ -54,44 +54,62 @@
|
9
|
public class EcogridQueryParser
|
10
|
{
|
11
|
//fields
|
12
|
- private QueryType ecogridQuery;
|
13
|
- private Document doc;
|
14
|
+ private QueryType _ecogridQuery;
|
15
|
+ private Node _queryNode;
|
16
|
+
|
17
|
//Constant
|
18
|
- private static final String QUERYIDATTRIBUTE = "/query/@queryId";
|
19
|
- private static final String SYSTEMATTRIBUTE = "/query/@system";
|
20
|
- private static final String NAMESPACE = "/query/namespace";
|
21
|
- private static final String PREFIX = "prefix";
|
22
|
- private static final String RETURNFIELD = "/query/returnfield";
|
23
|
- private static final String TITLE = "/query/title";
|
24
|
- private static final String FIRSTAND = "/query/AND";
|
25
|
- private static final String FIRSTOR = "/query/OR";
|
26
|
- private static final String FIRSTCONDITION = "/query/condition";
|
27
|
- private static final String AND = "AND";
|
28
|
- private static final String OR = "OR";
|
29
|
- private static final String CON = "condition";
|
30
|
- private static final String OPERATOR = "operator";
|
31
|
- private static final String CONCEPT = "concept";
|
32
|
+ private static final String QUERYIDATTRIBUTE = "@queryId";
|
33
|
+ private static final String SYSTEMATTRIBUTE = "@system";
|
34
|
+ private static final String NAMESPACE = "namespace";
|
35
|
+ private static final String PREFIX = "prefix";
|
36
|
+ private static final String RETURNFIELD = "returnField";
|
37
|
+ private static final String TITLE = "title";
|
38
|
+ private static final String FIRSTAND = "AND";
|
39
|
+ private static final String FIRSTOR = "OR";
|
40
|
+ private static final String FIRSTCONDITION = "condition";
|
41
|
+ private static final String AND = "AND";
|
42
|
+ private static final String OR = "OR";
|
43
|
+ private static final String CON = "condition";
|
44
|
+ private static final String OPERATOR = "operator";
|
45
|
+ private static final String CONCEPT = "concept";
|
46
|
+
|
47
|
/**
|
48
|
- * default constructor
|
49
|
+ * Constructor with reader for parsing XML
|
50
|
* @param xmlInput xml source
|
51
|
*/
|
52
|
public EcogridQueryParser (Reader xmlInput) throws Exception
|
53
|
{
|
54
|
//create new ecogrid query java object
|
55
|
- ecogridQuery = new QueryType();
|
56
|
+ _ecogridQuery = new QueryType();
|
57
|
//build dom tree
|
58
|
InputSource in = new InputSource(xmlInput);
|
59
|
DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance();
|
60
|
dfactory.setNamespaceAware(false);
|
61
|
- doc = dfactory.newDocumentBuilder().parse(in);
|
62
|
- }//EcogridQueryParser
|
63
|
+ Document doc = dfactory.newDocumentBuilder().parse(in);
|
64
|
+
|
65
|
+ // Find the query node, all searches are relative to it.
|
66
|
+ NodeList queryIdList = XPathAPI.selectNodeList(doc, "/query");
|
67
|
+ _queryNode = queryIdList.item(0);
|
68
|
+
|
69
|
+ } //EcogridQueryParser
|
70
|
+
|
71
|
+ /**
|
72
|
+ * Constructor wityh DOM node point to Query node
|
73
|
+ * @param aQueryDOMNode DOM Node
|
74
|
+ */
|
75
|
+ public EcogridQueryParser (Node aQueryDOMNode)
|
76
|
+ {
|
77
|
+ //create new ecogrid query java object
|
78
|
+ _ecogridQuery = new QueryType();
|
79
|
+ _queryNode = aQueryDOMNode;
|
80
|
+ } //EcogridQueryParser
|
81
|
|
82
|
/**
|
83
|
* Method to get ecogridquery
|
84
|
*/
|
85
|
public QueryType getEcogridQuery()
|
86
|
{
|
87
|
- return ecogridQuery;
|
88
|
+ return _ecogridQuery;
|
89
|
}
|
90
|
|
91
|
/**
|
92
|
@@ -99,7 +117,7 @@
|
93
|
*/
|
94
|
public void setEcogridQuery(QueryType query)
|
95
|
{
|
96
|
- ecogridQuery = query;
|
97
|
+ _ecogridQuery = query;
|
98
|
}
|
99
|
|
100
|
/**
|
101
|
@@ -114,30 +132,55 @@
|
102
|
setupFirstRelation();
|
103
|
}//parseXML
|
104
|
|
105
|
-
|
106
|
+ private Node getAttrNode(String aDocXPath, String aNodeXPath)
|
107
|
+ {
|
108
|
+ Node node = _queryNode;
|
109
|
+ try
|
110
|
+ {
|
111
|
+ if (_queryNode.getNodeType() == Node.DOCUMENT_NODE)
|
112
|
+ {
|
113
|
+ NodeList queryIdList = XPathAPI.selectNodeList(_queryNode, aDocXPath);
|
114
|
+ node = queryIdList.item(0);
|
115
|
+ }
|
116
|
+ else
|
117
|
+ {
|
118
|
+ NodeList queryIdList = XPathAPI.selectNodeList(_queryNode, aNodeXPath);
|
119
|
+ node = queryIdList.item(0);
|
120
|
+ }
|
121
|
+ } catch (Exception e)
|
122
|
+ {
|
123
|
+ System.err.println(e);
|
124
|
+ }
|
125
|
+ return node;
|
126
|
+ }
|
127
|
/* setup queryid and system */
|
128
|
private void setupQueryIdAndSystem() throws Exception
|
129
|
{
|
130
|
+ // The _queryNode may be a document node qparsed in from an XML document or may be
|
131
|
+ // a generic DOM node (a subtree) of an existing tree
|
132
|
// get query id
|
133
|
- NodeList queryIdList = XPathAPI.selectNodeList(doc, QUERYIDATTRIBUTE);
|
134
|
- String queryId = (queryIdList.item(0)).getNodeValue();
|
135
|
+ NodeList queryIdList = XPathAPI.selectNodeList(_queryNode, QUERYIDATTRIBUTE);
|
136
|
+ String queryId = ((Node)queryIdList.item(0)).getNodeValue();
|
137
|
+
|
138
|
//System.out.println("queryId is: "+ queryId);
|
139
|
// set query id
|
140
|
- ecogridQuery.setQueryId(queryId);
|
141
|
+ _ecogridQuery.setQueryId(queryId);
|
142
|
// get system
|
143
|
- NodeList systemList = XPathAPI.selectNodeList(doc, SYSTEMATTRIBUTE);
|
144
|
+ NodeList systemList = XPathAPI.selectNodeList(_queryNode, SYSTEMATTRIBUTE);
|
145
|
String system = (systemList.item(0)).getNodeValue();
|
146
|
//System.out.println("system is: "+ system);
|
147
|
URI systemUri = new URI(system);
|
148
|
//set system
|
149
|
- ecogridQuery.setSystem(systemUri);
|
150
|
- }//setupQueryIdAndSystem
|
151
|
+ _ecogridQuery.setSystem(systemUri);
|
152
|
+
|
153
|
+ } // setupQueryIdAndSystem
|
154
|
|
155
|
+
|
156
|
/* setup namepsace */
|
157
|
private void setupNamespace() throws Exception
|
158
|
{
|
159
|
// get namespace
|
160
|
- NodeList namespaceList = XPathAPI.selectNodeList(doc, NAMESPACE);
|
161
|
+ NodeList namespaceList = XPathAPI.selectNodeList(_queryNode, NAMESPACE);
|
162
|
int length = namespaceList.getLength();
|
163
|
QueryType_namespace [] namespaceArray;
|
164
|
if ( length != 0 )
|
165
|
@@ -159,7 +202,7 @@
|
166
|
namespaceArray[i]=queryNamespace;
|
167
|
}
|
168
|
// set up the QueryType_namespace object to ecogrid query object
|
169
|
- ecogridQuery.setNamespace(namespaceArray);
|
170
|
+ _ecogridQuery.setNamespace(namespaceArray);
|
171
|
}
|
172
|
}//setupNamespace
|
173
|
|
174
|
@@ -167,7 +210,7 @@
|
175
|
private void setupReturnField() throws Exception
|
176
|
{
|
177
|
// get retrunfield
|
178
|
- NodeList returnFieldList = XPathAPI.selectNodeList(doc, RETURNFIELD);
|
179
|
+ NodeList returnFieldList = XPathAPI.selectNodeList(_queryNode, RETURNFIELD);
|
180
|
String [] returnFieldArray ;
|
181
|
int length = returnFieldList.getLength();
|
182
|
if (length != 0)
|
183
|
@@ -181,7 +224,7 @@
|
184
|
returnFieldArray[i] = returnfieldString;
|
185
|
}
|
186
|
// set up the QueryType_namespace object to ecogrid query object
|
187
|
- ecogridQuery.setReturnfield(returnFieldArray);
|
188
|
+ _ecogridQuery.setReturnfield(returnFieldArray);
|
189
|
}
|
190
|
}//setupReturnField
|
191
|
|
192
|
@@ -189,7 +232,7 @@
|
193
|
private void setupTitle() throws Exception
|
194
|
{
|
195
|
// get retrunfield
|
196
|
- NodeList titleList = XPathAPI.selectNodeList(doc, TITLE);
|
197
|
+ NodeList titleList = XPathAPI.selectNodeList(_queryNode, TITLE);
|
198
|
String [] titleArray ;
|
199
|
int length = titleList.getLength();
|
200
|
if (length != 0)
|
201
|
@@ -204,16 +247,16 @@
|
202
|
titleArray[i] = titleString;
|
203
|
}
|
204
|
// set up the QueryType_namespace object to ecogrid query object
|
205
|
- ecogridQuery.setTitle(titleArray);
|
206
|
+ _ecogridQuery.setTitle(titleArray);
|
207
|
}
|
208
|
}//setupReturnField
|
209
|
|
210
|
/* setup first relation type */
|
211
|
private void setupFirstRelation() throws Exception
|
212
|
{
|
213
|
- NodeList firstAND = XPathAPI.selectNodeList(doc, FIRSTAND);
|
214
|
- NodeList firstOR = XPathAPI.selectNodeList(doc, FIRSTOR);
|
215
|
- NodeList firstCondition = XPathAPI.selectNodeList(doc, FIRSTCONDITION);
|
216
|
+ NodeList firstAND = XPathAPI.selectNodeList(_queryNode, FIRSTAND);
|
217
|
+ NodeList firstOR = XPathAPI.selectNodeList(_queryNode, FIRSTOR);
|
218
|
+ NodeList firstCondition = XPathAPI.selectNodeList(_queryNode, FIRSTCONDITION);
|
219
|
int andLength = firstAND.getLength();
|
220
|
int orLength = firstOR.getLength();
|
221
|
int conLength = firstCondition.getLength();
|
222
|
@@ -222,7 +265,7 @@
|
223
|
//first is and
|
224
|
ANDType and = new ANDType();
|
225
|
handleANDType(and, firstAND.item(0));
|
226
|
- ecogridQuery.setAND(and);
|
227
|
+ _ecogridQuery.setAND(and);
|
228
|
|
229
|
}
|
230
|
else if (orLength != 0 && andLength ==0 && conLength == 0)
|
231
|
@@ -230,13 +273,13 @@
|
232
|
// first is or
|
233
|
ORType or = new ORType();
|
234
|
handleORType(or, firstOR.item(0));
|
235
|
- ecogridQuery.setOR(or);
|
236
|
+ _ecogridQuery.setOR(or);
|
237
|
}
|
238
|
else if (conLength != 0 &&orLength == 0 && andLength == 0 )
|
239
|
{
|
240
|
// first is condition
|
241
|
ConditionType condition = handleConditionType(firstCondition.item(0));
|
242
|
- ecogridQuery.setCondition(condition);
|
243
|
+ _ecogridQuery.setCondition(condition);
|
244
|
}
|
245
|
else
|
246
|
{
|
247
|
Index: src/org/ecoinformatics/ecogrid/EcogridQueryTransformer.java
|
248
|
===================================================================
|
249
|
RCS file: /cvs/seek/projects/ecogrid/src/org/ecoinformatics/ecogrid/EcogridQueryTransformer.java,v
|
250
|
retrieving revision 1.3
|
251
|
diff -u -r1.3 EcogridQueryTransformer.java
|
252
|
--- src/org/ecoinformatics/ecogrid/EcogridQueryTransformer.java 11 Oct 2004 19:34:59 -0000 1.3
|
253
|
+++ src/org/ecoinformatics/ecogrid/EcogridQueryTransformer.java 9 Dec 2004 21:02:26 -0000
|
254
|
@@ -202,7 +202,7 @@
|
255
|
{
|
256
|
for (int i = 0; i < returnfields.length; i++)
|
257
|
{
|
258
|
- strBuf.append(" <returnfield>" + returnfields[i] + "</returnfield>\n");
|
259
|
+ strBuf.append(" <returnField>" + returnfields[i] + "</returnField>\n");
|
260
|
}
|
261
|
}
|
262
|
|