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

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.  * $Log: QName.hpp,v $
  58.  * Revision 1.8  2001/12/06 17:48:36  tng
  59.  * Performance Enhancement.  Added setNPrefix and setNLocalPart methods that allow code to take advantage of the fact that it knows the length of the prefix and local name, when possible.  That can avoid a copy of the prefix into a null-terminated temporary variable before copying into the fPrefix.
  60.  * Also changed the getRawName method so that it would simply return the local part when there is no prefix, instead of allocating another buffer to copy the local part into the fRawName.
  61.  * When there is a prefix, changed the getRawName to copy the prefix and local part into the fRawName using XMLString::moveChars instead of using XMLString::copyString and XMLString::catString.  The catString method has to loop past the prefix portion of the fRawName, which seems like a waste.
  62.  * By Henry Zongaro.
  63.  *
  64.  * Revision 1.7  2001/07/24 18:31:47  knoaman
  65.  * Added support for <group> + extra constraint checking for complexType
  66.  *
  67.  * Revision 1.6  2001/05/11 13:26:28  tng
  68.  * Copyright update.
  69.  *
  70.  * Revision 1.5  2001/04/19 18:17:10  tng
  71.  * Schema: SchemaValidator update, and use QName in Content Model
  72.  *
  73.  * Revision 1.4  2001/03/21 21:56:12  tng
  74.  * Schema: Add Schema Grammar, Schema Validator, and split the DTDValidator into DTDValidator, DTDScanner, and DTDGrammar.
  75.  *
  76.  * Revision 1.3  2001/02/27 14:48:39  tng
  77.  * Schema: Add CMAny and ContentLeafNameTypeVector, by Pei Yong Zhang
  78.  *
  79.  * Revision 1.2  2001/02/26 21:56:16  tng
  80.  * Schema: QName can also be constructed with rawName.
  81.  *
  82.  * Revision 1.1  2001/02/26 19:44:25  tng
  83.  * Schema: add utility class QName, by Pei Yong Zhang.
  84.  *
  85.  */
  86. #if !defined(QNAME_HPP)
  87. #define QNAME_HPP
  88. #include <util/XMLString.hpp>
  89. #include <util/XMLUniDefs.hpp>
  90. #include <util/XMLUni.hpp>
  91. class XMLUTIL_EXPORT QName
  92. {
  93. public :
  94.     // -----------------------------------------------------------------------
  95.     //  Contructors and Destructor
  96.     // -----------------------------------------------------------------------
  97.     /** Default constructor. */
  98.     QName();
  99.     /** Constructs a specified qname using prefix, and localpart. */
  100.     QName
  101.     (   const XMLCh* const        prefix
  102.       , const XMLCh* const        localPart
  103.    , const unsigned int        uriId
  104.     );
  105.     /** Constructs a specified qname using rawName. */
  106.     QName
  107.     (   const XMLCh* const        rawName
  108.    , const unsigned int        uriId
  109.     );
  110.     /** Copy constructor. */
  111.     QName(const QName* const qname);
  112.     ~QName();
  113.     // -----------------------------------------------------------------------
  114.     //  Getters
  115.     // -----------------------------------------------------------------------
  116.     const XMLCh* getPrefix() const;
  117.     XMLCh* getPrefix();
  118.     const XMLCh* getLocalPart() const;
  119.     XMLCh* getLocalPart();
  120.     const unsigned int getURI() const;
  121.     unsigned int getURI();
  122.     const XMLCh* getRawName() const;
  123.     XMLCh* getRawName();
  124.     // -----------------------------------------------------------------------
  125.     //  Setters
  126.     // -----------------------------------------------------------------------
  127.     void setName
  128.     (
  129.         const XMLCh* const        prefix
  130.       , const XMLCh* const        localPart
  131.    , const unsigned int        uriId
  132.     );
  133.     void setName
  134.     (
  135.         const XMLCh* const        rawName
  136.    , const unsigned int        uriId
  137.     );
  138.     void setPrefix(const XMLCh*) ;
  139.     void setLocalPart(const XMLCh*) ;
  140.     void setNPrefix(const XMLCh*, const unsigned int) ;
  141.     void setNLocalPart(const XMLCh*, const unsigned int) ;
  142.     void setURI(const unsigned int) ;
  143.     void setValues(const QName& qname);
  144.     // -----------------------------------------------------------------------
  145.     //  comparison
  146.     // -----------------------------------------------------------------------
  147.     bool operator==(const QName&);
  148.     // -----------------------------------------------------------------------
  149.     //  Misc
  150.     // -----------------------------------------------------------------------
  151.     void cleanUp();
  152. private :
  153.     // -----------------------------------------------------------------------
  154.     //  Private instance variables
  155.     //
  156.     //  We copy the followings from XMLAttr.hpp, but stick to Java version's
  157.     //  naming convention
  158.     //
  159.     //  fPrefix
  160.     //  fPrefixBufSz
  161.     //      The prefix that was applied to this attribute's name, and the
  162.     //      current size of the buffer (minus one for the null.) Prefixes
  163.     //      really don't matter technically but it might be required for
  164.     //      pratical reasons, to recreate the original document for instance.
  165.     //
  166.     //  fLocalPart
  167.     //  fLocalPartBufSz
  168.     //      The base part of the name of the attribute, and the current size
  169.     //      of the buffer (minus one, where the null is.)
  170.     //
  171.     //  fRawName
  172.     //  fRawNameBufSz
  173.     //      This is the QName form of the name, which is faulted in (from the
  174.     //      prefix and name) upon request. The size field indicates the
  175.     //      current size of the buffer (minus one for the null.) It will be
  176.     //      zero until fauled in.
  177.     //
  178.     //  fURIId
  179.     //      The id of the URI that this attribute belongs to.
  180.     // -----------------------------------------------------------------------
  181.     XMLCh*              fPrefix;
  182.     unsigned int        fPrefixBufSz;
  183.     XMLCh*              fLocalPart;
  184.     unsigned int        fLocalPartBufSz;
  185.     XMLCh*              fRawName;
  186.     unsigned int        fRawNameBufSz;
  187.     unsigned int        fURIId;
  188. };
  189. // ---------------------------------------------------------------------------
  190. //  QName: Getter methods
  191. // ---------------------------------------------------------------------------
  192. inline const XMLCh* QName::getPrefix() const
  193. {
  194. return fPrefix;
  195. }
  196. inline XMLCh* QName::getPrefix()
  197. {
  198. return fPrefix;
  199. }
  200. inline const XMLCh* QName::getLocalPart() const
  201. {
  202. return fLocalPart;
  203. }
  204. inline XMLCh* QName::getLocalPart()
  205. {
  206. return fLocalPart;
  207. }
  208. inline const unsigned int QName::getURI() const
  209. {
  210. return fURIId;
  211. }
  212. inline unsigned int QName::getURI()
  213. {
  214. return fURIId;
  215. }
  216. // ---------------------------------------------------------------------------
  217. //  QName: Setter methods
  218. // ---------------------------------------------------------------------------
  219. inline void QName::setURI(const unsigned int uriId)
  220. {
  221.     fURIId = uriId;
  222. }
  223. #endif