View Javadoc

1   /*
2    * Copyright 2001-2005 (C) MetaStuff, Ltd. All Rights Reserved.
3    *
4    * This software is open source.
5    * See the bottom of this file for the licence.
6    */
7   
8   package org.dom4j.tree;
9   
10  import org.dom4j.Namespace;
11  import org.dom4j.QName;
12  
13  /***
14   * <p>
15   * <code>FlyweightAttribute</code> is a Flyweight pattern implementation of a
16   * singly linked, read-only XML Attribute.
17   * </p>
18   * 
19   * <p>
20   * This node could be shared across documents and elements though it does not
21   * support the parent relationship.
22   * </p>
23   * 
24   * @author <a href="mailto:jstrachan@apache.org">James Strachan </a>
25   * @version $Revision: 1.7 $
26   */
27  public class FlyweightAttribute extends AbstractAttribute {
28      /*** The <code>QName</code> for this element */
29      private QName qname;
30  
31      /*** The value of the <code>Attribute</code> */
32      protected String value;
33  
34      public FlyweightAttribute(QName qname) {
35          this.qname = qname;
36      }
37  
38      public FlyweightAttribute(QName qname, String value) {
39          this.qname = qname;
40          this.value = value;
41      }
42  
43      /***
44       * Creates the <code>Attribute</code> with the specified local name and
45       * value.
46       * 
47       * @param name
48       *            is the name of the attribute
49       * @param value
50       *            is the value of the attribute
51       */
52      public FlyweightAttribute(String name, String value) {
53          this.qname = getDocumentFactory().createQName(name);
54          this.value = value;
55      }
56  
57      /***
58       * Creates the <code>Attribute</code> with the specified local name, value
59       * and <code>Namespace</code>.
60       * 
61       * @param name
62       *            is the name of the attribute
63       * @param value
64       *            is the value of the attribute
65       * @param namespace
66       *            is the namespace of the attribute
67       */
68      public FlyweightAttribute(String name, String value, Namespace namespace) {
69          this.qname = getDocumentFactory().createQName(name, namespace);
70          this.value = value;
71      }
72  
73      public String getValue() {
74          return value;
75      }
76  
77      public QName getQName() {
78          return qname;
79      }
80  }
81  
82  /*
83   * Redistribution and use of this software and associated documentation
84   * ("Software"), with or without modification, are permitted provided that the
85   * following conditions are met:
86   * 
87   * 1. Redistributions of source code must retain copyright statements and
88   * notices. Redistributions must also contain a copy of this document.
89   * 
90   * 2. Redistributions in binary form must reproduce the above copyright notice,
91   * this list of conditions and the following disclaimer in the documentation
92   * and/or other materials provided with the distribution.
93   * 
94   * 3. The name "DOM4J" must not be used to endorse or promote products derived
95   * from this Software without prior written permission of MetaStuff, Ltd. For
96   * written permission, please contact dom4j-info@metastuff.com.
97   * 
98   * 4. Products derived from this Software may not be called "DOM4J" nor may
99   * "DOM4J" appear in their names without prior written permission of MetaStuff,
100  * Ltd. DOM4J is a registered trademark of MetaStuff, Ltd.
101  * 
102  * 5. Due credit should be given to the DOM4J Project - http://www.dom4j.org
103  * 
104  * THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS ``AS IS'' AND
105  * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
106  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
107  * ARE DISCLAIMED. IN NO EVENT SHALL METASTUFF, LTD. OR ITS CONTRIBUTORS BE
108  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
109  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
110  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
111  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
112  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
113  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
114  * POSSIBILITY OF SUCH DAMAGE.
115  * 
116  * Copyright 2001-2005 (C) MetaStuff, Ltd. All Rights Reserved.
117  */