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.bean;
9   
10  import org.dom4j.Element;
11  import org.dom4j.QName;
12  import org.dom4j.tree.AbstractAttribute;
13  
14  /***
15   * <p>
16   * <code>BeanAttribute</code> represents a mutable XML attribute which is
17   * backed by a property of the JavaBean of its parent element.
18   * </p>
19   * 
20   * @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a>
21   * @version $Revision: 1.7 $
22   */
23  public class BeanAttribute extends AbstractAttribute {
24      /*** The list of Bean attributes */
25      private final BeanAttributeList beanList;
26  
27      /*** The index in the Bean attribute list */
28      private final int index;
29  
30      public BeanAttribute(BeanAttributeList beanList, int index) {
31          this.beanList = beanList;
32          this.index = index;
33      }
34  
35      public QName getQName() {
36          return beanList.getQName(index);
37      }
38  
39      public Element getParent() {
40          return beanList.getParent();
41      }
42  
43      public String getValue() {
44          Object data = getData();
45  
46          return (data != null) ? data.toString() : null;
47      }
48  
49      public void setValue(String data) {
50          beanList.setData(index, data);
51      }
52  
53      public Object getData() {
54          return beanList.getData(index);
55      }
56  
57      public void setData(Object data) {
58          beanList.setData(index, data);
59      }
60  }
61  
62  /*
63   * Redistribution and use of this software and associated documentation
64   * ("Software"), with or without modification, are permitted provided that the
65   * following conditions are met:
66   * 
67   * 1. Redistributions of source code must retain copyright statements and
68   * notices. Redistributions must also contain a copy of this document.
69   * 
70   * 2. Redistributions in binary form must reproduce the above copyright notice,
71   * this list of conditions and the following disclaimer in the documentation
72   * and/or other materials provided with the distribution.
73   * 
74   * 3. The name "DOM4J" must not be used to endorse or promote products derived
75   * from this Software without prior written permission of MetaStuff, Ltd. For
76   * written permission, please contact dom4j-info@metastuff.com.
77   * 
78   * 4. Products derived from this Software may not be called "DOM4J" nor may
79   * "DOM4J" appear in their names without prior written permission of MetaStuff,
80   * Ltd. DOM4J is a registered trademark of MetaStuff, Ltd.
81   * 
82   * 5. Due credit should be given to the DOM4J Project - http://www.dom4j.org
83   * 
84   * THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS ``AS IS'' AND
85   * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
86   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
87   * ARE DISCLAIMED. IN NO EVENT SHALL METASTUFF, LTD. OR ITS CONTRIBUTORS BE
88   * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
89   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
90   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
91   * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
92   * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
93   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
94   * POSSIBILITY OF SUCH DAMAGE.
95   * 
96   * Copyright 2001-2005 (C) MetaStuff, Ltd. All Rights Reserved.
97   */