View Javadoc

    1   package org.codehaus.xfire.xmlbeans;
    2
    3   import java.beans.PropertyDescriptor;
    4   import java.lang.reflect.Field;
    5   import java.lang.reflect.Method;
    6
    7   import org.apache.xmlbeans.XmlObject;
    8   import org.codehaus.xfire.aegis.type.Type;
    9   import org.codehaus.xfire.aegis.type.TypeCreator;
    10  import org.codehaus.xfire.aegis.type.TypeMapping;
    11
    12  public class XmlBeansTypeCreator
    13      implements TypeCreator
    14  {
    15      private TypeCreator nextCreator;
    16      private TypeMapping typeMapping;
    17
    18      public XmlBeansTypeCreator(TypeCreator nextCreator)
    19      {
    20          this.nextCreator = nextCreator;
    21      }
    22
    23      public TypeMapping getTypeMapping()
    24      {
    25          return typeMapping;
    26      }
    27
    28      public Type createType(Method m, int index)
    29      {
    30          Class clazz = null;
    31          if (index > -1)
    32          {
    33              clazz = m.getParameterTypes()[index];
    34          }
    35          else
    36          {
    37              clazz = m.getReturnType();
    38          }
    39
    40          if (isXmlBean(clazz))
    41          {
    42              return createXmlBeanType(clazz);
    43          }
    44          else
    45          {
    46              System.out.println(nextCreator);
    47              return nextCreator.createType(m, index);
    48          }
    49      }
    50
    51      protected Type createXmlBeanType(Class clazz)
    52      {
    53          return new XmlBeansType(clazz);
    54      }
    55
    56      private boolean isXmlBean(Class clazz)
    57      {
    58          return XmlObject.class.isAssignableFrom(clazz);
    59      }
    60
    61      public Type createType(PropertyDescriptor pd)
    62      {
    63          Class clazz = pd.getPropertyType();
    64          if (isXmlBean(clazz))
    65          {
    66              return createXmlBeanType(clazz);
    67          }
    68          else
    69          {
    70              return nextCreator.createType(pd);
    71          }
    72      }
    73
    74      public Type createType(Field f)
    75      {
    76          Class clazz = f.getType();
    77          if (isXmlBean(clazz))
    78          {
    79              return createXmlBeanType(clazz);
    80          }
    81          else
    82          {
    83              return nextCreator.createType(f);
    84          }
    85      }
    86
    87      public Type createType(Class clazz)
    88      {
    89          if (isXmlBean(clazz))
    90          {
    91              return createXmlBeanType(clazz);
    92          }
    93          else
    94          {
    95              return nextCreator.createType(clazz);
    96          }
    97      }
    98
    99      public void setTypeMapping(TypeMapping typeMapping)
    100     {
    101         this.typeMapping = typeMapping;
    102
    103         nextCreator.setTypeMapping(typeMapping);
    104     }
    105 }