View Javadoc

    1   package org.codehaus.xfire.aegis.type.java5;
    2
    3   import java.beans.PropertyDescriptor;
    4   import java.lang.reflect.Method;
    5   import java.lang.reflect.ParameterizedType;
    6
    7   import javax.xml.namespace.QName;
    8
    9   import org.codehaus.xfire.aegis.type.AbstractTypeCreator;
    10  import org.codehaus.xfire.aegis.type.Type;
    11  import org.codehaus.xfire.util.NamespaceHelper;
    12
    13  public class Java5TypeCreator
    14      extends AbstractTypeCreator
    15  {
    16
    17      @Override
    18      public TypeClassInfo createClassInfo(Method m, int index)
    19      {
    20          if (index >= 0)
    21          {
    22              TypeClassInfo info;
    23              java.lang.reflect.Type genericType = m.getGenericParameterTypes()[index];
    24              if(genericType instanceof Class)
    25              {
    26                  info = nextCreator.createClassInfo(m, index);
    27              }
    28              else
    29              {
    30                  info = new TypeClassInfo();
    31                  info.setGenericType(genericType);
    32              }
    33              info.setTypeClass(m.getParameterTypes()[index]);
    34              if(m.getParameterAnnotations()[index].length > 0)
    35                  info.setAnnotations(m.getParameterAnnotations()[index]);
    36              return info;
    37          }
    38          else
    39          {
    40              java.lang.reflect.Type genericReturnType = m.getGenericReturnType();
    41              TypeClassInfo info;
    42              if(genericReturnType instanceof Class)
    43              {
    44                  info = nextCreator.createClassInfo(m, index);
    45              }
    46              else
    47              {
    48                  info = new TypeClassInfo();
    49                  info.setGenericType(genericReturnType);
    50              }
    51              info.setTypeClass(m.getReturnType());
    52              if(m.getAnnotations().length > 0)
    53                  info.setAnnotations(m.getAnnotations());
    54              return info;
    55          }
    56      }
    57
    58      @Override
    59      public TypeClassInfo createClassInfo(PropertyDescriptor pd)
    60      {
    61          TypeClassInfo info = createBasicClassInfo(pd.getPropertyType());
    62          info.setGenericType(pd.getReadMethod().getGenericReturnType());
    63          info.setAnnotations(pd.getReadMethod().getAnnotations());
    64
    65          return info;
    66      }
    67
    68      @Override
    69      public Type createCollectionType(TypeClassInfo info)
    70      {
    71          Object genericType = info.getGenericType();
    72          Class paramClass = Object.class;
    73          if (genericType instanceof ParameterizedType)
    74          {
    75              ParameterizedType type = (ParameterizedType) genericType;
    76
    77              if (type.getActualTypeArguments()[0] instanceof Class)
    78              {
    79                  paramClass = (Class) type.getActualTypeArguments()[0];
    80              }
    81          }
    82
    83          return super.createCollectionType(info, paramClass);
    84      }
    85
    86      @Override
    87      public Type createDefaultType(TypeClassInfo info)
    88      {
    89          AnnotatedType type = new AnnotatedType(info.getTypeClass());
    90          type.setTypeMapping(getTypeMapping());
    91
    92          return type;
    93      }
    94
    95      @Override
    96      public Type createEnumType(TypeClassInfo info)
    97      {
    98          EnumType type = new EnumType();
    99
    100         String name = info.getTypeClass().getSimpleName();
    101         String ns = NamespaceHelper.makeNamespaceFromClassName(info.getTypeClass().getName(), "http");
    102
    103         type.setSchemaType(new QName(ns, name));
    104         type.setTypeClass(info.getTypeClass());
    105         type.setTypeMapping(getTypeMapping());
    106
    107         return type;
    108     }
    109
    110     @Override
    111     protected boolean isEnum(Class javaType)
    112     {
    113         return javaType.isEnum();
    114     }
    115 }