View Javadoc

    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      protected QName createQName(PropertyDescriptor desc)
    38      {
    39          String name = null;
    40          String ns = null;
    41
    42          XmlType xtype = (XmlType) getTypeClass().getAnnotation(XmlType.class);
    43          if (xtype != null)
    44          {
    45              ns = xtype.namespace();
    46          }
    47
    48          if (isAttribute(desc))
    49          {
    50              XmlAttribute att = desc.getReadMethod().getAnnotation(XmlAttribute.class);
    51              name = att.name();
    52              if (att.namespace().length() > 0) ns = att.namespace();
    53          }
    54          else if (isAnnotatedElement(desc))
    55          {
    56              XmlElement att = desc.getReadMethod().getAnnotation(XmlElement.class);
    57              name = att.name();
    58              if (att.namespace().length() > 0) ns = att.namespace();
    59          }
    60
    61          if (name == null || name.length() == 0)
    62              name = desc.getName();
    63
    64          if (ns == null || ns.length() == 0)
    65              ns = NamespaceHelper.makeNamespaceFromClassName( getTypeClass().getName(), "http");
    66
    67          return new QName(ns, name);
    68      }
    69
    70      public boolean isNillable(QName name)
    71      {
    72          return super.isNillable(name);
    73      }
    74  }