Package org.exolab.castor.mapping.loader
Class Types
- java.lang.Object
-
- org.exolab.castor.mapping.loader.Types
-
public class Types extends java.lang.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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static class
Types.TypeInfo
Information about a specific Java type.
-
Field Summary
Fields Modifier and Type Field Description (package private) static Types.TypeInfo[]
_typeInfos
List of all the simple types supported by Castor.
-
Constructor Summary
Constructors Constructor Description Types()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
addConvertibleType(java.lang.Class<?> type)
static void
addEnumType(java.lang.Class<?> type)
static java.lang.Object
getDefault(java.lang.Class<?> type)
Returns the default value for this Java type (e.g.static boolean
isCloneable(java.lang.Class<?> type)
Returns true if the Java type implements theCloneable
interface.static boolean
isConstructable(java.lang.Class<?> type)
Returns true if the objects of this class are constructable.static boolean
isConstructable(java.lang.Class<?> type, boolean allowAbstractOrInterface)
Returns true if the objects of this class are constructable.static boolean
isConvertibleType(java.lang.Class<?> type)
static boolean
isEnumType(java.lang.Class<?> type)
static boolean
isImmutable(java.lang.Class<?> type)
Returns true if the Java type is immutable.static boolean
isPrimitiveType(java.lang.Class<?> type)
Returns true if the Java type is represented as a primitive type.static boolean
isSerializable(java.lang.Class<?> type)
Returns true if the Java type implements theSerializable
interface.static boolean
isSimpleType(java.lang.Class<?> type)
Returns true if the Java type is represented as a simple type.static java.lang.Object
newInstance(java.lang.Class<?> type)
Constructs a new object from the given class.static java.lang.Object
newInstance(java.lang.Class<?> type, java.lang.Object[] args)
Constructs a new object from the given class.static java.lang.Class<?>
typeFromName(java.lang.ClassLoader loader, java.lang.String typeName)
Returns the class name based on the supplied type name.static java.lang.Class<?>
typeFromPrimitive(java.lang.Class<?> type)
Maps from a primitive Java type to a Java class.
-
-
-
Field Detail
-
_typeInfos
static Types.TypeInfo[] _typeInfos
List of all the simple types supported by Castor.
-
-
Method Detail
-
typeFromName
public static java.lang.Class<?> typeFromName(java.lang.ClassLoader loader, java.lang.String typeName) throws java.lang.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 nulltypeName
- The type name- Returns:
- The type class
- Throws:
java.lang.ClassNotFoundException
- The specified class could not be found
-
getDefault
public static java.lang.Object getDefault(java.lang.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 java.lang.Class<?> typeFromPrimitive(java.lang.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(java.lang.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(java.lang.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(java.lang.Class<?> type)
-
isEnumType
public static boolean isEnumType(java.lang.Class<?> type)
-
addConvertibleType
public static void addConvertibleType(java.lang.Class<?> type)
-
isConvertibleType
public static boolean isConvertibleType(java.lang.Class<?> type)
-
newInstance
public static java.lang.Object newInstance(java.lang.Class<?> type) throws java.lang.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:
java.lang.IllegalStateException
- The Java object cannot be constructed
-
newInstance
public static java.lang.Object newInstance(java.lang.Class<?> type, java.lang.Object[] args) throws java.lang.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:
java.lang.IllegalStateException
- The Java object cannot be constructed
-
isConstructable
public static boolean isConstructable(java.lang.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(java.lang.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(java.lang.Class<?> type)
Returns true if the Java type implements theSerializable
interface.- Parameters:
type
- The Java type- Returns:
- True if declared as serializable
-
isImmutable
public static boolean isImmutable(java.lang.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(java.lang.Class<?> type)
Returns true if the Java type implements theCloneable
interface.- Parameters:
type
- The Java type- Returns:
- True if declared as cloneable
-
-