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

xml/soap/webservice

开发平台:

C/C++

  1. #ifndef AttrImpl_HEADER_GUARD_
  2. #define AttrImpl_HEADER_GUARD_
  3. /*
  4.  * The Apache Software License, Version 1.1
  5.  *
  6.  * Copyright (c) 1999-2001 The Apache Software Foundation.  All rights
  7.  * reserved.
  8.  *
  9.  * Redistribution and use in source and binary forms, with or without
  10.  * modification, are permitted provided that the following conditions
  11.  * are met:
  12.  *
  13.  * 1. Redistributions of source code must retain the above copyright
  14.  *    notice, this list of conditions and the following disclaimer.
  15.  *
  16.  * 2. Redistributions in binary form must reproduce the above copyright
  17.  *    notice, this list of conditions and the following disclaimer in
  18.  *    the documentation and/or other materials provided with the
  19.  *    distribution.
  20.  *
  21.  * 3. The end-user documentation included with the redistribution,
  22.  *    if any, must include the following acknowledgment:
  23.  *       "This product includes software developed by the
  24.  *        Apache Software Foundation (http://www.apache.org/)."
  25.  *    Alternately, this acknowledgment may appear in the software itself,
  26.  *    if and wherever such third-party acknowledgments normally appear.
  27.  *
  28.  * 4. The names "Xerces" and "Apache Software Foundation" must
  29.  *    not be used to endorse or promote products derived from this
  30.  *    software without prior written permission. For written
  31.  *    permission, please contact apache@apache.org.
  32.  *
  33.  * 5. Products derived from this software may not be called "Apache",
  34.  *    nor may "Apache" appear in their name, without prior written
  35.  *    permission of the Apache Software Foundation.
  36.  *
  37.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  38.  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  39.  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  40.  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  41.  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  42.  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  43.  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  44.  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  45.  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  46.  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  47.  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  48.  * SUCH DAMAGE.
  49.  * ====================================================================
  50.  *
  51.  * This software consists of voluntary contributions made by many
  52.  * individuals on behalf of the Apache Software Foundation, and was
  53.  * originally based on software copyright (c) 1999, International
  54.  * Business Machines, Inc., http://www.ibm.com .  For more information
  55.  * on the Apache Software Foundation, please see
  56.  * <http://www.apache.org/>.
  57.  */
  58. /**
  59.  * Attribute represents an XML-style attribute of an
  60.  * Element. Typically, the allowable values are controlled by its
  61.  * declaration in the Document Type Definition (DTD) governing this
  62.  * kind of document.
  63.  * <P>
  64.  * If the attribute has not been explicitly assigned a value, but has
  65.  * been declared in the DTD, it will exist and have that default. Only
  66.  * if neither the document nor the DTD specifies a value will the
  67.  * Attribute really be considered absent and have no value; in that
  68.  * case, querying the attribute will return null.
  69.  * <P>
  70.  * Attributes may have multiple children that contain their data. (XML
  71.  * allows attributes to contain entity references, and tokenized
  72.  * attribute types such as NMTOKENS may have a child for each token.)
  73.  * For convenience, the Attribute object's getValue() method returns
  74.  * the string version of the attribute's value.
  75.  * <P>
  76.  * Attributes are not children of the Elements they belong to, in the
  77.  * usual sense, and have no valid Parent reference. However, the spec
  78.  * says they _do_ belong to a specific Element, and an INUSE exception
  79.  * is to be thrown if the user attempts to explicitly share them
  80.  * between elements.
  81.  * <P>
  82.  * Note that Elements do not permit attributes to appear to be shared
  83.  * (see the INUSE exception), so this object's mutability is
  84.  * officially not an issue.
  85.  * <p>
  86.  * Note: The ownerNode attribute is used to store the Element the Attr
  87.  * node is associated with. Attr nodes do not have parent nodes.
  88.  * Besides, the getOwnerElement() method can be used to get the element node
  89.  * this attribute is associated with.
  90.  * <P>
  91.  * AttrImpl does not support Namespaces. AttrNSImpl, which inherits from
  92.  * it, does.
  93.  *
  94.  * <p>AttrImpl used to inherit from ParentNode. It now directly inherits from
  95.  * NodeImpl and provide its own implementation of the ParentNode's behavior.
  96.  * The reason is that we now try and avoid to always creating a Text node to
  97.  * hold the value of an attribute. The DOM spec requires it, so we still have
  98.  * to do it in case getFirstChild() is called for instance. The reason
  99.  * attribute values are stored as a list of nodes is so that they can carry
  100.  * more than a simple string. They can also contain EntityReference nodes.
  101.  * However, most of the times people only have a single string that they only
  102.  * set and get through Element.set/getAttribute or Attr.set/getValue. In this
  103.  * new version, the Attr node has a value pointer which can either be the
  104.  * String directly or a pointer to the first ChildNode. A flag tells which one
  105.  * it currently is. Note that while we try to stick with the direct String as
  106.  * much as possible once we've switched to a node there is no going back. This
  107.  * is because we have no way to know whether the application keeps referring to
  108.  * the node we once returned.
  109.  * <p> The gain in memory varies on the density of attributes in the document.
  110.  * But in the tests I've run I've seen up to 12% of memory gain. And the good
  111.  * thing is that it also leads to a slight gain in speed because we allocate
  112.  * fewer objects! I mean, that's until we have to actually create the node...
  113.  * <p>
  114.  * To avoid too much duplicated code, I got rid of ParentNode and renamed
  115.  * ChildAndParentNode, which I never really liked, to ParentNode for
  116.  * simplicity, this doesn't make much of a difference in memory usage because
  117.  * there are only very objects that are only a Parent. This is only true now
  118.  * because AttrImpl now inherits directly from NodeImpl and has its own
  119.  * implementation of the ParentNode's node behavior. So there is still some
  120.  * duplicated code there.
  121.  *
  122.  * <p><b>WARNING</b>: Some of the code here is partially duplicated in
  123.  * ParentNode, be careful to keep these two classes in sync!
  124.  *
  125.  * $Id: AttrImpl.hpp,v 1.13 2001/05/11 13:25:17 tng Exp $
  126.  */
  127. //
  128. //  This file is part of the internal implementation of the C++ XML DOM.
  129. //  It should NOT be included or used directly by application programs.
  130. //
  131. //  Applications should include the file <dom/DOM.hpp> for the entire
  132. //  DOM API, or DOM_*.hpp for individual DOM classes, where the class
  133. //  name is substituded for the *.
  134. //
  135. #include <util/XercesDefs.hpp>
  136. #include "ChildNode.hpp"
  137. #include "DOM_Node.hpp"
  138. class ElementImpl;
  139. class CDOM_EXPORT AttrImpl: public NodeImpl {
  140. public:
  141.     DOMString name;
  142.     /** This can either be a DOMString or the first child node (ChildNode*). */
  143.     void *value;
  144. public:
  145.     AttrImpl(DocumentImpl *ownerDocument, const DOMString &aName);
  146.     AttrImpl(const AttrImpl &other, bool deep=false);
  147.     virtual ~AttrImpl();
  148.     virtual NodeImpl *cloneNode(bool deep=false);
  149.     virtual DOMString getNodeName();
  150.     virtual short getNodeType();
  151.     virtual DOMString getName();
  152.     virtual DOMString getNodeValue();
  153.     virtual bool getSpecified();
  154.     virtual DOMString getValue();
  155.     virtual bool isAttrImpl();
  156.     virtual void setNodeValue(const DOMString &value);
  157.     virtual void setSpecified(bool arg);
  158.     virtual void setValue(const DOMString &value);
  159.     virtual DOMString toString();
  160.     //Introduced in DOM Level 2
  161.     ElementImpl *getOwnerElement();
  162.     void setOwnerElement(ElementImpl *ownerElem);    //internal use only
  163.     // ParentNode stuff
  164.     virtual NodeListImpl *getChildNodes();
  165.     virtual NodeImpl * getFirstChild();
  166.     virtual NodeImpl * getLastChild();
  167.     virtual unsigned int getLength();
  168.     virtual bool        hasChildNodes();
  169.     virtual NodeImpl    *insertBefore(NodeImpl *newChild, NodeImpl *refChild);
  170.     virtual NodeImpl    *item(unsigned int index);
  171.     virtual NodeImpl    *removeChild(NodeImpl *oldChild);
  172.     virtual NodeImpl    *replaceChild(NodeImpl *newChild, NodeImpl *oldChild);
  173.     virtual void        setReadOnly(bool isReadOnly, bool deep);
  174.     //Introduced in DOM Level 2
  175.     virtual void normalize();
  176. protected:
  177.     void makeChildNode();
  178.     void cloneChildren(const NodeImpl &other);
  179.     ChildNode * lastChild();
  180.     void lastChild(ChildNode *);
  181. };
  182. #endif