001/* 002 * Copyright 2001 (C) MetaStuff, Ltd. All Rights Reserved. 003 * 004 * This software is open source. 005 * See the bottom of this file for the licence. 006 * 007 * $Id: BeanAttribute.java,v 1.2 2001/03/02 11:43:17 jstrachan Exp $ 008 */ 009 010package org.dom4j.bean; 011 012import org.dom4j.Element; 013import org.dom4j.QName; 014import org.dom4j.tree.AbstractAttribute; 015 016/** <p><code>BeanAttribute</code> represents a mutable XML attribute which 017 * is backed by a property of the JavaBean of its parent element.</p> 018 * 019 * @author <a href="mailto:james.strachan@metastuff.com">James Strachan</a> 020 * @version $Revision: 1.2 $ 021 */ 022public class BeanAttribute extends AbstractAttribute { 023 024 /** The list of Bean attributes */ 025 private final BeanAttributeList beanList; 026 027 /** The index in the Bean attribute list */ 028 private final int index; 029 030 031 public BeanAttribute(BeanAttributeList beanList, int index) { 032 this.beanList = beanList; 033 this.index = index; 034 } 035 036 public QName getQName() { 037 return beanList.getQName(index); 038 } 039 040 public Element getParent() { 041 return beanList.getParent(); 042 } 043 044 public String getValue() { 045 Object data = getData(); 046 return ( data != null ) ? data.toString() : null; 047 } 048 049 public void setValue(String data) { 050 beanList.setData(index, data); 051 } 052 053 public Object getData() { 054 return beanList.getData(index); 055 } 056 057 public void setData(Object data) { 058 beanList.setData(index, data); 059 } 060 061} 062 063 064 065 066/* 067 * Redistribution and use of this software and associated documentation 068 * ("Software"), with or without modification, are permitted provided 069 * that the following conditions are met: 070 * 071 * 1. Redistributions of source code must retain copyright 072 * statements and notices. Redistributions must also contain a 073 * copy of this document. 074 * 075 * 2. Redistributions in binary form must reproduce the 076 * above copyright notice, this list of conditions and the 077 * following disclaimer in the documentation and/or other 078 * materials provided with the distribution. 079 * 080 * 3. The name "DOM4J" must not be used to endorse or promote 081 * products derived from this Software without prior written 082 * permission of MetaStuff, Ltd. For written permission, 083 * please contact dom4j-info@metastuff.com. 084 * 085 * 4. Products derived from this Software may not be called "DOM4J" 086 * nor may "DOM4J" appear in their names without prior written 087 * permission of MetaStuff, Ltd. DOM4J is a registered 088 * trademark of MetaStuff, Ltd. 089 * 090 * 5. Due credit should be given to the DOM4J Project 091 * (http://dom4j.org/). 092 * 093 * THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS 094 * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT 095 * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 096 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 097 * METASTUFF, LTD. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 098 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 099 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 100 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 101 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 102 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 103 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 104 * OF THE POSSIBILITY OF SUCH DAMAGE. 105 * 106 * Copyright 2001 (C) MetaStuff, Ltd. All Rights Reserved. 107 * 108 * $Id: BeanAttribute.java,v 1.2 2001/03/02 11:43:17 jstrachan Exp $ 109 */