Package org.apache.ofbiz.base.util
Class ObjectType
java.lang.Object
org.apache.ofbiz.base.util.ObjectType
Utilities for analyzing and converting Object types in Java
Takes advantage of reflection
-
Nested Class Summary
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic Boolean
doRealCompare
(Object value1, Object value2, String operator, String type, String format, List<Object> messages, Locale locale, ClassLoader loader, boolean value2InlineConstant) static Object
getInstance
(String className) Returns an instance of the specified class.static boolean
instanceOf
(Class<?> objectClass, String typeName) Tests if a class is a class of a sub-class of or properly implements an interface.static boolean
instanceOf
(Class<?> objectClass, String typeName, ClassLoader loader) Tests if a class is a class of a sub-class of or properly implements an interface.static boolean
instanceOf
(Object obj, String typeName) Tests if an object is an instance of a sub-class of or properly implements an interface.static boolean
instanceOf
(Object obj, String typeName, ClassLoader loader) Tests if an object is an instance of a sub-class of or properly implements an interface.static boolean
static Class<?>
Loads a class with the current thread's context classloader.static Class<?>
loadClass
(String className, ClassLoader loader) Loads a class with the specified classloader.static Object
simpleTypeOrObjectConvert
(Object obj, String type, String format, Locale locale) static Object
simpleTypeOrObjectConvert
(Object obj, String type, String format, Locale locale, boolean noTypeFail) static Object
simpleTypeOrObjectConvert
(Object obj, String type, String format, TimeZone timeZone, Locale locale, boolean noTypeFail) Converts the passed object to the named type.
-
Field Details
-
NULL
-
-
Constructor Details
-
ObjectType
public ObjectType()
-
-
Method Details
-
loadClass
Loads a class with the current thread's context classloader.- Parameters:
className
- The name of the class to load- Returns:
- The requested class
- Throws:
ClassNotFoundException
-
loadClass
public static Class<?> loadClass(String className, ClassLoader loader) throws ClassNotFoundException Loads a class with the specified classloader.- Parameters:
className
- The name of the class to loadloader
- The ClassLoader to use- Returns:
- The requested class
- Throws:
ClassNotFoundException
-
getInstance
public static Object getInstance(String className) throws ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException Returns an instance of the specified class. This uses the default no-arg constructor to create the instance.- Parameters:
className
- Name of the class to instantiate- Returns:
- An instance of the named class
- Throws:
ClassNotFoundException
InstantiationException
IllegalAccessException
NoSuchMethodException
InvocationTargetException
-
instanceOf
Tests if a class is a class of a sub-class of or properly implements an interface.- Parameters:
objectClass
- Class to testtypeName
- name to test against- Returns:
- true if objectClass is a class or a sub-class of, or properly implements an interface
-
instanceOf
Tests if an object is an instance of a sub-class of or properly implements an interface.- Parameters:
obj
- Object to testtypeName
- name to test against- Returns:
- true if obj is an instance of a sub-class of, or properly implements an interface
-
instanceOf
Tests if a class is a class of a sub-class of or properly implements an interface.- Parameters:
objectClass
- Class to testtypeName
- Object to test againstloader
-- Returns:
- true if objectClass is a class of a sub-class of, or properly implements an interface
-
instanceOf
Tests if an object is an instance of a sub-class of or properly implements an interface.- Parameters:
obj
- Object to testtypeName
- Object to test againstloader
-- Returns:
- true if obj is an instance of a sub-class of, or properly implements an interface
-
simpleTypeOrObjectConvert
public static Object simpleTypeOrObjectConvert(Object obj, String type, String format, Locale locale, boolean noTypeFail) throws GeneralException - Throws:
GeneralException
-
simpleTypeOrObjectConvert
public static Object simpleTypeOrObjectConvert(Object obj, String type, String format, TimeZone timeZone, Locale locale, boolean noTypeFail) throws GeneralException Converts the passed object to the named type. Initially created for only simple types but actually handle more types and not all simple types. See ObjectTypeTests class for more, and (normally) up to date information Supported types: - All PRIMITIVES - Simple types: String, Boolean, Double, Float, Long, Integer, BigDecimal. - Other Objects: List, Map, Set, Calendar, Date (java.sql.Date), Time, Timestamp, TimeZone, Date (util.Date and sql.Date) - Simple types (maybe) not handled: Short, BigInteger, Byte, Character, ObjectName and Void...- Parameters:
obj
- Object to converttype
- Optional Java class name of type to convert to. Anull
or emptyString
will return the original object.format
- Optional (can be null) format string for Date, Time, TimestamptimeZone
- Optional (can be null) TimeZone for converting dates and timeslocale
- Optional (can be null) Locale for formatting and parsing Double, Float, Long, IntegernoTypeFail
- Fail (Exception) when no type conversion is available, false will return the primary object- Returns:
- the converted value
- Throws:
GeneralException
-
simpleTypeOrObjectConvert
public static Object simpleTypeOrObjectConvert(Object obj, String type, String format, Locale locale) throws GeneralException - Throws:
GeneralException
-
doRealCompare
-
isEmpty
-