Class JavaComponentUtil

java.lang.Object
com.zfabrik.components.java.JavaComponentUtil

public class JavaComponentUtil extends Object
Utility functions around Java components. These are useful when implementing a component type that requires to load Java classes as well as anything that consumes Java component names (and should use the defaulting methods).
Author:
hb
  • Constructor Details

    • JavaComponentUtil

      public JavaComponentUtil()
  • Method Details

    • getJavaComponent

      public static IResourceHandle getJavaComponent(String forComponent)
      Given a component name return the default Java component for it. That is, a project name will be completed by /java, a component name will be appended /java after removing the last name segment
      Parameters:
      forComponent - A component name to derive a Java component lookup from
      Returns:
      The resource handle of a derived Java component
    • getJavaComponentName

      public static String getJavaComponentName(String forComponent)
      Given a component name return the default Java component name for it. That is, a project name will be completed by /java, a component name will be appended /java after removing the last name segment
      Parameters:
      forComponent - A component name to derive a Java component name from
      Returns:
      The name of a derived Java component
    • fixJavaComponentName

      public static String fixJavaComponentName(String forModuleOrComponent)
      Given a module name or a component name, determine a java component name. This is not about the default java component name. Use getJavaComponentName(String) for that. This does not alter a fully qualified component name, but appends /java to a module name
      Parameters:
      forModuleOrComponent - The name of a Java component or a module
      Returns:
      A Java component name
    • loadImplementationFromJavaComponent

      public static <T> T loadImplementationFromJavaComponent(String componentName, String clzNameProp, IResourceHandle r, Class<T> type)
      Load an implementation for a component by looking up the associated Java component In addition, manage the dependency to the Java component
      Parameters:
      componentName - A component name
      clzNameProp - A property declaring a class name in the component's descriptor
      r - A resource handle that will be dependent on the loading Java component
      type - The expected implementation type of the implementation class
      Returns:
      the implementation instance
    • loadImplementationClassFromJavaComponent

      public static Class<?> loadImplementationClassFromJavaComponent(String componentName, String clzNameProp, IResourceHandle r)
      load an implementation class for a component by looking up the associated Java component In addition, manage the dependency to the Java component
      Parameters:
      componentName - A component name
      clzNameProp - A property declaring a class name in the component's descriptor
      r - A resource handle that will be dependent on the loading Java component
      Returns:
      the implementation class
    • getPrivateLoaderOfJavaComponent

      public static ClassLoader getPrivateLoaderOfJavaComponent(String componentName, ClassLoader defaultLoader)
      Gets the private class loader of the default java component for the given component name. Defaults to the passed default loader, if no Java component is defined.
    • getPrivateLoaderOfJavaComponent

      public static ClassLoader getPrivateLoaderOfJavaComponent(String componentName)
      Gets the private class loader of the default java component for the given component name. Defaults to the core class loader
    • getCompilerComponentById

      public static String getCompilerComponentById(String compilerID) throws IOException
      Gets a java compiler implementation component by id. This is a utility function that simply issues the corresponding query and checks for existence and uniqueness.
      Parameters:
      compilerID - The id of a compiler
      Returns:
      The component name providing the compiler
      Throws:
      IOException
    • privateContextWrap

      public static <T> T privateContextWrap(String cn, T t, Class<T> intf)
      Creates a context class loader switching invocation wrapper by passing an interface, an implementation, and a component name.
    • privateContextExceptionExecute

      public static <T> T privateContextExceptionExecute(String componentName, Callable<T> callable) throws Exception
      Like ThreadUtil.cleanContextExceptionExecute(ClassLoader, Callable) but simply based on a component identification
      Throws:
      Exception
    • privateContextExecute

      public static <T> T privateContextExecute(String componentName, Callable<T> callable)
      Like ThreadUtil.cleanContextExceptionExecute(ClassLoader, Callable) but simply based on a component identification
    • parseDependencies

      public static Collection<String> parseDependencies(String s)
      Parse a reference and includes list and normalize component names.
    • _parseDependencies

      public static Collection<String> _parseDependencies(String s, boolean applyQuery)
    • isPreBuilt

      public static boolean isPreBuilt(IComponentDescriptor desc)
      Given a Java component descriptor, check, if no build is required
    • getInstanceFolder

      public static File getInstanceFolder(File componentFolder)
      Given a component folder, compute the instance folder. The instance folder is where after initialization, we find the runtime resources of the Java component, including build artifacts.