Interface ClassUtil


public interface ClassUtil
  • Method Details

    • loadClass

      Class<?> loadClass(String className) throws IOException
      loads Class that match given classname, this Class can be from the Lucee core as well
      Parameters:
      className - name of the Class to load
      Returns:
      Class
      Throws:
      IOException - IO Exception
    • loadClass

      Class<?> loadClass(PageContext pc, String className, String bundleName, String bundleVersion) throws org.osgi.framework.BundleException, IOException
      loads Class that match given classname and the given bundle name and version, this Class can be from the Lucee core as well
      Parameters:
      pc - Page Context
      className - name of the Class to load
      bundleName - name of the bundle to load from
      bundleVersion - version of the bundle to load from (if null ignored)
      Returns:
      class
      Throws:
      org.osgi.framework.BundleException - Bundle Exception
      IOException - IO Exception
    • loadBIF

      Throws:
      InstantiationException
      IllegalAccessException
    • isInstaneOf

      boolean isInstaneOf(String srcClassName, Class<?> trg)
      check if Class is instanceof another Class
      Parameters:
      srcClassName - class name to check
      trg - class to check
      Returns:
      is instance of
    • isInstaneOf

      boolean isInstaneOf(String srcClassName, String trgClassName)
      Parameters:
      srcClassName - class name to check
      trgClassName - class name to check
      Returns:
      is instance of
    • isInstaneOf

      boolean isInstaneOf(Class<?> src, String trgClassName)
      check if Class is instanceof another Class
      Parameters:
      src - is Class of?
      trgClassName - Class name to check
      Returns:
      is Class Class of...
    • isInstaneOfIgnoreCase

      boolean isInstaneOfIgnoreCase(Class<?> src, String trg)
    • isInstaneOf

      boolean isInstaneOf(Class<?> src, Class<?> trg)
      check if Class is instanceof another Class
      Parameters:
      src - Class to check
      trg - is Class of ?
      Returns:
      is Class Class of...
    • getClasses

      Class<?>[] getClasses(Object[] objs)
      get all Classes from an Object Array
      Parameters:
      objs - Objects to get
      Returns:
      classes from Objects
    • toReferenceClass

      Class<?> toReferenceClass(Class<?> c)
      convert a primitive Class Type to a Reference Type (Example: int to java.lang.Integer)
      Parameters:
      c - Class to convert
      Returns:
      converted Class (if primitive)
    • like

      boolean like(Class<?> src, Class<?> trg)
      checks if src Class is "like" trg class
      Parameters:
      src - Source Class
      trg - Target Class
      Returns:
      is similar
    • convert

      Object convert(Object src, Class<?> trgClass, RefInteger rating) throws PageException
      convert Object from src to trg Type, if possible
      Parameters:
      src - Object to convert
      trgClass - Target Class
      rating - rating
      Returns:
      converted Object
      Throws:
      PageException - Page Exception
    • getFieldsIgnoreCase

      Field[] getFieldsIgnoreCase(Class<?> clazz, String name) throws NoSuchFieldException
      same like method getField from Class but ignore case from field name
      Parameters:
      clazz - Class to search the field
      name - name to search
      Returns:
      Matching Field
      Throws:
      NoSuchFieldException - No Such Field Exception
    • getFieldsIgnoreCase

      Field[] getFieldsIgnoreCase(Class<?> clazz, String name, Field[] defaultValue)
    • getPropertyKeys

      String[] getPropertyKeys(Class<?> clazz)
    • hasPropertyIgnoreCase

      boolean hasPropertyIgnoreCase(Class<?> clazz, String name)
    • hasFieldIgnoreCase

      boolean hasFieldIgnoreCase(Class<?> clazz, String name)
    • callConstructor

      Object callConstructor(Class<?> clazz, Object[] args) throws PageException
      call constructor of a Class with matching arguments
      Parameters:
      clazz - Class to get Instance
      args - Arguments for the Class
      Returns:
      invoked Instance
      Throws:
      PageException - Page Exception
    • callConstructor

      Object callConstructor(Class<?> clazz, Object[] args, Object defaultValue)
    • callMethod

      Object callMethod(Object obj, Collection.Key methodName, Object[] args) throws PageException
      calls a Method of an Object
      Parameters:
      obj - Object to call Method on it
      methodName - Name of the Method to get
      args - Arguments of the Method to get
      Returns:
      return return value of the called Method
      Throws:
      PageException - Page Exception
    • callMethod

      Object callMethod(Object obj, Collection.Key methodName, Object[] args, Object defaultValue)
    • callStaticMethod

      Object callStaticMethod(Class<?> clazz, String methodName, Object[] args) throws PageException
      calls a Static Method on the given CLass
      Parameters:
      clazz - Class to call Method on it
      methodName - Name of the Method to get
      args - Arguments of the Method to get
      Returns:
      return return value of the called Method
      Throws:
      PageException - Page Exception
    • getField

      Object getField(Object obj, String prop) throws PageException
      to get a visible Field of an object
      Parameters:
      obj - Object to invoke
      prop - property to call
      Returns:
      property value
      Throws:
      PageException - Page Exception
    • getField

      Object getField(Object obj, String prop, Object defaultValue)
    • setField

      boolean setField(Object obj, String prop, Object value) throws PageException
      assign a value to a visible Field of an object
      Parameters:
      obj - Object to assign value to his property
      prop - name of property
      value - Value to assign
      Returns:
      success
      Throws:
      PageException - Page Exception
    • getProperty

      Object getProperty(Object obj, String prop) throws PageException
      to get a visible Property (Field or Getter) of an object
      Parameters:
      obj - Object to invoke
      prop - property to call
      Returns:
      property value
      Throws:
      PageException - Page Exception
    • getProperty

      Object getProperty(Object obj, String prop, Object defaultValue)
      to get a visible Property (Field or Getter) of an object
      Parameters:
      obj - Object to invoke
      prop - property to call
      defaultValue - default value
      Returns:
      property value
    • setProperty

      void setProperty(Object obj, String prop, Object value) throws PageException
      assign a value to a visible Property (Field or Setter) of an object
      Parameters:
      obj - Object to assign value to his property
      prop - name of property
      value - Value to assign
      Throws:
      PageException - Page Exception
    • setPropertyEL

      void setPropertyEL(Object obj, String prop, Object value)
      assign a value to a visible Property (Field or Setter) of an object
      Parameters:
      obj - Object to assign value to his property
      prop - name of property
      value - Value to assign
    • getDeclaredMethods

      Method[] getDeclaredMethods(Class<?> clazz)
      return all methods that are defined by the Class itself (not extended)
      Parameters:
      clazz - class
      Returns:
      Returns declared methods.
    • canConvert

      boolean canConvert(Class<?> from, Class<?> to)
      check if given Class "from" can be converted to Class "to" without explicit casting
      Parameters:
      from - source class
      to - target class
      Returns:
      is it possible to convert from "from" to "to"
    • loadClassByBundle

      Class<?> loadClassByBundle(String className, String name, String strVersion, Identification id) throws IOException, org.osgi.framework.BundleException
      Throws:
      IOException
      org.osgi.framework.BundleException
    • loadClassByBundle

      Class<?> loadClassByBundle(String className, String name, org.osgi.framework.Version version, Identification id) throws org.osgi.framework.BundleException, IOException
      Throws:
      org.osgi.framework.BundleException
      IOException
    • loadClass

      Class<?> loadClass(String className, Class<?> defaultValue)
      loads a Class from a String classname
      Parameters:
      className - class name
      defaultValue - default value
      Returns:
      matching Class
    • loadClass

      Class<?> loadClass(ClassLoader cl, String className, Class<?> defaultValue)
      loads a Class from a specified Classloader with given classname
      Parameters:
      cl - class loader
      className - class name
      defaultValue - default value
      Returns:
      matching Class
    • loadClass

      Class<?> loadClass(ClassLoader cl, String className) throws IOException
      loads a Class from a specified Classloader with given classname
      Parameters:
      cl - class loader
      className - class name
      Returns:
      matching Class
      Throws:
      IOException - IO Exception
    • loadInstance

      Object loadInstance(Class<?> clazz) throws IOException
      loads a Class from a String classname
      Parameters:
      clazz - Class to load
      Returns:
      matching Class
      Throws:
      IOException - IO Exception
    • loadInstance

      Object loadInstance(String className) throws IOException
      Throws:
      IOException
    • loadInstance

      Object loadInstance(ClassLoader cl, String className) throws IOException
      Throws:
      IOException
    • loadInstance

      Object loadInstance(Class<?> clazz, Object defaultValue)
      loads a Class from a String classname
      Parameters:
      clazz - Class to load
      defaultValue - default value
      Returns:
      matching Class
    • loadInstance

      Object loadInstance(String className, Object defaultValue)
    • loadInstance

      Object loadInstance(ClassLoader cl, String className, Object defaultValue)
    • loadInstance

      Object loadInstance(Class<?> clazz, Object[] args) throws IOException, InvocationTargetException
      loads a Class from a String classname
      Parameters:
      clazz - Class to load
      args - arguments
      Returns:
      matching Class
      Throws:
      IOException - IO Exception
      InvocationTargetException - Invocation Target Exception
    • loadInstance

      Object loadInstance(String className, Object[] args) throws IOException, InvocationTargetException
      Throws:
      IOException
      InvocationTargetException
    • loadInstance

      Object loadInstance(ClassLoader cl, String className, Object[] args) throws IOException, InvocationTargetException
      Throws:
      IOException
      InvocationTargetException
    • loadInstance

      Object loadInstance(Class<?> clazz, Object[] args, Object defaultValue)
      loads a Class from a String classname
      Parameters:
      clazz - Class to load
      args - arguments
      defaultValue - default value
      Returns:
      matching Class
    • loadInstance

      Object loadInstance(String className, Object[] args, Object defaultValue)
    • loadInstance

      Object loadInstance(ClassLoader cl, String className, Object[] args, Object defaultValue)
    • isBytecode

      boolean isBytecode(InputStream is) throws IOException
      check if given stream is a bytecode stream, if yes remove bytecode mark
      Parameters:
      is - Input Stream
      Returns:
      is bytecode stream
      Throws:
      IOException - IO Exception
    • isBytecode

      boolean isBytecode(byte[] barr)
    • getName

      String getName(Class<?> clazz)
    • getMethodIgnoreCase

      Method getMethodIgnoreCase(Class<?> clazz, String methodName, Class<?>[] args) throws IOException
      Throws:
      IOException
    • getMethodIgnoreCase

      Method getMethodIgnoreCase(Class<?> clazz, String methodName, Class<?>[] args, Method defaultValue)
    • getFieldNames

      String[] getFieldNames(Class<?> clazz)
      return all field names as String array
      Parameters:
      clazz - Class to get field names from
      Returns:
      field names
    • toBytes

      byte[] toBytes(Class<?> clazz) throws IOException
      Throws:
      IOException
    • toArrayClass

      Class<?> toArrayClass(Class<?> clazz)
      return an array Class based on the given Class (opposite from Class.getComponentType())
      Parameters:
      clazz - class
      Returns:
      Returns an Array Class.
    • toComponentType

      Class<?> toComponentType(Class<?> clazz)
    • getSourcePathForClass

      String getSourcePathForClass(Class<?> clazz, String defaultValue)
      returns the path to the directory or jar file that the Class was loaded from
      Parameters:
      clazz - - the Class object to check, for a live object pass obj.getClass();
      defaultValue - - a value to return in case the source could not be determined
      Returns:
      Returns the source path for the Class.
    • getSourcePathForClass

      String getSourcePathForClass(String className, String defaultValue)
      tries to load the Class and returns the path that it was loaded from
      Parameters:
      className - - the name of the Class to check
      defaultValue - - a value to return in case the source could not be determined
      Returns:
      Returns the source path for the Class.
    • extractPackage

      String extractPackage(String className)
      extracts the package from a className, return null, if there is none.
      Parameters:
      className - Class Name
      Returns:
      Returns the source path for the Class.
    • extractName

      String extractName(String className)
      extracts the Class name of a classname with package
      Parameters:
      className - Class Name
      Returns:
      Returns Class name.
    • start

      void start(org.osgi.framework.Bundle bundle) throws org.osgi.framework.BundleException
      Throws:
      org.osgi.framework.BundleException
    • addBundle

      org.osgi.framework.Bundle addBundle(org.osgi.framework.BundleContext context, InputStream is, boolean closeStream, boolean checkExistence) throws org.osgi.framework.BundleException, IOException
      Throws:
      org.osgi.framework.BundleException
      IOException