View Javadoc

    1   package org.codehaus.xfire.jaxb;
    2
    3   import org.codehaus.xfire.aegis.type.Type;
    4   import org.codehaus.xfire.aegis.type.TypeCreator;
    5   import org.codehaus.xfire.aegis.type.TypeMapping;
    6
    7   import javax.xml.bind.Element;
    8   import javax.xml.bind.JAXBContext;
    9   import java.beans.PropertyDescriptor;
    10  import java.lang.reflect.Field;
    11  import java.lang.reflect.Method;
    12
    13  /***
    14   * User: chris
    15   * Date: Aug 12, 2005
    16   * Time: 5:32:07 PM
    17   */
    18  public class JaxbTypeCreator implements TypeCreator
    19  {
    20      private TypeCreator nextCreator;
    21      private JAXBContext jaxbContext;
    22      private TypeMapping typeMapping;
    23
    24      public JaxbTypeCreator(TypeCreator nextCreator, JAXBContext jaxbContext)
    25      {
    26          this.nextCreator = nextCreator;
    27          this.jaxbContext = jaxbContext;
    28      }
    29
    30      public Type createType(Method m, int index)
    31      {
    32          Class clazz = null;
    33          if (index > -1)
    34          {
    35              clazz = m.getParameterTypes()[index];
    36          } else
    37          {
    38              clazz = m.getReturnType();
    39          }
    40
    41          if (isJaxbType(clazz))
    42          {
    43              return createJaxbType(clazz);
    44          } else
    45          {
    46              System.out.println(nextCreator);
    47              return nextCreator.createType(m, index);
    48          }
    49      }
    50
    51      public static boolean isJaxbType(Class clazz)
    52      {
    53          return Element.class.isAssignableFrom(clazz);
    54      }
    55
    56      private Type createJaxbType(Class clazz)
    57      {
    58          return new JaxbType(clazz, jaxbContext);  //To change body of created methods use File | Settings | File Templates.
    59      }
    60
    61      public Type createType(PropertyDescriptor pd)
    62      {
    63          Class clazz = pd.getPropertyType();
    64          if (isJaxbType(clazz))
    65          {
    66              return createJaxbType(clazz);
    67          } else
    68          {
    69              return nextCreator.createType(pd);
    70          }
    71      }
    72
    73      public Type createType(Field f)
    74      {
    75          Class clazz = f.getType();
    76          if (isJaxbType(clazz))
    77          {
    78              return createJaxbType(clazz);
    79          } else
    80          {
    81              return nextCreator.createType(f);
    82          }
    83      }
    84
    85      public Type createType(Class clazz)
    86      {
    87          if (isJaxbType(clazz))
    88          {
    89              return createJaxbType(clazz);
    90          } else
    91          {
    92              return nextCreator.createType(clazz);
    93          }
    94      }
    95
    96      public void setTypeMapping(TypeMapping typeMapping)
    97      {
    98          this.typeMapping = typeMapping;
    99
    100         nextCreator.setTypeMapping(typeMapping);
    101     }
    102
    103 }