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

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: XMLAttDef.hpp,v $
  58.  * Revision 1.13  2001/11/15 16:36:36  knoaman
  59.  * Re-organize constant values.
  60.  *
  61.  * Revision 1.12  2001/08/09 15:23:37  knoaman
  62.  * add support for <anyAttribute> declaration.
  63.  *
  64.  * Revision 1.11  2001/06/21 14:25:26  knoaman
  65.  * Fix for bug 1946
  66.  *
  67.  * Revision 1.10  2001/05/11 13:25:31  tng
  68.  * Copyright update.
  69.  *
  70.  * Revision 1.9  2001/02/27 18:48:20  tng
  71.  * Schema: Add SchemaAttDef, SchemaElementDecl, SchemaAttDefList.
  72.  *
  73.  * Revision 1.8  2000/12/14 18:49:56  tng
  74.  * Fix API document generation warning: "Warning: end of member group without matching begin"
  75.  *
  76.  * Revision 1.7  2000/11/30 18:22:38  andyh
  77.  * reuseValidator - fix bugs (spurious errors) that occured on reuse due to
  78.  * pools already containing some items.  Fixed by Tinny Ng.
  79.  *
  80.  * Revision 1.6  2000/07/07 22:23:38  jpolast
  81.  * remove useless getKey() functions.
  82.  *
  83.  * Revision 1.5  2000/02/24 20:00:22  abagchi
  84.  * Swat for removing Log from API docs
  85.  *
  86.  * Revision 1.4  2000/02/16 23:03:48  roddey
  87.  * More documentation updates
  88.  *
  89.  * Revision 1.3  2000/02/15 01:21:30  roddey
  90.  * Some initial documentation improvements. More to come...
  91.  *
  92.  * Revision 1.2  2000/02/06 07:47:46  rahulj
  93.  * Year 2K copyright swat.
  94.  *
  95.  * Revision 1.1.1.1  1999/11/09 01:08:27  twl
  96.  * Initial checkin
  97.  *
  98.  * Revision 1.2  1999/11/08 20:44:34  rahul
  99.  * Swat for adding in Product name and CVS comment log variable.
  100.  *
  101.  */
  102. #if !defined(ATTDEF_HPP)
  103. #define ATTDEF_HPP
  104. #include <util/XMLString.hpp>
  105. class XMLAttr;
  106. /** Represents the core information of an atribute definition
  107.  *
  108.  *  This class defines the basic characteristics of an attribute, no matter
  109.  *  what type of validator is used. If a particular schema associates more
  110.  *  information with an attribute it will create a derivative of this class.
  111.  *  So this class provides an abstract way to get basic information on
  112.  *  attributes from any type of validator.
  113.  *
  114.  *  This class supports keyed collection semantics on the fully qualified
  115.  *  attribute name, by providing a getKey() method to extract the key string.
  116.  *  getKey(), in this case, just calls the virtual method getFullName() to
  117.  *  get the fully qualified name, as defined by the derived class.
  118.  *
  119.  *  Note that the 'value' of an attribute type definition is the default or
  120.  *  of fixed value given to it in its definition. If the attribute is of the
  121.  *  enumerated or notation type, it will have an 'enumeration value' as well
  122.  *  which is a space separated list of its possible vlaues.
  123.  */
  124. class XMLPARSER_EXPORT XMLAttDef
  125. {
  126. public:
  127.     // -----------------------------------------------------------------------
  128.     //  Class specific types
  129.     //
  130.     //  AttTypes
  131.     //      The list of possible types that an attribute can have, according
  132.     //      to the XML 1.0 spec and schema.
  133.     //
  134.     //  DefAttTypes
  135.     //      The modifiers that an attribute decl can have, which indicates
  136.     //      whether instances of that attributes are required, implied, etc..
  137.     //
  138.     //  CreateReasons
  139.     //      This type is used to store how an attribute declaration got into
  140.     //      the elementdecl's attribute pool.
  141.     //
  142.     // -----------------------------------------------------------------------
  143. enum AttTypes
  144.     {
  145.         CData               = 0
  146.         , ID                = 1
  147.         , IDRef             = 2
  148.         , IDRefs            = 3
  149.         , Entity            = 4
  150.         , Entities          = 5
  151.         , NmToken           = 6
  152.         , NmTokens          = 7
  153.         , Notation          = 8
  154.         , Enumeration       = 9
  155.         , Simple            = 10
  156.         , Any_Any           = 11
  157.         , Any_Other         = 12
  158.         , Any_List          = 13
  159.         , AttTypes_Count
  160.         , AttTypes_Min      = 0
  161.         , AttTypes_Max      = 13
  162.         , AttTypes_Unknown  = -1
  163. };
  164.     enum DefAttTypes
  165.     {
  166.         Default                  = 0
  167.         , Fixed                  = 1
  168.         , Required               = 2
  169.         , Required_And_Fixed     = 3
  170.         , Implied                = 4
  171.         , ProcessContents_Strict = 5
  172.         , ProcessContents_Lax    = 6
  173.         , ProcessContents_Skip   = 7
  174.         , Prohibited             = 8
  175.         , DefAttTypes_Count
  176.         , DefAttTypes_Min   = 0
  177.         , DefAttTypes_Max   = 8
  178.         , DefAttTypes_Unknown = -1
  179. };
  180.     enum CreateReasons
  181.     {
  182.         NoReason
  183.         , JustFaultIn
  184.     };
  185.     // -----------------------------------------------------------------------
  186.     //  Public static data members
  187.     // -----------------------------------------------------------------------
  188.     static const unsigned int fgInvalidAttrId;
  189.     // -----------------------------------------------------------------------
  190.     //  Public, static methods
  191.     // -----------------------------------------------------------------------
  192.     /** @name Public, static methods */
  193.     //@{
  194.     /** Get a string representation of the passed attribute type enum
  195.       *
  196.       * This method allows you to get a textual representation of an attriubte
  197.       * type, mostly for debug or display.
  198.       *
  199.       * @param attrType The attribute type value to get the string for.
  200.       *
  201.       * @return A const pointer to the static string that holds the text
  202.       *         description of the passed type.
  203.       */
  204.     static const XMLCh* getAttTypeString(const AttTypes attrType);
  205.     /** Get a string representation of the passed def attribute type enum
  206.       *
  207.       * This method allows you to get a textual representation of an default
  208.       * attributetype, mostly for debug or display.
  209.       *
  210.       * @param attrType The default attribute type value to get the string for.
  211.       *
  212.       * @return A const pointer to the static string that holds the text
  213.       *         description of the passed default type.
  214.       */
  215.     static const XMLCh* getDefAttTypeString(const DefAttTypes attrType);
  216.     //@}
  217.     // -----------------------------------------------------------------------
  218.     //  Destructor
  219.     // -----------------------------------------------------------------------
  220.     /** @name Destructor */
  221.     //@{
  222.     /**
  223.       *  Destructor
  224.       */
  225.     virtual ~XMLAttDef();
  226.     //@}
  227.     // -----------------------------------------------------------------------
  228.     //  The virtual attribute def interface
  229.     // -----------------------------------------------------------------------
  230.     /** @name Virtual interface */
  231.     //@{
  232.     /** Get the full name of this attribute type
  233.       *
  234.       * The derived class should return a const pointer to the full name of
  235.       * this attribute. This will vary depending on the type of validator in
  236.       * use.
  237.       *
  238.       * @return A const pointer to the full name of this attribute type.
  239.       */
  240.     virtual const XMLCh* getFullName() const = 0;
  241.     //@}
  242.     // -----------------------------------------------------------------------
  243.     //  Getter methods
  244.     // -----------------------------------------------------------------------
  245.     /** @name Getter methods */
  246.     //@{
  247.     /** Get the default type of this attribute type
  248.       *
  249.       * This method returns the 'default type' of the attribute. Default
  250.       * type in this case refers to the XML concept of a default type for
  251.       * an attribute, i.e. #FIXED, #IMPLIED, etc...
  252.       *
  253.       * @return The default type enum for this attribute type.
  254.       */
  255.     DefAttTypes getDefaultType() const;
  256.     /** Get the enumeration value (if any) of this attribute type
  257.       *
  258.       * If the attribute is of an enumeration or notatin type, then this
  259.       * method will return a const reference to a string that contains the
  260.       * space separated values that can the attribute can have.
  261.       *
  262.       * @return A const pointer to a string that contains the space separated
  263.       *         legal values for this attribute.
  264.       */
  265.     const XMLCh* getEnumeration() const;
  266.     /** Get the pool id of this attribute type
  267.       *
  268.       * This method will return the id of this attribute in the validator's
  269.       * attribute pool. It was set by the validator when this attribute was
  270.       * created.
  271.       *
  272.       * @return The pool id of this attribute type.
  273.       */
  274.     unsigned int getId() const;
  275.     /** Query whether the attribute was explicitly provided.
  276.       *
  277.       * When the scanner scans a start tag, it will ask the element decl
  278.       * object of the element type of that start tag to clear the 'provided'
  279.       * flag on all its attributes. As the scanner sees explicitly provided
  280.       * attributes, its turns on this flag to indicate that this attribute
  281.       * has been provided. In this way, the scanner can catch duplicated
  282.       * attributes and required attributes that aren't provided, and default
  283.       * in fixed/default valued attributes that are not explicitly provided.
  284.       *
  285.       * @return Returns a boolean value that indicates whether this attribute
  286.       *         was explicitly provided.
  287.       */
  288.     bool getProvided() const;
  289.     /** Get the type of this attribute
  290.       *
  291.       * Gets the type of this attribute. This type is represented by an enum
  292.       * that convers the types of attributes allowed by XML, e.g. CDATA, NMTOKEN,
  293.       * NOTATION, etc...
  294.       *
  295.       * @return The attribute type enumeration value for this type of
  296.       *         attribute.
  297.       */
  298.     AttTypes getType() const;
  299.     /** Get the default/fixed value of this attribute (if any.)
  300.       *
  301.       * If the attribute defined a default/fixed value, then it is stored
  302.       * and this method will retrieve it. If it has non, then a null pointer
  303.       * is returned.
  304.       *
  305.       * @return A const pointer to the default/fixed value for this attribute
  306.       *         type.
  307.       */
  308.     const XMLCh* getValue() const;
  309.     /** Get the create reason for this attribute
  310.       *
  311.       * This method returns an enumeration which indicates why this attribute
  312.       * declaration exists.
  313.       *
  314.       * @return An enumerated value that indicates the reason why this attribute
  315.       * was added to the attribute table.
  316.       */
  317.     CreateReasons getCreateReason() const;
  318.     /** Indicate whether this attribute has been declared externally
  319.       *
  320.       * This method returns a boolean that indicates whether this attribute
  321.       * has been declared externally.
  322.       *
  323.       * @return true if this attribute has been declared externally, else false.
  324.       */
  325.     bool isExternal() const;
  326.     //@}
  327.     // -----------------------------------------------------------------------
  328.     //  Setter methods
  329.     // -----------------------------------------------------------------------
  330.     /** @name Setter methods */
  331.     //@{
  332.     /** Set the default attribute type
  333.       *
  334.       * This method sets the default attribute type for this attribute.
  335.       * This setting controls whether the attribute is required, fixed,
  336.       * implied, etc...
  337.       *
  338.       * @param  The new default attribute to set
  339.       */
  340.     void setDefaultType(const XMLAttDef::DefAttTypes newValue);
  341.     /** Set the pool id for this attribute type.
  342.       *
  343.       * This method sets the pool id of this attribute type. This is usually
  344.       * called by the validator that creates the actual instance (which is of
  345.       * a derived type known only by the validator.)
  346.       *
  347.       * @param  The new pool id to set.
  348.       */
  349.     void setId(const unsigned int newId);
  350.     /** Set or clear the 'provided' flag.
  351.       *
  352.       * This method will set or clear the 'provided' flag. This is called
  353.       * by the scanner as it is scanning a start tag and marking off the
  354.       * attributes that have been explicitly provided.
  355.       *
  356.       * @param  The new provided state to set
  357.       */
  358.     void setProvided(const bool newValue);
  359.     /** Set the type of this attribute type.
  360.       *
  361.       * This method will set the type of the attribute. The type of an attribute
  362.       * controls how it is normalized and what kinds of characters it can hold.
  363.       *
  364.       * @param  The new attribute type to set
  365.       */
  366.     void setType(const XMLAttDef::AttTypes newValue);
  367.     /** Set the default/fixed value of this attribute type.
  368.       *
  369.       * This method set the fixed/default value for the attribute. This value
  370.       * will be used when instances of this attribute type are faulted in. It
  371.       * <b>must</b> be a valid value for the type set by setType(). If the
  372.       * type is enumeration or notation, this must be one of the valid values
  373.       * set in the setEnumeration() call.
  374.       *
  375.       * @param  The new fixed/default value to set.
  376.       */
  377.     void setValue(const XMLCh* const newValue);
  378.     /** Set the enumerated value of this attribute type.
  379.       *
  380.       * This method sets the enumerated/notation value list for this attribute
  381.       * type. It is a space separated set of possible values. These values must
  382.       * meet the constrains of the XML spec for such values of this type of
  383.       * attribute. This should only be set if the setType() method is used to
  384.       * set the type to the enumeration or notation types.
  385.       *
  386.       * @param  The new enumerated/notation value list to set.
  387.       */
  388.     void setEnumeration(const XMLCh* const newValue);
  389.     /** Update the create reason for this attribute type.
  390.       *
  391.       * This method will update the 'create reason' field for this attribute
  392.       * decl object.
  393.       */
  394.     void setCreateReason(const CreateReasons newReason);
  395.     /**
  396.       * Set the attribute decl to indicate external declaration
  397.       */
  398.     void setExternalAttDeclaration(const bool aValue);
  399.     //@}
  400. protected :
  401.     // -----------------------------------------------------------------------
  402.     //  Hidden constructors
  403.     // -----------------------------------------------------------------------
  404.     XMLAttDef
  405.     (
  406.         const   AttTypes            type = CData
  407.         , const DefAttTypes         defType = Implied
  408.     );
  409.     XMLAttDef
  410.     (
  411.         const   XMLCh* const        attValue
  412.         , const AttTypes            type
  413.         , const DefAttTypes         defType
  414.         , const XMLCh* const        enumValues = 0
  415.     );
  416. private :
  417.     // -----------------------------------------------------------------------
  418.     //  Unimplemented constructors and operators
  419.     // -----------------------------------------------------------------------
  420.     XMLAttDef(const XMLAttDef&);
  421.     void operator=(const XMLAttDef&);
  422.     // -----------------------------------------------------------------------
  423.     //  Private helper methods
  424.     // -----------------------------------------------------------------------
  425.     void cleanUp();
  426.     // -----------------------------------------------------------------------
  427.     //  Private data members
  428.     //
  429.     //  fDefaultType
  430.     //      Indicates what, if any, default stuff this attribute has.
  431.     //
  432.     //  fEnumeration
  433.     //      If its an enumeration, this is the list of values as space
  434.     //      separated values.
  435.     //
  436.     //  fId
  437.     //      This is the unique id of this attribute, given to it when its put
  438.     //      into the validator's attribute decl pool. It defaults to the
  439.     //      special value XMLAttrDef::fgInvalidAttrId.
  440.     //
  441.     //  fProvided
  442.     //      This field is really for use by the scanner. It is used to track
  443.     //      which of the attributes of an element were provided. Any marked
  444.     //      as not provided (after scanning the start tag) and having a
  445.     //      default type of Required, is in error.
  446.     //
  447.     //  fType
  448.     //      The type of attribute, which is one of the AttTypes values.
  449.     //
  450.     //  fValue
  451.     //      This is the value of the attribute, which is the default value
  452.     //      given in the attribute declaration.
  453.     //
  454.     //  fCreateReason
  455.     //      This flag tells us how this attribute got created.  Sometimes even
  456.     //      the attribute was not declared for the element, we want to fault
  457.     //      fault it into the pool to avoid lots of redundant errors.
  458.     //
  459.     //  fExternalAttribute
  460.     //      This flag indicates whether or not the attribute was declared externally.
  461.     // -----------------------------------------------------------------------
  462.     DefAttTypes     fDefaultType;
  463.     XMLCh*          fEnumeration;
  464.     unsigned int    fId;
  465.     bool            fProvided;
  466.     AttTypes        fType;
  467.     XMLCh*          fValue;
  468.     CreateReasons   fCreateReason;
  469.     bool            fExternalAttribute;
  470. };
  471. // ---------------------------------------------------------------------------
  472. //  Getter methods
  473. // ---------------------------------------------------------------------------
  474. inline XMLAttDef::DefAttTypes XMLAttDef::getDefaultType() const
  475. {
  476.     return fDefaultType;
  477. }
  478. inline const XMLCh* XMLAttDef::getEnumeration() const
  479. {
  480.     return fEnumeration;
  481. }
  482. inline unsigned int XMLAttDef::getId() const
  483. {
  484.     return fId;
  485. }
  486. inline bool XMLAttDef::getProvided() const
  487. {
  488.     return fProvided;
  489. }
  490. inline XMLAttDef::AttTypes XMLAttDef::getType() const
  491. {
  492.     return fType;
  493. }
  494. inline const XMLCh* XMLAttDef::getValue() const
  495. {
  496.     return fValue;
  497. }
  498. inline XMLAttDef::CreateReasons XMLAttDef::getCreateReason() const
  499. {
  500.     return fCreateReason;
  501. }
  502. inline bool XMLAttDef::isExternal() const
  503. {
  504.     return fExternalAttribute;
  505. }
  506. // ---------------------------------------------------------------------------
  507. //  XMLAttDef: Setter methods
  508. // ---------------------------------------------------------------------------
  509. inline void XMLAttDef::setDefaultType(const XMLAttDef::DefAttTypes newValue)
  510. {
  511.     fDefaultType = newValue;
  512. }
  513. inline void XMLAttDef::setEnumeration(const XMLCh* const newValue)
  514. {
  515.     delete [] fEnumeration;
  516.     if (newValue) {
  517.         fEnumeration = XMLString::replicate(newValue);
  518.     }
  519.     else {
  520.         fEnumeration = 0;
  521.     }
  522. }
  523. inline void XMLAttDef::setId(const unsigned int newId)
  524. {
  525.     fId = newId;
  526. }
  527. inline void XMLAttDef::setProvided(const bool newValue)
  528. {
  529.     fProvided = newValue;
  530. }
  531. inline void XMLAttDef::setType(const XMLAttDef::AttTypes newValue)
  532. {
  533.     fType = newValue;
  534. }
  535. inline void XMLAttDef::setValue(const XMLCh* const newValue)
  536. {
  537.     delete [] fValue;
  538.     fValue = XMLString::replicate(newValue);
  539. }
  540. inline void
  541. XMLAttDef::setCreateReason(const XMLAttDef::CreateReasons newReason)
  542. {
  543.     fCreateReason = newReason;
  544. }
  545. inline void XMLAttDef::setExternalAttDeclaration(const bool aValue)
  546. {
  547.     fExternalAttribute = aValue;
  548. }
  549. #endif