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
30 public class CDATADescriptor extends SimpleProperty {
31
32 /*** Creates new CDATADescriptor */
33 public CDATADescriptor( final PropertyDescriptor property ) {
34 super ( property );
35 }
36
37 /*** Creates new CDATADescriptor */
38 public CDATADescriptor( final String name, final Class beanClass )
39 throws IntrospectionException {
40 this( new PropertyDescriptor( name, beanClass ) );
41 }
42
43 protected DataDescriptor getDescriptor( final Object obj ) {
44 if ( obj != null ) {
45 try {
46 final XMLBeanInfo info = Introspector.getBeanInfo( obj.getClass() );
47 final DataDescriptor descriptor = info.getDataDescriptor();
48
49 if ( descriptor != null ) {
50 return descriptor;
51 }
52 } catch ( IntrospectionException e ) {
53 throw new DOM4JBException( e );
54 }
55 }
56 return DataDescriptor.STRING;
57 }
58
59 public Node getContent( final Document document, final Object bean ) {
60 return document.createCDATASection( this, bean );
61 }
62 }
This page was automatically generated by Maven