Project

Profile

Help

How to connect?
Download (8.79 KB) Statistics
| Branch: | Tag: | Revision:

he / tags / 9.8.0.14 / hec / Saxon.C.API / XQueryProcessor.h @ 02f8308b

1
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright (c) 2013 Saxonica Limited.
3
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
4
// If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
5
// This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0.
6
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
7

    
8
#ifndef SAXON_XQUERY_H
9
#define SAXON_XQUERY_H
10

    
11

    
12

    
13
#include "SaxonProcessor.h"
14
//#include "XdmValue.h"
15
#include <string>
16

    
17

    
18

    
19
class SaxonProcessor;
20
class XdmValue;
21
class XdmItem;
22

    
23
/*! An <code>XQueryProcessor</code> represents factory to compile, load and execute the query.
24
 * <p/>
25
 */
26
class XQueryProcessor {
27
public:
28

    
29
    //! Default constructor.
30
    XQueryProcessor();
31

    
32
    //! Constructor with the SaxonProcessor supplied.
33
    /*!
34
     * @param SaxonProcessor - Supplied pointer to the SaxonProcessor object
35
     * @param cwd - set the current working directory. Default is the empty string
36
    */
37
    XQueryProcessor(SaxonProcessor *p, std::string cwd="");
38

    
39
    ~XQueryProcessor(){
40
        clearProperties();
41
        clearParameters();
42
    }
43

    
44
    //!Set the initial context item for the query
45
    /**
46
      @param value - the initial context item, or null if there is to be no initial context item
47
    */
48
    void setContextItem(XdmItem * value);
49

    
50
    /**
51
     * Set the output file where the result is sent
52
    */
53
    void setOutputFile(const char* outfile);
54

    
55
    /**
56
     * Set the source from file for the query.
57
    */
58
    void setContextItemFromFile(const char * filename); 
59

    
60
    /**
61
     * Set a parameter value used in the query
62
     *s
63
     * @param name  of the parameter, as a string. For namespaced parameter use the JAXP solution i.e. "{uri}name"
64
     * @param value of the query parameter, or null to clear a previously set value
65
     */
66
    void setParameter(const char * name, XdmValue*value);
67

    
68

    
69
    /**
70
     * Remove a parameter (name, value) pair
71
     *
72
     * @param namespacei currently not used
73
     * @param name  of the parameter
74
     * @return bool - outcome of the romoval
75
     */
76
    bool removeParameter(const char * name);
77

    
78
    /**
79
     * Set a property specific to the processor in use. 
80
     * XQueryProcessor: set serialization properties (names start with '!' i.e. name "!method" -> "xml")
81
     * 'o':outfile name, 's': source as file name
82
     * 'q': query file name, 'q': current by name, 'qs': string form of the query, 'base': set the base URI of the query, 'dtd': set DTD validation 'on' or 'off'
83
     * @param name of the property
84
     * @param value of the property
85
     */
86
    void setProperty(const char * name, const char * value);
87

    
88
    /**
89
     * Clear parameter values set
90
     *  @param deleteValues.  Individual pointers to XdmValue objects have to be deleted in the calling program
91
     * Default behaviour (false) is to leave XdmValues in memory
92
     *  true then XdmValues are deleted
93
     */
94
    void clearParameters(bool deleteValues=false);
95

    
96
    /**
97
     * Clear property values set
98
     */
99
    void clearProperties();
100

    
101

    
102
    //!Perform the Query to file.
103
    /**
104
     * The result is is saved to file
105
     *
106
     * @param infilename - The file name of the source document
107
     * @param ofilename - The file name of where result will be stored
108
     * @param query - The query as string representation. TODO check
109
     */
110
    void executeQueryToFile(const char * infilename, const char * ofilename, const char * query);
111

    
112
     //!Perform the Query to a XdmValue representation.
113
    /**
114
     * @param infilename - The file name of the source document
115
     * @param ofilename - The file name of where result will be stored
116
     * @param query - The query as string representation
117
     * @return XdmValue - result of the the query as a XdmValue 
118
     */
119
    XdmValue * executeQueryToValue(const char * infilename, const char * query);
120

    
121

    
122
    //!Perform the Query to a string representation.
123
    /**
124
     * @param infilename - The file name of the source document
125
     * @param query - The query as string representation
126
     * @return char array - result of as a string
127
     */
128
    const char * executeQueryToString(const char * infilename, const char * query);
129

    
130
    //!Execute the Query cached.
131
    /** 
132
     * The use of the context item would have had to be set in advance
133
     * @return XdmValue of the result
134
     *
135
     */
136
    XdmValue * runQueryToValue();
137

    
138
    /**
139
     * Execute the Query cached.
140
     * The use of the context item would have had to be set in advance
141
     * @return Result as a string (i.e. pointer array of char)
142
     *
143
     */
144
    const char * runQueryToString();
145

    
146

    
147
    //!Execute the Query cached to file.
148
    /**
149
     * The use of the context item would have had to be set in advance
150
     * Assume the output filename has been set in advance
151
     * @return Result as a string (i.e. pointer array of char)
152
     *
153
     */
154
    void runQueryToFile();
155

    
156
     //!Declare a namespace binding.
157
     /**
158
     * Declare a namespace binding as part of the static context for queries compiled using this
159
     * XQueryCompiler. This binding may be overridden by a binding that appears in the query prolog.
160
     * The namespace binding will form part of the static context of the query, but it will not be copied
161
     * into result trees unless the prefix is actually used in an element or attribute name.
162
     *
163
     * @param prefix The namespace prefix. If the value is a zero-length string, this method sets the default
164
     *               namespace for elements and types.
165
     * @param uri    The namespace URI. It is possible to specify a zero-length string to "undeclare" a namespace;
166
     *               in this case the prefix will not be available for use, except in the case where the prefix
167
     *               is also a zero length string, in which case the absence of a prefix implies that the name
168
     *               is in no namespace.
169
     * Assume the prefix or uri is null.
170
     */
171
    void declareNamespace(const char *prefix, const char * uri);
172

    
173

    
174
     //!Get all parameters as a std::map
175
     /**
176
      * @return std::map  - map of the parameters string->XdmValue* 
177
     */
178
     std::map<std::string,XdmValue*>& getParameters();
179

    
180
      //!Get all properties as a std::map
181
     /**
182
      * @return std::map map of the properties string->string 
183
     */
184
     std::map<std::string,std::string>& getProperties();
185

    
186
     //!Compile a query supplied as by file name.
187
    /**
188
     * The supplied query is cached for later execution.
189
     */
190
    void setQueryFile(const char* filename);
191

    
192
     //!Compile a query supplied as a string.
193
    /**
194
     * The supplied query is cached for later execution.
195
     */
196
    void setQueryContent(const char* content);
197

    
198
     //!Set the static base URI for the query
199
     /**
200
     * @param baseURI the static base URI; or null to indicate that no base URI is available
201
     */
202
    void setQueryBaseURI(const char * baseURI);
203

    
204
    /**
205
     * set the current working directory
206
    */
207
   void setcwd(const char* cwd);
208

    
209

    
210
     //! Check for exception thrown.
211
   /**
212
    * @return char*. Returns the main exception message if thrown otherwise return NULL
213
    */
214
    const char* checkException();
215

    
216
    /**
217
     * Checks for pending exceptions without creating a local reference to the exception object
218
     * @return bool - true when there is a pending exception; otherwise return false
219
    */
220
    bool exceptionOccurred();
221

    
222
    //! Clear any exception thrown
223
    void exceptionClear();
224

    
225
     //!Get number of errors reported during execution of the query
226
    /**
227
     * A transformation may have a number of errors reported against it.
228
     * @return int - Count of the exceptions recorded against the transformation
229
    */
230
    int exceptionCount();
231

    
232

    
233
     //! Get the ith error message if there are any error
234
    /**
235
     * A transformation may have a number of errors reported against it.
236
     * @return char* - The message of the i'th exception 
237
    */
238
    const char * getErrorMessage(int i);
239

    
240

    
241
     //! Get the i'th error code if there are any error
242
    /**
243
     * After the execution of the query there may be a number of errors reported against it.
244
     * @return char* - The error code of the i'th exception.
245
    */
246
    const char * getErrorCode(int i);
247
    
248

    
249
private:
250
        std::string cwdXQ; /*!< current working directory */
251
        SaxonProcessor * proc;
252
        jclass  cppClass;
253
        jobject cppXQ;
254
        //std::string outputfile1; /*!< output file where result will be saved */
255
        bool queryFileExists;
256
        std::string failure; //for testing
257
        std::map<std::string,XdmValue*> parameters; /*!< map of parameters used for the transformation as (string, value) pairs */
258
        std::map<std::string,std::string> properties; /*!< map of properties used for the transformation as (string, string) pairs */
259
};
260

    
261
#endif /* SAXON_XQUERY_H */
(20-20/45)