0
|
1 |
"{ Package: 'stx:goodies/xmlsuite/xquery' }"
|
|
2 |
|
|
3 |
"{ NameSpace: XQuery }"
|
|
4 |
|
|
5 |
Object subclass:#XQueryExecutor
|
|
6 |
instanceVariableNames:'astTree documentProvider documentAdaptorsPool interpreter'
|
|
7 |
classVariableNames:''
|
|
8 |
poolDictionaries:''
|
|
9 |
category:'XQuery-Executor'
|
|
10 |
!
|
|
11 |
|
|
12 |
|
|
13 |
!XQueryExecutor class methodsFor:'instance creation'!
|
|
14 |
|
|
15 |
new
|
|
16 |
^ self basicNew initialize.
|
|
17 |
|
|
18 |
"Created: / 29-08-2007 / 09:39:50 / janfrog"
|
|
19 |
! !
|
|
20 |
|
|
21 |
!XQueryExecutor class methodsFor:'defaults'!
|
|
22 |
|
|
23 |
defaultDocumentProvider
|
|
24 |
"default value for the 'documentProvider' instance variable (automatically generated)"
|
|
25 |
|
|
26 |
^XMLv2::XPathDocumentProvider default.
|
|
27 |
|
|
28 |
"Created: / 19-10-2006 / 23:12:33 / ked"
|
|
29 |
"Modified: / 02-12-2006 / 12:00:09 / ked"
|
|
30 |
"Modified: / 05-12-2006 / 14:59:22 / janfrog"
|
|
31 |
! !
|
|
32 |
|
|
33 |
!XQueryExecutor methodsFor:'accessing'!
|
|
34 |
|
|
35 |
astTree
|
|
36 |
^ astTree
|
|
37 |
|
|
38 |
"Created: / 31-03-2006 / 17:34:36 / ked"
|
|
39 |
!
|
|
40 |
|
|
41 |
astTree:something
|
|
42 |
astTree := something.
|
|
43 |
|
|
44 |
"Created: / 31-03-2006 / 17:34:36 / ked"
|
|
45 |
!
|
|
46 |
|
|
47 |
documentProvider
|
|
48 |
documentProvider isNil ifTrue:[documentProvider := self class defaultDocumentProvider].
|
|
49 |
^ documentProvider
|
|
50 |
|
|
51 |
"Created: / 19-10-2006 / 23:12:33 / ked"
|
|
52 |
"Modified: / 10-12-2006 / 13:30:28 / janfrog"
|
|
53 |
!
|
|
54 |
|
|
55 |
documentProvider:aDocumentProvider
|
|
56 |
|
|
57 |
<resource: #obsolete>
|
|
58 |
self obsoleteMethodWarning.
|
|
59 |
|
|
60 |
self setDocumentProvider: aDocumentProvider
|
|
61 |
|
|
62 |
"Created: / 19-10-2006 / 23:12:33 / ked"
|
|
63 |
"Modified: / 10-12-2006 / 13:28:58 / janfrog"
|
|
64 |
!
|
|
65 |
|
|
66 |
xqueryInterpreterClass
|
|
67 |
^ XQueryInterpreter
|
|
68 |
|
|
69 |
"Created: / 14-11-2007 / 11:25:27 / janfrog"
|
|
70 |
! !
|
|
71 |
|
|
72 |
!XQueryExecutor methodsFor:'accessing - document'!
|
|
73 |
|
|
74 |
documentAdaptorsFor: aURI
|
|
75 |
|
|
76 |
documentAdaptorsPool ifNil:[
|
|
77 |
documentAdaptorsPool := Dictionary new.
|
|
78 |
].
|
|
79 |
|
|
80 |
^documentAdaptorsPool at: aURI ifAbsentPut:[
|
|
81 |
|
|
82 |
(self documentProvider documentAdaptorsFor: aURI)
|
|
83 |
].
|
|
84 |
|
|
85 |
"Modified: / 02-12-2006 / 11:59:45 / ked"
|
|
86 |
"Created: / 20-09-2007 / 10:34:10 / janfrog"
|
|
87 |
!
|
|
88 |
|
|
89 |
releaseDocumentAdaptors
|
|
90 |
documentAdaptorsPool ifNotNil:[
|
|
91 |
documentAdaptorsPool do:[:documentAdaptor |
|
|
92 |
documentAdaptor releaseResources.
|
|
93 |
].
|
|
94 |
documentAdaptorsPool := nil.
|
|
95 |
].
|
|
96 |
|
|
97 |
"Created: / 25-10-2006 / 09:24:43 / ked"
|
|
98 |
"Modified: / 02-11-2006 / 10:28:44 / ked"
|
|
99 |
! !
|
|
100 |
|
|
101 |
!XQueryExecutor methodsFor:'evaluation'!
|
|
102 |
|
|
103 |
evaluate: aString
|
|
104 |
|
|
105 |
"Provided for compatibility with @class XMLv2::XPathProcessor"
|
|
106 |
|
|
107 |
^self executeQuery: aString
|
|
108 |
|
|
109 |
"Created: / 10-12-2006 / 13:32:17 / janfrog"
|
|
110 |
! !
|
|
111 |
|
|
112 |
!XQueryExecutor methodsFor:'initialization'!
|
|
113 |
|
|
114 |
initialize
|
|
115 |
"Invoked when a new instance is created."
|
|
116 |
"/ please change as required (and remove this comment)
|
|
117 |
"/ astTree := nil.
|
|
118 |
"/ documentProvider := nil.
|
|
119 |
"/ documentAdaptorsPool := nil.
|
|
120 |
"/ super initialize. -- commented since inherited method does nothing
|
|
121 |
|
|
122 |
interpreter := self xqueryInterpreterClass new
|
|
123 |
|
|
124 |
"Created: / 29-08-2007 / 09:39:50 / janfrog"
|
|
125 |
"Modified: / 14-11-2007 / 11:25:27 / janfrog"
|
|
126 |
!
|
|
127 |
|
|
128 |
setDocumentAdaptor: aDocumentAdaptor
|
|
129 |
|
|
130 |
"Ignored. Provided fr compatilibility with @class XPathProcessor"
|
|
131 |
|
|
132 |
"Created: / 10-12-2006 / 13:30:13 / janfrog"
|
|
133 |
!
|
|
134 |
|
|
135 |
setDocumentProvider: aDocumentProvider
|
|
136 |
|
|
137 |
documentProvider := aDocumentProvider
|
|
138 |
|
|
139 |
"Created: / 10-12-2006 / 13:29:28 / janfrog"
|
|
140 |
! !
|
|
141 |
|
|
142 |
!XQueryExecutor methodsFor:'libraries'!
|
|
143 |
|
|
144 |
loadFunctionLibrary: aFunctionLibrary
|
|
145 |
|
|
146 |
interpreter loadFunctionLibrary: aFunctionLibrary
|
|
147 |
|
|
148 |
"Created: / 29-08-2007 / 09:39:23 / janfrog"
|
|
149 |
! !
|
|
150 |
|
|
151 |
!XQueryExecutor methodsFor:'queries'!
|
|
152 |
|
|
153 |
executeQuery: queryString
|
|
154 |
|
|
155 |
|millisecondsToRun resultSequence|
|
|
156 |
|
|
157 |
millisecondsToRun := Time millisecondsToRun:
|
|
158 |
[resultSequence := self primExecuteQuery: queryString].
|
|
159 |
|
|
160 |
^(XQueryResult withAll:resultSequence)
|
|
161 |
setQueryString: queryString;
|
|
162 |
setQueryTime:
|
|
163 |
(millisecondsToRun > 0
|
|
164 |
ifTrue:[TimeDuration new setMilliseconds: millisecondsToRun]
|
|
165 |
ifFalse:[nil]);
|
|
166 |
yourself.
|
|
167 |
|
|
168 |
"Created: / 31-03-2006 / 17:48:31 / ked"
|
|
169 |
"Modified: / 03-12-2006 / 22:01:11 / ked"
|
|
170 |
"Modified: / 21-11-2007 / 15:51:00 / janfrog"
|
|
171 |
!
|
|
172 |
|
|
173 |
primExecuteQuery:queryString
|
|
174 |
|result|
|
|
175 |
|
|
176 |
Object errorSignal
|
|
177 |
handle:[:ex | XQueryParserError raiseErrorString:ex messageText. ]
|
|
178 |
do:[ astTree := XQueryParser parseQuery:queryString. ].
|
|
179 |
Object errorSignal
|
|
180 |
handle:[:ex | XQueryInterpreterError raiseErrorString:ex messageText. ]
|
|
181 |
do:[ result := interpreter evaluateNode:self ].
|
|
182 |
^ result
|
|
183 |
|
|
184 |
"Modified: / 03-12-2006 / 22:01:11 / ked"
|
|
185 |
"Created: / 24-12-2006 / 13:53:35 / janfrog"
|
|
186 |
"Modified: / 21-11-2007 / 15:41:07 / janfrog"
|
|
187 |
! !
|
|
188 |
|
|
189 |
!XQueryExecutor class methodsFor:'documentation'!
|
|
190 |
|
|
191 |
version
|
|
192 |
^ '$Header: /opt/data/cvs/stx/goodies/xmlsuite/xquery/XQuery__XQueryExecutor.st,v 1.7 2007-11-22 21:56:49 vranyj1 Exp $'
|
|
193 |
! !
|