Class Types

java.lang.Object
org.exolab.castor.mapping.loader.Types

public class Types extends Object
Type information. Can be used to map between short type names (such as 'int') and actual Java types (java.lang.Integer), to determine whether a type is simple (i.e. maps to a single XML attribute, SQL column, etc), as well as to create a new instance of a type.
Version:
$Revision: 8670 $ $Date: 2006-04-25 15:08:23 -0600 (Tue, 25 Apr 2006) $
Author:
Assaf Arkin
  • Field Details

    • _typeInfos

      static Types.TypeInfo[] _typeInfos
      List of all the simple types supported by Castor.
  • Constructor Details

    • Types

      public Types()
  • Method Details

    • typeFromName

      public static Class<?> typeFromName(ClassLoader loader, String typeName) throws ClassNotFoundException
      Returns the class name based on the supplied type name. The type name can be a short name (e.g. int, byte) or any other Java class (e.g. myapp.Product). If a short type name is used, the primitive type might be returned. If a Java class name is used, the class will be loaded and returned through the supplied class loader.
      Parameters:
      loader - The class loader to use, may be null
      typeName - The type name
      Returns:
      The type class
      Throws:
      ClassNotFoundException - The specified class could not be found
    • getDefault

      public static Object getDefault(Class<?> type)
      Returns the default value for this Java type (e.g. 0 for integer, empty string) or null if no default value is known. The default value only applies to primitive types (that is, Integer.TYPE but not java.lang.Integer).
      Parameters:
      type - The Java type
      Returns:
      The default value or null
    • typeFromPrimitive

      public static Class<?> typeFromPrimitive(Class<?> type)
      Maps from a primitive Java type to a Java class. Returns the same class if type is not a primitive. The following conversion applies:
       From            To
       --------------  ---------------
       Boolean.TYPE    Boolean.class
       Byte.TYPE       Byte.class
       Character.TYPE  Character.class
       Short.TYPE      Short.class
       Integer.TYPE    Integer.class
       Long.TYPE       Long.class
       Float.TYPE      Float.class
       Double.TYPE     Double.class
       
      Parameters:
      type - The Java type (primitive or not)
      Returns:
      A comparable non-primitive Java type
    • isSimpleType

      public static boolean isSimpleType(Class<?> type)
      Returns true if the Java type is represented as a simple type. A simple can be described with a single XML attribute value, a single SQL column, a single LDAP attribute value, etc. The following types are considered simple:
      • All primitive types
      • String
      • Date
      • java.sql.Date
      • java.sql.Time
      • Timestamp
      • byte/char arrays
      • BigDecimal
      Parameters:
      type - The Java type
      Returns:
      True if a simple type
    • isPrimitiveType

      public static boolean isPrimitiveType(Class<?> type)
      Returns true if the Java type is represented as a primitive type. Wrapper like java.lang.Integer are considered as primitive.
      Parameters:
      type - The Java type
      Returns:
      True if a primitive type
    • addEnumType

      public static void addEnumType(Class<?> type)
    • isEnumType

      public static boolean isEnumType(Class<?> type)
    • addConvertibleType

      public static void addConvertibleType(Class<?> type)
    • isConvertibleType

      public static boolean isConvertibleType(Class<?> type)
    • newInstance

      public static Object newInstance(Class<?> type) throws IllegalStateException
      Constructs a new object from the given class. Does not generate any checked exceptions, since object creation has been proven to work when creating descriptor from mapping.
      Parameters:
      type - The class type of the object instance to be constructed.
      Returns:
      An instance of the class type specified.
      Throws:
      IllegalStateException - The Java object cannot be constructed
    • newInstance

      public static Object newInstance(Class<?> type, Object[] args) throws IllegalStateException
      Constructs a new object from the given class. Does not generate any checked exceptions, since object creation has been proven to work when creating descriptor from mapping.
      Parameters:
      type - The class type of the object instance to be constructed.
      args - Arguments to be supplied to constructor call.
      Returns:
      An instance of the class type specified.
      Throws:
      IllegalStateException - The Java object cannot be constructed
    • isConstructable

      public static boolean isConstructable(Class<?> type)
      Returns true if the objects of this class are constructable. The class must be publicly available and have a default public constructor.
      Parameters:
      type - The Java type
      Returns:
      True if constructable
    • isConstructable

      public static boolean isConstructable(Class<?> type, boolean allowAbstractOrInterface)
      Returns true if the objects of this class are constructable. The class must be publicly available and have a default public constructor.
      Parameters:
      allowAbstractOrInterface - True to indicate that abstract classes of interfaces are allowed.
      type - The Java type
      Returns:
      True if constructable
    • isSerializable

      public static boolean isSerializable(Class<?> type)
      Returns true if the Java type implements the Serializable interface.
      Parameters:
      type - The Java type
      Returns:
      True if declared as serializable
    • isImmutable

      public static boolean isImmutable(Class<?> type)
      Returns true if the Java type is immutable. Immutable objects are not copied.
      Parameters:
      type - The Java type
      Returns:
      True if immutable type
    • isCloneable

      public static boolean isCloneable(Class<?> type)
      Returns true if the Java type implements the Cloneable interface.
      Parameters:
      type - The Java type
      Returns:
      True if declared as cloneable