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.basic.BeanTypeInfo;
8 import org.codehaus.xfire.util.NamespaceHelper;
9
10 public class AnnotatedTypeInfo
11 extends BeanTypeInfo
12 {
13 public AnnotatedTypeInfo(Class typeClass)
14 {
15 super(typeClass);
16
17 initialize();
18 }
19
20 protected boolean isAttribute(PropertyDescriptor desc)
21 {
22 return desc.getReadMethod().isAnnotationPresent(XmlAttribute.class);
23 }
24
25 protected boolean isElement(PropertyDescriptor desc)
26 {
27 return !isAttribute(desc);
28 }
29
30 protected boolean isAnnotatedElement(PropertyDescriptor desc)
31 {
32 return desc.getReadMethod().isAnnotationPresent(XmlElement.class);
33 }
34
35 protected QName createQName(PropertyDescriptor desc)
36 {
37 String name = null;
38 String ns = null;
39
40 XmlType xtype = (XmlType) getTypeClass().getAnnotation(XmlType.class);
41 if (xtype != null)
42 {
43 ns = xtype.namespace();
44 }
45
46 if (isAttribute(desc))
47 {
48 XmlAttribute att = desc.getReadMethod().getAnnotation(XmlAttribute.class);
49 name = att.name();
50 if (att.namespace().length() > 0) ns = att.namespace();
51 }
52 else if (isAnnotatedElement(desc))
53 {
54 XmlElement att = desc.getReadMethod().getAnnotation(XmlElement.class);
55 name = att.name();
56 if (att.namespace().length() > 0) ns = att.namespace();
57 }
58
59 if (name == null || name.length() == 0)
60 name = desc.getName();
61
62 if (ns == null || ns.length() == 0)
63 ns = NamespaceHelper.makeNamespaceFromClassName( getTypeClass().getName(), "http");
64
65 return new QName(ns, name);
66 }
67
68 public boolean isNillable(QName name)
69 {
70 return super.isNillable(name);
71 }
72 }