TokenFactory.hpp
上传用户:huihehuasu
上传日期:2007-01-10
资源大小:6948k
文件大小:7k
源码类别:

xml/soap/webservice

开发平台:

C/C++

  1. /*
  2.  * The Apache Software License, Version 1.1
  3.  *
  4.  * Copyright (c) 2001 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.  * $Id: TokenFactory.hpp,v 1.5 2001/05/18 16:51:35 knoaman Exp $
  58.  */
  59. #if !defined(TOKENFACTORY_HPP)
  60. #define TOKENFACTORY_HPP
  61. // ---------------------------------------------------------------------------
  62. //  Includes
  63. // ---------------------------------------------------------------------------
  64. #include <util/XMLUniDefs.hpp>
  65. #include <util/RefHashTableOf.hpp>
  66. #include <util/RefVectorOf.hpp>
  67. #include <util/regx/Token.hpp>
  68. #include <util/Mutexes.hpp>
  69. // ---------------------------------------------------------------------------
  70. //  Forward Declaration
  71. // ---------------------------------------------------------------------------
  72. class RangeToken;
  73. class CharToken;
  74. class ClosureToken;
  75. class ConditionToken;
  76. class ConcatToken;
  77. class ModifierToken;
  78. class ParenToken;
  79. class StringToken;
  80. class UnionToken;
  81. class XMLUTIL_EXPORT TokenFactory {
  82. public:
  83. // -----------------------------------------------------------------------
  84.     //  Constructors and destructors
  85.     // -----------------------------------------------------------------------
  86.     TokenFactory();
  87.     ~TokenFactory();
  88.     // -----------------------------------------------------------------------
  89.     //  Factory methods
  90.     // -----------------------------------------------------------------------
  91.     Token* createToken(const unsigned short tokType);
  92.     ParenToken* createLook(const unsigned short tokType, Token* const token);
  93.     ParenToken* createParenthesis(Token* const token, const int noGroups);
  94.     ClosureToken* createClosure(Token* const token, bool isNonGreedy = false);
  95.     ConcatToken* createConcat(Token* const token1, Token* const token2);
  96.     UnionToken* createUnion(const bool isConcat = false);
  97.     RangeToken* createRange(const bool isNegRange = false);
  98.     CharToken* createChar(const XMLUInt32 ch, const bool isAnchor = false);
  99.     StringToken* createBackReference(const int refNo);
  100.     StringToken* createString(const XMLCh* const literal);
  101.     ModifierToken* createModifierGroup(Token* const child,
  102.                                        const int add, const int mask);
  103.     ConditionToken* createCondition(const int refNo, Token* const condition,
  104.                                     Token* const yesFlow, Token* const noFlow);
  105. //static void printUnicode();
  106.     // -----------------------------------------------------------------------
  107.     //  Getter methods
  108.     // -----------------------------------------------------------------------
  109.     /*
  110.      *  Gets a commonly used RangeToken from the token registry based on the
  111.      *  range name.
  112.      */
  113.     RangeToken* getRange(const XMLCh* const name,const bool complement=false);
  114.     Token* getLineBegin();
  115. Token* getLineBegin2();
  116.     Token* getLineEnd();
  117.     Token* getStringBegin();
  118.     Token* getStringEnd();
  119.     Token* getStringEnd2();
  120.     Token* getWordEdge();
  121.     Token* getNotWordEdge();
  122.     Token* getWordBegin();
  123.     Token* getWordEnd();
  124.     Token* getDot();
  125. Token* getCombiningCharacterSequence();
  126. Token* getGraphemePattern();
  127. private:
  128.     // -----------------------------------------------------------------------
  129.     //  Unimplemented constructors and operators
  130.     // -----------------------------------------------------------------------
  131.     TokenFactory(const TokenFactory&);
  132.     void operator=(const TokenFactory&);
  133.     // -----------------------------------------------------------------------
  134.     //  Private Helpers methods
  135.     // -----------------------------------------------------------------------
  136.     /*
  137.      *  Initializes the registry with a set of commonly used RangeToken
  138.      *  objects.
  139.      */
  140.     void initializeRegistry();
  141.     // -----------------------------------------------------------------------
  142.     //  Private data members
  143.     //
  144.     //  fRangeInitialized
  145.     //      Indicates whether we have initialized the RangeFactory instance or
  146.     //      not
  147. //
  148.     //  fToken
  149.     //      Contains user created Token objects. Used for memory cleanup.
  150.     // -----------------------------------------------------------------------
  151.     bool                fRangeInitialized;
  152. XMLMutex            fMutex;
  153.     RefVectorOf<Token>* fTokens;
  154.     Token*              fEmpty;
  155.     Token*              fLineBegin;
  156.     Token*              fLineBegin2;
  157.     Token*              fLineEnd;
  158.     Token*              fStringBegin;
  159.     Token*              fStringEnd;
  160.     Token*              fStringEnd2;
  161.     Token*              fWordEdge;
  162.     Token*              fNotWordEdge;
  163.     Token*              fWordEnd;
  164.     Token*              fWordBegin;
  165.     Token*              fDot;
  166. Token*              fCombiningChar;
  167. Token*              fGrapheme;
  168. };
  169. #endif
  170. /**
  171.   * End file TokenFactory
  172.   */