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

xml/soap/webservice

开发平台:

C/C++

  1. /*
  2.  * The Apache Software License, Version 1.1
  3.  *
  4.  * Copyright (c) 1999-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) 1999, 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.  * $Log: DTDGrammar.hpp,v $
  58.  * Revision 1.5  2001/09/14 14:50:22  tng
  59.  * Schema: Fix some wildcard bugs, and some retrieving qualified/unqualified element decl problems.
  60.  *
  61.  * Revision 1.4  2001/05/28 20:56:17  tng
  62.  * Schema: Move getTargetNamespace as virtual function in base class Grammar
  63.  *
  64.  * Revision 1.3  2001/05/11 13:27:09  tng
  65.  * Copyright update.
  66.  *
  67.  * Revision 1.2  2001/04/19 18:17:21  tng
  68.  * Schema: SchemaValidator update, and use QName in Content Model
  69.  *
  70.  * Revision 1.1  2001/03/21 21:56:20  tng
  71.  * Schema: Add Schema Grammar, Schema Validator, and split the DTDValidator into DTDValidator, DTDScanner, and DTDGrammar.
  72.  *
  73.  */
  74. #if !defined(DTDGRAMMAR_HPP)
  75. #define DTDGRAMMAR_HPP
  76. #include <util/RefHashTableOf.hpp>
  77. #include <util/NameIdPool.hpp>
  78. #include <util/StringPool.hpp>
  79. #include <validators/common/Grammar.hpp>
  80. #include <validators/DTD/DTDElementDecl.hpp>
  81. //
  82. // This class stores the DTD information
  83. //  NOTE: DTDs are not namespace aware, so we just use regular NameIdPool
  84. //  data structures to store element and attribute decls. They are all set
  85. //  to be in the global namespace and the full QName is used as the base name
  86. //  of the decl. This means that all the URI parameters below are expected
  87. //  to be null pointers (and anything else will cause an exception.)
  88. //
  89. class VALIDATORS_EXPORT DTDGrammar : public Grammar
  90. {
  91. public:
  92.     // -----------------------------------------------------------------------
  93.     //  Constructors and Destructor
  94.     // -----------------------------------------------------------------------
  95.     DTDGrammar();
  96.     virtual ~DTDGrammar();
  97.     // -----------------------------------------------------------------------
  98.     //  Implementation of Virtual Interface
  99.     // -----------------------------------------------------------------------
  100.     virtual Grammar::GrammarType getGrammarType();
  101.     virtual const XMLCh* getTargetNamespace() const;
  102.     virtual XMLElementDecl* findOrAddElemDecl
  103.     (
  104.         const   unsigned int    uriId
  105.         , const XMLCh* const    baseName
  106.         , const XMLCh* const    prefixName
  107.         , const XMLCh* const    qName
  108.         , unsigned int          scope
  109.         ,       bool&           wasAdded
  110.     ) ;
  111.     virtual unsigned int getElemId
  112.     (
  113.         const   unsigned int    uriId
  114.         , const XMLCh* const    baseName
  115.         , const XMLCh* const    qName
  116.         , unsigned int          scope
  117.     )   const ;
  118.     virtual const XMLElementDecl* getElemDecl
  119.     (
  120.         const   unsigned int    uriId
  121.         , const XMLCh* const    baseName
  122.         , const XMLCh* const    qName
  123.         , unsigned int          scope
  124.     )   const ;
  125.     virtual XMLElementDecl* getElemDecl
  126.     (
  127.         const   unsigned int    uriId
  128.         , const XMLCh* const    baseName
  129.         , const XMLCh* const    qName
  130.         , unsigned int          scope
  131.     );
  132.     virtual const XMLElementDecl* getElemDecl
  133.     (
  134.         const   unsigned int    elemId
  135.     )   const;
  136.     virtual XMLElementDecl* getElemDecl
  137.     (
  138.         const   unsigned int    elemId
  139.     );
  140.     virtual const XMLNotationDecl* getNotationDecl
  141.     (
  142.         const   XMLCh* const    notName
  143.     )   const;
  144.     virtual XMLNotationDecl* getNotationDecl
  145.     (
  146.         const   XMLCh* const    notName
  147.     );
  148.     virtual XMLElementDecl* putElemDecl
  149.     (
  150.         const   unsigned int    uriId
  151.         , const XMLCh* const    baseName
  152.         , const XMLCh* const    prefixName
  153.         , const XMLCh* const    qName
  154.         , unsigned int          scope
  155.     );
  156.     virtual unsigned int putElemDecl
  157.     (
  158.         XMLElementDecl* const elemDecl
  159.     )   const;
  160.     virtual unsigned int putNotationDecl
  161.     (
  162.         XMLNotationDecl* const notationDecl
  163.     )   const;
  164.     virtual void reset();
  165.     // -----------------------------------------------------------------------
  166.     //  Getter methods
  167.     // -----------------------------------------------------------------------
  168.     unsigned int getRootElemId();
  169.     NameIdPoolEnumerator<DTDElementDecl> getElemEnumerator() const;
  170.     NameIdPoolEnumerator<XMLNotationDecl> getNotationEnumerator() const;
  171.     // -----------------------------------------------------------------------
  172.     //  Setter methods
  173.     // -----------------------------------------------------------------------
  174.     void setRootElemId(unsigned int rootElemId);
  175. private:
  176.     // -----------------------------------------------------------------------
  177.     //  Private data members
  178.     //
  179.     //  fElemDeclPool
  180.     //      This is the element decl pool. It contains all of the elements
  181.     //      declared in the DTD (and their associated attributes.) When in
  182.     //      non-validating mode, its just populated as new elements are seen
  183.     //      and they are given default characteristics.
  184.     //
  185.     //  fNotationDeclPool
  186.     //      This is a pool of NotationDecl objects, which contains all of the
  187.     //      notations declared in the DTD subsets.
  188.     //
  189.     //  fRootElemId
  190.     //      The id of the root element that we found in the DOCTYPE statement.
  191.     //      Its initialized to ContentModel::fgInvalidElemId, so that its
  192.     //      invalid unless we have a DOCTYPE.
  193.     // -----------------------------------------------------------------------
  194.     NameIdPool<DTDElementDecl>*     fElemDeclPool;
  195.     NameIdPool<XMLNotationDecl>*    fNotationDeclPool;
  196.     unsigned int                    fRootElemId;
  197. };
  198. // ---------------------------------------------------------------------------
  199. //  DTDGrammar: Getter methods
  200. // ---------------------------------------------------------------------------
  201. inline unsigned int DTDGrammar::getRootElemId()
  202. {
  203.     return fRootElemId;
  204. }
  205. // ---------------------------------------------------------------------------
  206. //  DTDGrammar: Getter methods
  207. // ---------------------------------------------------------------------------
  208. inline NameIdPoolEnumerator<DTDElementDecl>
  209. DTDGrammar::getElemEnumerator() const
  210. {
  211.     return NameIdPoolEnumerator<DTDElementDecl>(fElemDeclPool);
  212. }
  213. inline NameIdPoolEnumerator<XMLNotationDecl>
  214. DTDGrammar::getNotationEnumerator() const
  215. {
  216.     return NameIdPoolEnumerator<XMLNotationDecl>(fNotationDeclPool);
  217. }
  218. // -----------------------------------------------------------------------
  219. //  Setter methods
  220. // -----------------------------------------------------------------------
  221. inline void DTDGrammar::setRootElemId(unsigned int rootElemId) {
  222.     fRootElemId = rootElemId;
  223. }
  224. // ---------------------------------------------------------------------------
  225. //  DTDGrammar: Virtual methods
  226. // ---------------------------------------------------------------------------
  227. inline Grammar::GrammarType DTDGrammar::getGrammarType() {
  228.     return Grammar::DTDGrammarType;
  229. }
  230. inline const XMLCh* DTDGrammar::getTargetNamespace() const {
  231.     return XMLUni::fgZeroLenString;
  232. }
  233. // Element Decl
  234. inline unsigned int DTDGrammar::getElemId (const   unsigned int  uriId
  235.                                               , const XMLCh* const    baseName
  236.                                               , const XMLCh* const    qName
  237.                                               , unsigned int          scope ) const
  238. {
  239.     //
  240.     //  In this case, we don't return zero to mean 'not found', so we have to
  241.     //  map it to the official not found value if we don't find it.
  242.     //
  243.     const DTDElementDecl* decl = fElemDeclPool->getByKey(qName);
  244.     if (!decl)
  245.         return XMLElementDecl::fgInvalidElemId;
  246.     return decl->getId();
  247. }
  248. inline const XMLElementDecl* DTDGrammar::getElemDecl( const   unsigned int  uriId
  249.                                               , const XMLCh* const    baseName
  250.                                               , const XMLCh* const    qName
  251.                                               , unsigned int          scope )   const
  252. {
  253.     return fElemDeclPool->getByKey(qName);
  254. }
  255. inline XMLElementDecl* DTDGrammar::getElemDecl (const   unsigned int  uriId
  256.                                               , const XMLCh* const    baseName
  257.                                               , const XMLCh* const    qName
  258.                                               , unsigned int          scope )
  259. {
  260.     return fElemDeclPool->getByKey(qName);
  261. }
  262. inline const XMLElementDecl* DTDGrammar::getElemDecl(const unsigned int elemId) const
  263. {
  264.     // Look up this element decl by id
  265.     return fElemDeclPool->getById(elemId);
  266. }
  267. inline XMLElementDecl* DTDGrammar::getElemDecl(const unsigned int elemId)
  268. {
  269.     // Look up this element decl by id
  270.     return fElemDeclPool->getById(elemId);
  271. }
  272. inline unsigned int DTDGrammar::putElemDecl (XMLElementDecl* const elemDecl)   const
  273. {
  274.     return fElemDeclPool->put((DTDElementDecl*) elemDecl);
  275. }
  276. // Notation Decl
  277. inline const XMLNotationDecl* DTDGrammar::getNotationDecl(const XMLCh* const notName) const
  278. {
  279.     return fNotationDeclPool->getByKey(notName);
  280. }
  281. inline XMLNotationDecl* DTDGrammar::getNotationDecl(const XMLCh* const notName)
  282. {
  283.     return fNotationDeclPool->getByKey(notName);
  284. }
  285. inline unsigned int DTDGrammar::putNotationDecl(XMLNotationDecl* const notationDecl)   const
  286. {
  287.     return fNotationDeclPool->put(notationDecl);
  288. }
  289. #endif