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 import java.lang.reflect.InvocationTargetException;
23 import java.util.List;
24
25 import com.teamkonzept.dom4jb.DOM4JBException;
26 import com.teamkonzept.dom4jb.beans.Introspector;
27 import com.teamkonzept.dom4jb.beans.Property;
28 import com.teamkonzept.dom4jb.beans.XMLBeanInfo;
29 import com.teamkonzept.dom4jb.dom.Document;
30
31 /*** %REVIEW%
32 *
33 */
34 public class ContentDescriptor extends GroupDescriptor {
35
36 private static final Object[] NO_PARAMS = new Object[0];
37
38 private final PropertyDescriptor property;
39
40 public ContentDescriptor( final String name, final Class beanClass )
41 throws IntrospectionException {
42 this.property = Property.getProperty( name, beanClass );
43 }
44
45 public ContentIterator getContentIterator( final Document doc,
46 final Object bean ) {
47 try {
48 final Object obj = getObject( bean );
49
50 if ( obj != null ) {
51 final XMLBeanInfo info = Introspector.getBeanInfo( obj.getClass() );
52 final GroupDescriptor descriptor = info.getContentDescriptors();
53
54 if ( descriptor != null ) {
55 return descriptor.getContentIterator( doc, obj );
56 }
57 }
58 } catch ( IntrospectionException e ) {
59 throw new DOM4JBException( e );
60 } catch ( IllegalAccessException e ) {
61 throw new DOM4JBException( e );
62 } catch ( InvocationTargetException e ) {
63 throw new DOM4JBException( e );
64 }
65
66 return null; // %REVIEW% /* GroupNode.EMPTY_DESCRIPTOR; */
67 }
68
69 public boolean isEmpty() {
70 return false;
71 }
72
73 protected final Object getObject( final Object bean )
74 throws IllegalAccessException,
75 InvocationTargetException {
76 return property.getReadMethod().invoke( bean, NO_PARAMS );
77 }
78
79 public void addTo( final List list ) {
80 list.add( this );
81 }
82 }
This page was automatically generated by Maven