source: trunk/VUT/GtpVisibilityPreprocessor/support/xerces/include/xercesc/validators/schema/identity/XercesXPath.hpp @ 358

Revision 358, 19.8 KB checked in by bittner, 19 years ago (diff)

xerces added

RevLine 
[358]1/*
2 * Copyright 2001-2004 The Apache Software Foundation.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17/*
18 * $Id: XercesXPath.hpp,v 1.9 2004/09/08 13:57:00 peiyongz Exp $
19 */
20
21#if !defined(XERCESXPATH_HPP)
22#define XERCESXPATH_HPP
23
24
25// ---------------------------------------------------------------------------
26//  Includes
27// ---------------------------------------------------------------------------
28#include <xercesc/util/QName.hpp>
29#include <xercesc/util/RefVectorOf.hpp>
30#include <xercesc/util/ValueVectorOf.hpp>
31
32#include <xercesc/internal/XSerializable.hpp>
33
34XERCES_CPP_NAMESPACE_BEGIN
35
36// ---------------------------------------------------------------------------
37//  Forward Declarations
38// ---------------------------------------------------------------------------
39class XMLStringPool;
40class NamespaceScope;
41
42
43class VALIDATORS_EXPORT XercesNodeTest : public XSerializable, public XMemory
44{
45public:
46    // -----------------------------------------------------------------------
47    //  Constants
48    // -----------------------------------------------------------------------
49    enum {
50        QNAME = 1,
51        WILDCARD = 2,
52        NODE = 3,
53        NAMESPACE= 4,
54        UNKNOWN
55    };
56
57    // -----------------------------------------------------------------------
58    //  Constructors/Destructor
59    // -----------------------------------------------------------------------
60    XercesNodeTest(const short type,
61                   MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
62    XercesNodeTest(const QName* const qName);
63    XercesNodeTest(const XMLCh* const prefix, const unsigned int uriId,
64                   MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
65    XercesNodeTest(const XercesNodeTest& other);
66    ~XercesNodeTest() { delete fName; }
67
68    // -----------------------------------------------------------------------
69    //  Operators
70    // -----------------------------------------------------------------------
71    XercesNodeTest& operator= (const XercesNodeTest& other);
72    bool operator== (const XercesNodeTest& other) const;
73    bool operator!= (const XercesNodeTest& other) const;
74
75        // -----------------------------------------------------------------------
76    //  Getter methods
77    // -----------------------------------------------------------------------
78    short getType() const { return fType; }
79    QName* getName() const { return fName; }
80
81    /***
82     * Support for Serialization/De-serialization
83     ***/
84    DECL_XSERIALIZABLE(XercesNodeTest)
85
86    XercesNodeTest(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
87
88private:
89    // -----------------------------------------------------------------------
90    //  Data members
91    // -----------------------------------------------------------------------
92    short  fType;
93    QName* fName;
94};
95
96
97/**
98  * A location path step comprised of an axis and node test.
99  */
100class VALIDATORS_EXPORT XercesStep : public XSerializable, public XMemory
101{
102public:
103    // -----------------------------------------------------------------------
104    //  Constants
105    // -----------------------------------------------------------------------
106    enum { // Axis type
107        CHILD = 1,
108        ATTRIBUTE = 2,
109        SELF = 3,
110        DESCENDANT = 4,
111        UNKNOWN
112    };
113
114    // -----------------------------------------------------------------------
115    //  Constructors/Destructor
116    // -----------------------------------------------------------------------
117    XercesStep(const unsigned short axisType, XercesNodeTest* const nodeTest);
118    XercesStep(const XercesStep& other);
119    ~XercesStep() { delete fNodeTest; }
120
121    // -----------------------------------------------------------------------
122    //  Operators
123    // -----------------------------------------------------------------------
124    XercesStep& operator= (const XercesStep& other);
125    bool operator== (const XercesStep& other) const;
126    bool operator!= (const XercesStep& other) const;
127
128        // -----------------------------------------------------------------------
129    //  Getter methods
130    // -----------------------------------------------------------------------
131    unsigned short getAxisType() const { return fAxisType; }
132    XercesNodeTest* getNodeTest() const { return fNodeTest; }
133
134    /***
135     * Support for Serialization/De-serialization
136     ***/
137    DECL_XSERIALIZABLE(XercesStep)
138
139    XercesStep(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
140
141private:
142    // -----------------------------------------------------------------------
143    //  Data members
144    // -----------------------------------------------------------------------
145    unsigned short  fAxisType;
146    XercesNodeTest* fNodeTest;
147};
148
149
150/**
151  * A location path representation for an XPath expression.
152  */
153class VALIDATORS_EXPORT XercesLocationPath : public XSerializable, public XMemory
154{
155public:
156    // -----------------------------------------------------------------------
157    //  Constructors/Destructor
158    // -----------------------------------------------------------------------
159    XercesLocationPath(RefVectorOf<XercesStep>* const steps);
160    ~XercesLocationPath() { delete fSteps; }
161
162    // -----------------------------------------------------------------------
163    //  Operators
164    // -----------------------------------------------------------------------
165    bool operator== (const XercesLocationPath& other) const;
166    bool operator!= (const XercesLocationPath& other) const;
167
168    // -----------------------------------------------------------------------
169    //  Access methods
170    // -----------------------------------------------------------------------
171    unsigned int getStepSize() const;
172    void addStep(XercesStep* const aStep);
173    XercesStep* getStep(const unsigned int index) const;
174
175    /***
176     * Support for Serialization/De-serialization
177     ***/
178    DECL_XSERIALIZABLE(XercesLocationPath)
179
180    XercesLocationPath(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
181
182private:
183    // -----------------------------------------------------------------------
184    //  Unimplemented contstructors and operators
185    // -----------------------------------------------------------------------
186    XercesLocationPath(const XercesLocationPath& other);
187    XercesLocationPath& operator= (const XercesLocationPath& other);
188
189    // -----------------------------------------------------------------------
190    //  Data members
191    // -----------------------------------------------------------------------
192    RefVectorOf<XercesStep>* fSteps;
193};
194
195
196class VALIDATORS_EXPORT XercesXPath : public XSerializable, public XMemory
197{
198public:
199    // -----------------------------------------------------------------------
200    //  Constants
201    // -----------------------------------------------------------------------
202    /**
203      * [28] ExprToken ::= '(' | ')' | '[' | ']' | '.' | '..' | '@' | ',' | '::'
204      *                  | NameTest | NodeType | Operator | FunctionName
205      *                  | AxisName | Literal | Number | VariableReference
206      */
207    enum {
208        EXPRTOKEN_OPEN_PAREN                  =  0,
209        EXPRTOKEN_CLOSE_PAREN                 =  1,
210        EXPRTOKEN_OPEN_BRACKET                =  2,
211        EXPRTOKEN_CLOSE_BRACKET               =  3,
212        EXPRTOKEN_PERIOD                      =  4,
213        EXPRTOKEN_DOUBLE_PERIOD               =  5,
214        EXPRTOKEN_ATSIGN                      =  6,
215        EXPRTOKEN_COMMA                       =  7,
216        EXPRTOKEN_DOUBLE_COLON                =  8,
217        EXPRTOKEN_NAMETEST_ANY                =  9,
218        EXPRTOKEN_NAMETEST_NAMESPACE          = 10,
219        EXPRTOKEN_NAMETEST_QNAME              = 11,
220        EXPRTOKEN_NODETYPE_COMMENT            = 12,
221        EXPRTOKEN_NODETYPE_TEXT               = 13,
222        EXPRTOKEN_NODETYPE_PI                 = 14,
223        EXPRTOKEN_NODETYPE_NODE               = 15,
224        EXPRTOKEN_OPERATOR_AND                = 16,
225        EXPRTOKEN_OPERATOR_OR                 = 17,
226        EXPRTOKEN_OPERATOR_MOD                = 18,
227        EXPRTOKEN_OPERATOR_DIV                = 19,
228        EXPRTOKEN_OPERATOR_MULT               = 20,
229        EXPRTOKEN_OPERATOR_SLASH              = 21,
230        EXPRTOKEN_OPERATOR_DOUBLE_SLASH       = 22,
231        EXPRTOKEN_OPERATOR_UNION              = 23,
232        EXPRTOKEN_OPERATOR_PLUS               = 24,
233        EXPRTOKEN_OPERATOR_MINUS              = 25,
234        EXPRTOKEN_OPERATOR_EQUAL              = 26,
235        EXPRTOKEN_OPERATOR_NOT_EQUAL          = 27,
236        EXPRTOKEN_OPERATOR_LESS               = 28,
237        EXPRTOKEN_OPERATOR_LESS_EQUAL         = 29,
238        EXPRTOKEN_OPERATOR_GREATER            = 30,
239        EXPRTOKEN_OPERATOR_GREATER_EQUAL      = 31,
240        EXPRTOKEN_FUNCTION_NAME               = 32,
241        EXPRTOKEN_AXISNAME_ANCESTOR           = 33,
242        EXPRTOKEN_AXISNAME_ANCESTOR_OR_SELF   = 34,
243        EXPRTOKEN_AXISNAME_ATTRIBUTE          = 35,
244        EXPRTOKEN_AXISNAME_CHILD              = 36,
245        EXPRTOKEN_AXISNAME_DESCENDANT         = 37,
246        EXPRTOKEN_AXISNAME_DESCENDANT_OR_SELF = 38,
247        EXPRTOKEN_AXISNAME_FOLLOWING          = 39,
248        EXPRTOKEN_AXISNAME_FOLLOWING_SIBLING  = 40,
249        EXPRTOKEN_AXISNAME_NAMESPACE          = 41,
250        EXPRTOKEN_AXISNAME_PARENT             = 42,
251        EXPRTOKEN_AXISNAME_PRECEDING          = 43,
252        EXPRTOKEN_AXISNAME_PRECEDING_SIBLING  = 44,
253        EXPRTOKEN_AXISNAME_SELF               = 45,
254        EXPRTOKEN_LITERAL                     = 46,
255        EXPRTOKEN_NUMBER                      = 47,
256        EXPRTOKEN_VARIABLE_REFERENCE          = 48
257    };
258
259    // -----------------------------------------------------------------------
260    //  Constructors/Destructor
261    // -----------------------------------------------------------------------
262    XercesXPath(const XMLCh* const xpathExpr,
263                XMLStringPool* const stringPool,
264                NamespaceScope* const scopeContext,
265                const unsigned int emptyNamespaceId,
266                const bool isSelector = false,
267                MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
268        ~XercesXPath();
269
270    // -----------------------------------------------------------------------
271    //  Operators
272    // -----------------------------------------------------------------------
273    bool operator== (const XercesXPath& other) const;
274    bool operator!= (const XercesXPath& other) const;
275
276    // -----------------------------------------------------------------------
277    //  Constructors/Destructor
278    // -----------------------------------------------------------------------
279    RefVectorOf<XercesLocationPath>* getLocationPaths() const;
280
281    /***
282     * Support for Serialization/De-serialization
283     ***/
284    DECL_XSERIALIZABLE(XercesXPath)
285
286    XercesXPath(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
287
288    XMLCh* getExpression();
289
290private:
291    // -----------------------------------------------------------------------
292    //  Unimplemented contstructors and operators
293    // -----------------------------------------------------------------------
294    XercesXPath(const XercesXPath& other);
295    XercesXPath& operator= (const XercesXPath& other);
296
297    // -----------------------------------------------------------------------
298    //  Helper methods
299    // -----------------------------------------------------------------------
300    void cleanUp();
301    void checkForSelectedAttributes();
302    void parseExpression(XMLStringPool* const stringPool,
303                         NamespaceScope* const scopeContext);
304
305    // -----------------------------------------------------------------------
306    //  Data members
307    // -----------------------------------------------------------------------
308    unsigned int                     fEmptyNamespaceId;
309    XMLCh*                           fExpression;
310    RefVectorOf<XercesLocationPath>* fLocationPaths;
311    MemoryManager*                   fMemoryManager;
312};
313
314
315class VALIDATORS_EXPORT XPathScanner : public XMemory
316{
317public:
318    // -----------------------------------------------------------------------
319    //  Constants
320    // -----------------------------------------------------------------------
321    enum {
322        CHARTYPE_INVALID            =  0,   // invalid XML character
323        CHARTYPE_OTHER              =  1,   // not special - one of "#%&;?\^`{}~" or DEL
324        CHARTYPE_WHITESPACE         =  2,   // one of "\t\n\r " (0x09, 0x0A, 0x0D, 0x20)
325        CHARTYPE_EXCLAMATION        =  3,   // '!' (0x21)
326        CHARTYPE_QUOTE              =  4,   // '\"' or '\'' (0x22 and 0x27)
327        CHARTYPE_DOLLAR             =  5,   // '$' (0x24)
328        CHARTYPE_OPEN_PAREN         =  6,   // '(' (0x28)
329        CHARTYPE_CLOSE_PAREN        =  7,   // ')' (0x29)
330        CHARTYPE_STAR               =  8,   // '*' (0x2A)
331        CHARTYPE_PLUS               =  9,   // '+' (0x2B)
332        CHARTYPE_COMMA              = 10,   // ',' (0x2C)
333        CHARTYPE_MINUS              = 11,   // '-' (0x2D)
334        CHARTYPE_PERIOD             = 12,   // '.' (0x2E)
335        CHARTYPE_SLASH              = 13,   // '/' (0x2F)
336        CHARTYPE_DIGIT              = 14,   // '0'-'9' (0x30 to 0x39)
337        CHARTYPE_COLON              = 15,   // ':' (0x3A)
338        CHARTYPE_LESS               = 16,   // '<' (0x3C)
339        CHARTYPE_EQUAL              = 17,   // '=' (0x3D)
340        CHARTYPE_GREATER            = 18,   // '>' (0x3E)
341        CHARTYPE_ATSIGN             = 19,   // '@' (0x40)
342        CHARTYPE_LETTER             = 20,   // 'A'-'Z' or 'a'-'z' (0x41 to 0x5A and 0x61 to 0x7A)
343        CHARTYPE_OPEN_BRACKET       = 21,   // '[' (0x5B)
344        CHARTYPE_CLOSE_BRACKET      = 22,   // ']' (0x5D)
345        CHARTYPE_UNDERSCORE         = 23,   // '_' (0x5F)
346        CHARTYPE_UNION              = 24,   // '|' (0x7C)
347        CHARTYPE_NONASCII           = 25   // Non-ASCII Unicode codepoint (>= 0x80)
348    };
349
350    // -----------------------------------------------------------------------
351    //  Constructors/Destructor
352    // -----------------------------------------------------------------------
353    XPathScanner(XMLStringPool* const stringPool);
354    virtual ~XPathScanner() {}
355
356    // -----------------------------------------------------------------------
357    //  Scan methods
358    // -----------------------------------------------------------------------
359    bool scanExpression(const XMLCh* const data, int currentOffset,
360                        const int endOffset, ValueVectorOf<int>* const tokens);
361
362protected:
363    // -----------------------------------------------------------------------
364    //  Helper methods
365    // -----------------------------------------------------------------------
366    /**
367      * This method adds the specified token to the token list. By default,
368      * this method allows all tokens. However, subclasses can can override
369      * this method in order to disallow certain tokens from being used in the
370      * scanned XPath expression. This is a convenient way of allowing only
371      * a subset of XPath.
372      */
373    virtual void addToken(ValueVectorOf<int>* const tokens, const int aToken);
374
375private:
376    // -----------------------------------------------------------------------
377    //  Unimplemented contstructors and operators
378    // -----------------------------------------------------------------------
379    XPathScanner(const XPathScanner& other);
380    XPathScanner& operator= (const XPathScanner& other);
381
382    // -----------------------------------------------------------------------
383    //  Helper methods
384    // -----------------------------------------------------------------------
385    void init();
386
387    // -----------------------------------------------------------------------
388    //  Scan methods
389    // -----------------------------------------------------------------------
390    int scanNCName(const XMLCh* const data, const int endOffset,
391                   int currentOffset);
392    int scanNumber(const XMLCh* const data, const int endOffset,
393                   int currentOffset, ValueVectorOf<int>* const tokens);
394
395    // -----------------------------------------------------------------------
396    //  Data members
397    // -----------------------------------------------------------------------
398    int fAndSymbol;
399    int fOrSymbol;
400    int fModSymbol;
401    int fDivSymbol;
402    int fCommentSymbol;
403    int fTextSymbol;
404    int fPISymbol;
405    int fNodeSymbol;
406    int fAncestorSymbol;
407    int fAncestorOrSelfSymbol;
408    int fAttributeSymbol;
409    int fChildSymbol;
410    int fDescendantSymbol;
411    int fDescendantOrSelfSymbol;
412    int fFollowingSymbol;
413    int fFollowingSiblingSymbol;
414    int fNamespaceSymbol;
415    int fParentSymbol;
416    int fPrecedingSymbol;
417    int fPrecedingSiblingSymbol;
418    int fSelfSymbol;
419    XMLStringPool* fStringPool;
420
421    static const XMLByte fASCIICharMap[128];
422};
423
424
425class VALIDATORS_EXPORT XPathScannerForSchema: public XPathScanner
426{
427public:
428    // -----------------------------------------------------------------------
429    //  Constructors/Destructor
430    // -----------------------------------------------------------------------
431    XPathScannerForSchema(XMLStringPool* const stringPool);
432    ~XPathScannerForSchema() {}
433
434protected:
435    // -----------------------------------------------------------------------
436    //  Helper methods
437    // -----------------------------------------------------------------------
438    void addToken(ValueVectorOf<int>* const tokens, const int aToken);
439
440private:
441    // -----------------------------------------------------------------------
442    //  Unimplemented contstructors and operators
443    // -----------------------------------------------------------------------
444    XPathScannerForSchema(const XPathScannerForSchema& other);
445    XPathScannerForSchema& operator= (const XPathScannerForSchema& other);
446};
447
448// ---------------------------------------------------------------------------
449//  XercesLocationPath: Access methods
450// ---------------------------------------------------------------------------
451inline unsigned int XercesLocationPath::getStepSize() const {
452
453    if (fSteps)
454        return fSteps->size();
455
456    return 0;
457}
458
459inline void XercesLocationPath::addStep(XercesStep* const aStep) {
460
461    fSteps->addElement(aStep);
462}
463
464inline XercesStep* XercesLocationPath::getStep(const unsigned int index) const {
465
466    if (fSteps)
467        return fSteps->elementAt(index);
468
469    return 0;
470}
471
472// ---------------------------------------------------------------------------
473//  XercesScanner: Helper methods
474// ---------------------------------------------------------------------------
475inline void XPathScanner::addToken(ValueVectorOf<int>* const tokens,
476                                   const int aToken) {
477    tokens->addElement(aToken);
478}
479
480
481// ---------------------------------------------------------------------------
482//  XercesXPath: Getter methods
483// ---------------------------------------------------------------------------
484inline RefVectorOf<XercesLocationPath>* XercesXPath::getLocationPaths() const {
485
486    return fLocationPaths;
487}
488
489inline XMLCh* XercesXPath::getExpression() {
490    return fExpression;
491}
492
493XERCES_CPP_NAMESPACE_END
494
495#endif
496
497/**
498  * End of file XercesPath.hpp
499  */
500
Note: See TracBrowser for help on using the repository browser.