1 package org.codehaus.xfire.aegis.type.java5;
2
3 import java.beans.PropertyDescriptor;
4
5 import javax.xml.namespace.QName;
6
7 import org.codehaus.xfire.aegis.type.TypeMapping;
8 import org.codehaus.xfire.aegis.type.basic.BeanTypeInfo;
9 import org.codehaus.xfire.util.NamespaceHelper;
10
11 public class AnnotatedTypeInfo
12 extends BeanTypeInfo
13 {
14 public AnnotatedTypeInfo(TypeMapping tm, Class typeClass)
15 {
16 super(typeClass);
17 setTypeMapping(tm);
18
19 initialize();
20 }
21
22 protected boolean isAttribute(PropertyDescriptor desc)
23 {
24 return desc.getReadMethod().isAnnotationPresent(XmlAttribute.class);
25 }
26
27 protected boolean isElement(PropertyDescriptor desc)
28 {
29 return !isAttribute(desc);
30 }
31
32 protected boolean isAnnotatedElement(PropertyDescriptor desc)
33 {
34 return desc.getReadMethod().isAnnotationPresent(XmlElement.class);
35 }
36
37 @Override
38 protected String createMappedName(PropertyDescriptor desc)
39 {
40 return createQName(desc).getLocalPart();
41 }
42
43 protected QName createQName(PropertyDescriptor desc)
44 {
45 String name = null;
46 String ns = null;
47
48 XmlType xtype = (XmlType) getTypeClass().getAnnotation(XmlType.class);
49 if (xtype != null)
50 {
51 ns = xtype.namespace();
52 }
53
54 if (isAttribute(desc))
55 {
56 XmlAttribute att = desc.getReadMethod().getAnnotation(XmlAttribute.class);
57 name = att.name();
58 if (att.namespace().length() > 0) ns = att.namespace();
59 }
60 else if (isAnnotatedElement(desc))
61 {
62 XmlElement att = desc.getReadMethod().getAnnotation(XmlElement.class);
63 name = att.name();
64 if (att.namespace().length() > 0) ns = att.namespace();
65 }
66
67 if (name == null || name.length() == 0)
68 name = desc.getName();
69
70 if (ns == null || ns.length() == 0)
71 ns = NamespaceHelper.makeNamespaceFromClassName( getTypeClass().getName(), "http");
72
73 return new QName(ns, name);
74 }
75
76 public boolean isNillable(String name)
77 {
78 PropertyDescriptor desc = getPropertyDescriptorFromMappedName(name);
79
80 if (isAnnotatedElement(desc))
81 {
82 XmlElement att = desc.getReadMethod().getAnnotation(XmlElement.class);
83 return att.nillable();
84 }
85 else
86 {
87 return super.isNillable(name);
88 }
89 }
90 }