View Javadoc
1 /* 2 * Copyright (C) 2002 Carsten Krebs (Team-Konzept GmbH & Co.KG) 3 * 4 * This library is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU Lesser General Public 6 * License as published by the Free Software Foundation; either 7 * version 2.1 of the License, or (at your option) any later version. 8 * 9 * This library is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 * Lesser General Public License for more details. 13 * 14 * You should have received a copy of the GNU Lesser General Public 15 * License along with this library; if not, write to the Free Software 16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 */ 18 package com.teamkonzept.dom4jb.schema; 19 20 import java.beans.IntrospectionException; 21 import java.beans.PropertyDescriptor; 22 23 import com.teamkonzept.dom4jb.DOM4JBException; 24 import com.teamkonzept.dom4jb.beans.Introspector; 25 import com.teamkonzept.dom4jb.beans.SimpleProperty; 26 import com.teamkonzept.dom4jb.beans.XMLBeanInfo; 27 import com.teamkonzept.dom4jb.dom.Document; 28 import com.teamkonzept.dom4jb.dom.Node; 29 import com.teamkonzept.dom4jb.dom.NodeName; 30 31 public class AttributeDescriptor extends SimpleProperty { 32 33 protected final NodeName name; 34 35 public AttributeDescriptor( final NodeName name, 36 final PropertyDescriptor property ) { 37 super( property ); 38 this.name = name; 39 } 40 41 protected AttributeDescriptor( final String name, 42 final PropertyDescriptor property ) { 43 this( NodeName.getInstance( name ), property ); 44 } 45 46 public AttributeDescriptor( final PropertyDescriptor property ) { 47 this( property.getName(), property ); 48 } 49 50 public AttributeDescriptor( final String name, final Class beanClass ) 51 throws IntrospectionException { 52 this( name, getProperty( name, beanClass ) ); 53 } 54 55 public AttributeDescriptor( final String attrName, 56 final String propertyName, 57 final Class beanClass ) 58 throws IntrospectionException { 59 this( attrName, getProperty( propertyName, beanClass ) ); 60 } 61 62 63 protected final DataDescriptor getDescriptor(final Object obj) { 64 if ( obj != null ) { 65 try { 66 final XMLBeanInfo info = Introspector.getBeanInfo( obj.getClass() ); 67 final DataDescriptor descriptor = info.getDataDescriptor(); 68 69 if ( descriptor != null ) { 70 return descriptor; 71 } 72 } catch ( IntrospectionException e ) { 73 throw new DOM4JBException( e ); 74 } 75 } 76 return DataDescriptor.STRING; 77 } 78 79 public NodeName getName() { 80 return this.name; 81 } 82 83 public Node getContent( final Document document, final Object bean ) { 84 return document.createAttribute( this, bean ); 85 } 86 87 public String toString() { 88 final StringBuffer buf = new StringBuffer( "Attribute(" ); 89 buf.append( name.toString() ); 90 buf.append( ':' ); 91 buf.append( super.toString() ); 92 buf.append( ')' ); 93 return buf.toString(); 94 } 95 96 }

This page was automatically generated by Maven