source: NonGTP/Xerces/xercesc/validators/schema/identity/XercesXPath.hpp @ 188

Revision 188, 21.9 KB checked in by mattausch, 19 years ago (diff)

added xercesc to support

Line 
1/*
2 * The Apache Software License, Version 1.1
3 *
4 * Copyright (c) 2001-2003 The Apache Software Foundation.  All rights
5 * reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * 1. Redistributions of source code must retain the above copyright
12 *    notice, this list of conditions and the following disclaimer.
13 *
14 * 2. Redistributions in binary form must reproduce the above copyright
15 *    notice, this list of conditions and the following disclaimer in
16 *    the documentation and/or other materials provided with the
17 *    distribution.
18 *
19 * 3. The end-user documentation included with the redistribution,
20 *    if any, must include the following acknowledgment:
21 *       "This product includes software developed by the
22 *        Apache Software Foundation (http://www.apache.org/)."
23 *    Alternately, this acknowledgment may appear in the software itself,
24 *    if and wherever such third-party acknowledgments normally appear.
25 *
26 * 4. The names "Xerces" and "Apache Software Foundation" must
27 *    not be used to endorse or promote products derived from this
28 *    software without prior written permission. For written
29 *    permission, please contact apache\@apache.org.
30 *
31 * 5. Products derived from this software may not be called "Apache",
32 *    nor may "Apache" appear in their name, without prior written
33 *    permission of the Apache Software Foundation.
34 *
35 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
36 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
37 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
38 * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
39 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
41 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
42 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
43 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
44 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
45 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
46 * SUCH DAMAGE.
47 * ====================================================================
48 *
49 * This software consists of voluntary contributions made by many
50 * individuals on behalf of the Apache Software Foundation, and was
51 * originally based on software copyright (c) 2001, International
52 * Business Machines, Inc., http://www.ibm.com .  For more information
53 * on the Apache Software Foundation, please see
54 * <http://www.apache.org/>.
55 */
56
57/*
58 * $Id: XercesXPath.hpp,v 1.8 2003/11/06 15:30:08 neilg Exp $
59 */
60
61#if !defined(XERCESXPATH_HPP)
62#define XERCESXPATH_HPP
63
64
65// ---------------------------------------------------------------------------
66//  Includes
67// ---------------------------------------------------------------------------
68#include <xercesc/util/QName.hpp>
69#include <xercesc/util/RefVectorOf.hpp>
70#include <xercesc/util/ValueVectorOf.hpp>
71
72#include <xercesc/internal/XSerializable.hpp>
73
74XERCES_CPP_NAMESPACE_BEGIN
75
76// ---------------------------------------------------------------------------
77//  Forward Declarations
78// ---------------------------------------------------------------------------
79class XMLStringPool;
80class NamespaceScope;
81
82
83class VALIDATORS_EXPORT XercesNodeTest : public XSerializable, public XMemory
84{
85public:
86    // -----------------------------------------------------------------------
87    //  Constants
88    // -----------------------------------------------------------------------
89    enum {
90        QNAME = 1,
91        WILDCARD = 2,
92        NODE = 3,
93        NAMESPACE= 4,
94        UNKNOWN
95    };
96
97    // -----------------------------------------------------------------------
98    //  Constructors/Destructor
99    // -----------------------------------------------------------------------
100    XercesNodeTest(const short type,
101                   MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
102    XercesNodeTest(const QName* const qName);
103    XercesNodeTest(const XMLCh* const prefix, const unsigned int uriId,
104                   MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
105    XercesNodeTest(const XercesNodeTest& other);
106    ~XercesNodeTest() { delete fName; }
107
108    // -----------------------------------------------------------------------
109    //  Operators
110    // -----------------------------------------------------------------------
111    XercesNodeTest& operator= (const XercesNodeTest& other);
112    bool operator== (const XercesNodeTest& other) const;
113    bool operator!= (const XercesNodeTest& other) const;
114
115        // -----------------------------------------------------------------------
116    //  Getter methods
117    // -----------------------------------------------------------------------
118    short getType() const { return fType; }
119    QName* getName() const { return fName; }
120
121    /***
122     * Support for Serialization/De-serialization
123     ***/
124    DECL_XSERIALIZABLE(XercesNodeTest)
125
126    XercesNodeTest(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
127
128private:
129    // -----------------------------------------------------------------------
130    //  Data members
131    // -----------------------------------------------------------------------
132    short  fType;
133    QName* fName;
134};
135
136
137/**
138  * A location path step comprised of an axis and node test.
139  */
140class VALIDATORS_EXPORT XercesStep : public XSerializable, public XMemory
141{
142public:
143    // -----------------------------------------------------------------------
144    //  Constants
145    // -----------------------------------------------------------------------
146    enum { // Axis type
147        CHILD = 1,
148        ATTRIBUTE = 2,
149        SELF = 3,
150        DESCENDANT = 4,
151        UNKNOWN
152    };
153
154    // -----------------------------------------------------------------------
155    //  Constructors/Destructor
156    // -----------------------------------------------------------------------
157    XercesStep(const unsigned short axisType, XercesNodeTest* const nodeTest);
158    XercesStep(const XercesStep& other);
159    ~XercesStep() { delete fNodeTest; }
160
161    // -----------------------------------------------------------------------
162    //  Operators
163    // -----------------------------------------------------------------------
164    XercesStep& operator= (const XercesStep& other);
165    bool operator== (const XercesStep& other) const;
166    bool operator!= (const XercesStep& other) const;
167
168        // -----------------------------------------------------------------------
169    //  Getter methods
170    // -----------------------------------------------------------------------
171    unsigned short getAxisType() const { return fAxisType; }
172    XercesNodeTest* getNodeTest() const { return fNodeTest; }
173
174    /***
175     * Support for Serialization/De-serialization
176     ***/
177    DECL_XSERIALIZABLE(XercesStep)
178
179    XercesStep(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
180
181private:
182    // -----------------------------------------------------------------------
183    //  Data members
184    // -----------------------------------------------------------------------
185    unsigned short  fAxisType;
186    XercesNodeTest* fNodeTest;
187};
188
189
190/**
191  * A location path representation for an XPath expression.
192  */
193class VALIDATORS_EXPORT XercesLocationPath : public XSerializable, public XMemory
194{
195public:
196    // -----------------------------------------------------------------------
197    //  Constructors/Destructor
198    // -----------------------------------------------------------------------
199    XercesLocationPath(RefVectorOf<XercesStep>* const steps);
200    ~XercesLocationPath() { delete fSteps; }
201
202    // -----------------------------------------------------------------------
203    //  Operators
204    // -----------------------------------------------------------------------
205    bool operator== (const XercesLocationPath& other) const;
206    bool operator!= (const XercesLocationPath& other) const;
207
208    // -----------------------------------------------------------------------
209    //  Access methods
210    // -----------------------------------------------------------------------
211    unsigned int getStepSize() const;
212    void addStep(XercesStep* const aStep);
213    XercesStep* getStep(const unsigned int index) const;
214
215    /***
216     * Support for Serialization/De-serialization
217     ***/
218    DECL_XSERIALIZABLE(XercesLocationPath)
219
220    XercesLocationPath(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
221
222private:
223    // -----------------------------------------------------------------------
224    //  Unimplemented contstructors and operators
225    // -----------------------------------------------------------------------
226    XercesLocationPath(const XercesLocationPath& other);
227    XercesLocationPath& operator= (const XercesLocationPath& other);
228
229    // -----------------------------------------------------------------------
230    //  Data members
231    // -----------------------------------------------------------------------
232    RefVectorOf<XercesStep>* fSteps;
233};
234
235
236class VALIDATORS_EXPORT XercesXPath : public XSerializable, public XMemory
237{
238public:
239    // -----------------------------------------------------------------------
240    //  Constants
241    // -----------------------------------------------------------------------
242    /**
243      * [28] ExprToken ::= '(' | ')' | '[' | ']' | '.' | '..' | '@' | ',' | '::'
244      *                  | NameTest | NodeType | Operator | FunctionName
245      *                  | AxisName | Literal | Number | VariableReference
246      */
247    enum {
248        EXPRTOKEN_OPEN_PAREN                  =  0,
249        EXPRTOKEN_CLOSE_PAREN                 =  1,
250        EXPRTOKEN_OPEN_BRACKET                =  2,
251        EXPRTOKEN_CLOSE_BRACKET               =  3,
252        EXPRTOKEN_PERIOD                      =  4,
253        EXPRTOKEN_DOUBLE_PERIOD               =  5,
254        EXPRTOKEN_ATSIGN                      =  6,
255        EXPRTOKEN_COMMA                       =  7,
256        EXPRTOKEN_DOUBLE_COLON                =  8,
257        EXPRTOKEN_NAMETEST_ANY                =  9,
258        EXPRTOKEN_NAMETEST_NAMESPACE          = 10,
259        EXPRTOKEN_NAMETEST_QNAME              = 11,
260        EXPRTOKEN_NODETYPE_COMMENT            = 12,
261        EXPRTOKEN_NODETYPE_TEXT               = 13,
262        EXPRTOKEN_NODETYPE_PI                 = 14,
263        EXPRTOKEN_NODETYPE_NODE               = 15,
264        EXPRTOKEN_OPERATOR_AND                = 16,
265        EXPRTOKEN_OPERATOR_OR                 = 17,
266        EXPRTOKEN_OPERATOR_MOD                = 18,
267        EXPRTOKEN_OPERATOR_DIV                = 19,
268        EXPRTOKEN_OPERATOR_MULT               = 20,
269        EXPRTOKEN_OPERATOR_SLASH              = 21,
270        EXPRTOKEN_OPERATOR_DOUBLE_SLASH       = 22,
271        EXPRTOKEN_OPERATOR_UNION              = 23,
272        EXPRTOKEN_OPERATOR_PLUS               = 24,
273        EXPRTOKEN_OPERATOR_MINUS              = 25,
274        EXPRTOKEN_OPERATOR_EQUAL              = 26,
275        EXPRTOKEN_OPERATOR_NOT_EQUAL          = 27,
276        EXPRTOKEN_OPERATOR_LESS               = 28,
277        EXPRTOKEN_OPERATOR_LESS_EQUAL         = 29,
278        EXPRTOKEN_OPERATOR_GREATER            = 30,
279        EXPRTOKEN_OPERATOR_GREATER_EQUAL      = 31,
280        EXPRTOKEN_FUNCTION_NAME               = 32,
281        EXPRTOKEN_AXISNAME_ANCESTOR           = 33,
282        EXPRTOKEN_AXISNAME_ANCESTOR_OR_SELF   = 34,
283        EXPRTOKEN_AXISNAME_ATTRIBUTE          = 35,
284        EXPRTOKEN_AXISNAME_CHILD              = 36,
285        EXPRTOKEN_AXISNAME_DESCENDANT         = 37,
286        EXPRTOKEN_AXISNAME_DESCENDANT_OR_SELF = 38,
287        EXPRTOKEN_AXISNAME_FOLLOWING          = 39,
288        EXPRTOKEN_AXISNAME_FOLLOWING_SIBLING  = 40,
289        EXPRTOKEN_AXISNAME_NAMESPACE          = 41,
290        EXPRTOKEN_AXISNAME_PARENT             = 42,
291        EXPRTOKEN_AXISNAME_PRECEDING          = 43,
292        EXPRTOKEN_AXISNAME_PRECEDING_SIBLING  = 44,
293        EXPRTOKEN_AXISNAME_SELF               = 45,
294        EXPRTOKEN_LITERAL                     = 46,
295        EXPRTOKEN_NUMBER                      = 47,
296        EXPRTOKEN_VARIABLE_REFERENCE          = 48
297    };
298
299    // -----------------------------------------------------------------------
300    //  Constructors/Destructor
301    // -----------------------------------------------------------------------
302    XercesXPath(const XMLCh* const xpathExpr,
303                XMLStringPool* const stringPool,
304                NamespaceScope* const scopeContext,
305                const unsigned int emptyNamespaceId,
306                const bool isSelector = false,
307                MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
308        ~XercesXPath();
309
310    // -----------------------------------------------------------------------
311    //  Operators
312    // -----------------------------------------------------------------------
313    bool operator== (const XercesXPath& other) const;
314    bool operator!= (const XercesXPath& other) const;
315
316    // -----------------------------------------------------------------------
317    //  Constructors/Destructor
318    // -----------------------------------------------------------------------
319    RefVectorOf<XercesLocationPath>* getLocationPaths() const;
320
321    /***
322     * Support for Serialization/De-serialization
323     ***/
324    DECL_XSERIALIZABLE(XercesXPath)
325
326    XercesXPath(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
327
328    XMLCh* getExpression();
329
330private:
331    // -----------------------------------------------------------------------
332    //  Unimplemented contstructors and operators
333    // -----------------------------------------------------------------------
334    XercesXPath(const XercesXPath& other);
335    XercesXPath& operator= (const XercesXPath& other);
336
337    // -----------------------------------------------------------------------
338    //  Helper methods
339    // -----------------------------------------------------------------------
340    void cleanUp();
341    void checkForSelectedAttributes();
342    void parseExpression(XMLStringPool* const stringPool,
343                         NamespaceScope* const scopeContext);
344
345    // -----------------------------------------------------------------------
346    //  Data members
347    // -----------------------------------------------------------------------
348    unsigned int                     fEmptyNamespaceId;
349    XMLCh*                           fExpression;
350    RefVectorOf<XercesLocationPath>* fLocationPaths;
351    MemoryManager*                   fMemoryManager;
352};
353
354
355class VALIDATORS_EXPORT XPathScanner : public XMemory
356{
357public:
358    // -----------------------------------------------------------------------
359    //  Constants
360    // -----------------------------------------------------------------------
361    enum {
362        CHARTYPE_INVALID            =  0,   // invalid XML character
363        CHARTYPE_OTHER              =  1,   // not special - one of "#%&;?\^`{}~" or DEL
364        CHARTYPE_WHITESPACE         =  2,   // one of "\t\n\r " (0x09, 0x0A, 0x0D, 0x20)
365        CHARTYPE_EXCLAMATION        =  3,   // '!' (0x21)
366        CHARTYPE_QUOTE              =  4,   // '\"' or '\'' (0x22 and 0x27)
367        CHARTYPE_DOLLAR             =  5,   // '$' (0x24)
368        CHARTYPE_OPEN_PAREN         =  6,   // '(' (0x28)
369        CHARTYPE_CLOSE_PAREN        =  7,   // ')' (0x29)
370        CHARTYPE_STAR               =  8,   // '*' (0x2A)
371        CHARTYPE_PLUS               =  9,   // '+' (0x2B)
372        CHARTYPE_COMMA              = 10,   // ',' (0x2C)
373        CHARTYPE_MINUS              = 11,   // '-' (0x2D)
374        CHARTYPE_PERIOD             = 12,   // '.' (0x2E)
375        CHARTYPE_SLASH              = 13,   // '/' (0x2F)
376        CHARTYPE_DIGIT              = 14,   // '0'-'9' (0x30 to 0x39)
377        CHARTYPE_COLON              = 15,   // ':' (0x3A)
378        CHARTYPE_LESS               = 16,   // '<' (0x3C)
379        CHARTYPE_EQUAL              = 17,   // '=' (0x3D)
380        CHARTYPE_GREATER            = 18,   // '>' (0x3E)
381        CHARTYPE_ATSIGN             = 19,   // '@' (0x40)
382        CHARTYPE_LETTER             = 20,   // 'A'-'Z' or 'a'-'z' (0x41 to 0x5A and 0x61 to 0x7A)
383        CHARTYPE_OPEN_BRACKET       = 21,   // '[' (0x5B)
384        CHARTYPE_CLOSE_BRACKET      = 22,   // ']' (0x5D)
385        CHARTYPE_UNDERSCORE         = 23,   // '_' (0x5F)
386        CHARTYPE_UNION              = 24,   // '|' (0x7C)
387        CHARTYPE_NONASCII           = 25   // Non-ASCII Unicode codepoint (>= 0x80)
388    };
389
390    // -----------------------------------------------------------------------
391    //  Constructors/Destructor
392    // -----------------------------------------------------------------------
393    XPathScanner(XMLStringPool* const stringPool);
394    virtual ~XPathScanner() {}
395
396    // -----------------------------------------------------------------------
397    //  Scan methods
398    // -----------------------------------------------------------------------
399    bool scanExpression(const XMLCh* const data, int currentOffset,
400                        const int endOffset, ValueVectorOf<int>* const tokens);
401
402protected:
403    // -----------------------------------------------------------------------
404    //  Helper methods
405    // -----------------------------------------------------------------------
406    /**
407      * This method adds the specified token to the token list. By default,
408      * this method allows all tokens. However, subclasses can can override
409      * this method in order to disallow certain tokens from being used in the
410      * scanned XPath expression. This is a convenient way of allowing only
411      * a subset of XPath.
412      */
413    virtual void addToken(ValueVectorOf<int>* const tokens, const int aToken);
414
415private:
416    // -----------------------------------------------------------------------
417    //  Unimplemented contstructors and operators
418    // -----------------------------------------------------------------------
419    XPathScanner(const XPathScanner& other);
420    XPathScanner& operator= (const XPathScanner& other);
421
422    // -----------------------------------------------------------------------
423    //  Helper methods
424    // -----------------------------------------------------------------------
425    void init();
426
427    // -----------------------------------------------------------------------
428    //  Scan methods
429    // -----------------------------------------------------------------------
430    int scanNCName(const XMLCh* const data, const int endOffset,
431                   int currentOffset);
432    int scanNumber(const XMLCh* const data, const int endOffset,
433                   int currentOffset, ValueVectorOf<int>* const tokens);
434
435    // -----------------------------------------------------------------------
436    //  Data members
437    // -----------------------------------------------------------------------
438    int fAndSymbol;
439    int fOrSymbol;
440    int fModSymbol;
441    int fDivSymbol;
442    int fCommentSymbol;
443    int fTextSymbol;
444    int fPISymbol;
445    int fNodeSymbol;
446    int fAncestorSymbol;
447    int fAncestorOrSelfSymbol;
448    int fAttributeSymbol;
449    int fChildSymbol;
450    int fDescendantSymbol;
451    int fDescendantOrSelfSymbol;
452    int fFollowingSymbol;
453    int fFollowingSiblingSymbol;
454    int fNamespaceSymbol;
455    int fParentSymbol;
456    int fPrecedingSymbol;
457    int fPrecedingSiblingSymbol;
458    int fSelfSymbol;
459    XMLStringPool* fStringPool;
460
461    static const XMLByte fASCIICharMap[128];
462};
463
464
465class VALIDATORS_EXPORT XPathScannerForSchema: public XPathScanner
466{
467public:
468    // -----------------------------------------------------------------------
469    //  Constructors/Destructor
470    // -----------------------------------------------------------------------
471    XPathScannerForSchema(XMLStringPool* const stringPool);
472    ~XPathScannerForSchema() {}
473
474protected:
475    // -----------------------------------------------------------------------
476    //  Helper methods
477    // -----------------------------------------------------------------------
478    void addToken(ValueVectorOf<int>* const tokens, const int aToken);
479
480private:
481    // -----------------------------------------------------------------------
482    //  Unimplemented contstructors and operators
483    // -----------------------------------------------------------------------
484    XPathScannerForSchema(const XPathScannerForSchema& other);
485    XPathScannerForSchema& operator= (const XPathScannerForSchema& other);
486};
487
488// ---------------------------------------------------------------------------
489//  XercesLocationPath: Access methods
490// ---------------------------------------------------------------------------
491inline unsigned int XercesLocationPath::getStepSize() const {
492
493    if (fSteps)
494        return fSteps->size();
495
496    return 0;
497}
498
499inline void XercesLocationPath::addStep(XercesStep* const aStep) {
500
501    fSteps->addElement(aStep);
502}
503
504inline XercesStep* XercesLocationPath::getStep(const unsigned int index) const {
505
506    if (fSteps)
507        return fSteps->elementAt(index);
508
509    return 0;
510}
511
512// ---------------------------------------------------------------------------
513//  XercesScanner: Helper methods
514// ---------------------------------------------------------------------------
515inline void XPathScanner::addToken(ValueVectorOf<int>* const tokens,
516                                   const int aToken) {
517    tokens->addElement(aToken);
518}
519
520
521// ---------------------------------------------------------------------------
522//  XercesXPath: Getter methods
523// ---------------------------------------------------------------------------
524inline RefVectorOf<XercesLocationPath>* XercesXPath::getLocationPaths() const {
525
526    return fLocationPaths;
527}
528
529inline XMLCh* XercesXPath::getExpression() {
530    return fExpression;
531}
532
533XERCES_CPP_NAMESPACE_END
534
535#endif
536
537/**
538  * End of file XercesPath.hpp
539  */
540
Note: See TracBrowser for help on using the repository browser.