Package org.exolab.castor.mapping.loader
Class Types
java.lang.Object
org.exolab.castor.mapping.loader.Types
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: 9061 $ $Date: 2006-04-25 15:08:23 -0600 (Tue, 25 Apr 2006) $
- Author:
- Assaf Arkin
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic void
addConvertibleType
(Class<?> type) static void
addEnumType
(Class<?> type) static Object
getDefault
(Class<?> type) Returns the default value for this Java type (e.g.static boolean
isCloneable
(Class<?> type) Returns true if the Java type implements theCloneable
interface.static boolean
isConstructable
(Class<?> type) Returns true if the objects of this class are constructable.static boolean
isConstructable
(Class<?> type, boolean allowAbstractOrInterface) Returns true if the objects of this class are constructable.static boolean
isConvertibleType
(Class<?> type) static boolean
isEnumType
(Class<?> type) static boolean
isImmutable
(Class<?> type) Returns true if the Java type is immutable.static boolean
isPrimitiveType
(Class<?> type) Returns true if the Java type is represented as a primitive type.static boolean
isSerializable
(Class<?> type) Returns true if the Java type implements theSerializable
interface.static boolean
isSimpleType
(Class<?> type) Returns true if the Java type is represented as a simple type.static Object
newInstance
(Class<?> type) Constructs a new object from the given class.static Object
newInstance
(Class<?> type, Object[] args) Constructs a new object from the given class.static Class<?>
typeFromName
(ClassLoader loader, String typeName) Returns the class name based on the supplied type name.static Class<?>
typeFromPrimitive
(Class<?> type) Maps from a primitive Java type to a Java class.
-
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 nulltypeName
- The type name- Returns:
- The type class
- Throws:
ClassNotFoundException
- The specified class could not be found
-
getDefault
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
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
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
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
-
isEnumType
-
addConvertibleType
-
isConvertibleType
-
newInstance
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
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
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
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 typeallowAbstractOrInterface
- True to indicate that abstract classes of interfaces are allowed.- Returns:
- True if constructable
-
isSerializable
Returns true if the Java type implements theSerializable
interface.- Parameters:
type
- The Java type- Returns:
- True if declared as serializable
-
isImmutable
Returns true if the Java type is immutable. Immutable objects are not copied.- Parameters:
type
- The Java type- Returns:
- True if immutable type
-
isCloneable
Returns true if the Java type implements theCloneable
interface.- Parameters:
type
- The Java type- Returns:
- True if declared as cloneable
-