Class ObjectType

java.lang.Object
org.apache.ofbiz.base.util.ObjectType

public class ObjectType extends Object
Utilities for analyzing and converting Object types in Java Takes advantage of reflection
  • Field Details

    • NULL

      public static final Object NULL
  • Constructor Details

    • ObjectType

      public ObjectType()
  • Method Details

    • loadClass

      public static Class<?> loadClass(String className) throws ClassNotFoundException
      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 load
      loader - The ClassLoader to use
      Returns:
      The requested class
      Throws:
      ClassNotFoundException
    • getInstance

      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

      public static boolean instanceOf(Class<?> objectClass, String typeName)
      Tests if a class is a class of a sub-class of or properly implements an interface.
      Parameters:
      objectClass - Class to test
      typeName - name to test against
      Returns:
      true if objectClass is a class or a sub-class of, or properly implements an interface
    • instanceOf

      public static boolean instanceOf(Object obj, String typeName)
      Tests if an object is an instance of a sub-class of or properly implements an interface.
      Parameters:
      obj - Object to test
      typeName - name to test against
      Returns:
      true if obj is an instance of a sub-class of, or properly implements an interface
    • instanceOf

      public 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.
      Parameters:
      objectClass - Class to test
      typeName - Object to test against
      loader -
      Returns:
      true if objectClass is a class of a sub-class of, or properly implements an interface
    • instanceOf

      public 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.
      Parameters:
      obj - Object to test
      typeName - Object to test against
      loader -
      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 convert
      type - Optional Java class name of type to convert to. A null or empty String will return the original object.
      format - Optional (can be null) format string for Date, Time, Timestamp
      timeZone - Optional (can be null) TimeZone for converting dates and times
      locale - Optional (can be null) Locale for formatting and parsing Double, Float, Long, Integer
      noTypeFail - 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

      public static Boolean doRealCompare(Object value1, Object value2, String operator, String type, String format, List<Object> messages, Locale locale, ClassLoader loader, boolean value2InlineConstant)
    • isEmpty

      public static boolean isEmpty(Object value)