Package com.zfabrik.components.java

## Class JavaComponentUtil

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

-     public class JavaComponentUtil
      extends java.lang.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 Summary

    Constructors
    Constructor | Description
    --- | ---
    `JavaComponentUtil()` |

  - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `static java.util.Collection<java.lang.String>` | `_parseDependencies​(java.lang.String s, boolean applyQuery)` |
    `static java.lang.String` | `fixJavaComponentName​(java.lang.String forModuleOrComponent)` | Given a module name or a component name, determine a java component name.
    `static java.lang.String` | `getCompilerComponentById​(java.lang.String compilerID)` | Gets a java compiler implementation component by id.
    `static java.io.File` | `getInstanceFolder​(java.io.File componentFolder)` | Given a component folder, compute the instance folder.
    `static IResourceHandle` | `getJavaComponent​(java.lang.String forComponent)` | Given a component name return the default Java component for it.
    `static java.lang.String` | `getJavaComponentName​(java.lang.String forComponent)` | Given a component name return the default Java component name for it.
    `static java.lang.ClassLoader` | `getPrivateLoaderOfJavaComponent​(java.lang.String componentName)` | Gets the private class loader of the default java component for the given component name.
    `static java.lang.ClassLoader` | `getPrivateLoaderOfJavaComponent​(java.lang.String componentName, java.lang.ClassLoader defaultLoader)` | Gets the private class loader of the default java component for the given component name.
    `static boolean` | `isPreBuilt​(IComponentDescriptor desc)` | Given a Java component descriptor, check, if no build is required
    `static java.lang.Class<?>` | `loadImplementationClassFromJavaComponent​(java.lang.String componentName, java.lang.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
    `static <T> T` | `loadImplementationFromJavaComponent​(java.lang.String componentName, java.lang.String clzNameProp, IResourceHandle r, java.lang.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
    `static java.util.Collection<java.lang.String>` | `parseDependencies​(java.lang.String s)` | Parse a reference and includes list and normalize component names.
    `static <T> T` | `privateContextExceptionExecute​(java.lang.String componentName, java.util.concurrent.Callable<T> callable)` | Like `ThreadUtil.cleanContextExceptionExecute(ClassLoader, Callable)` but simply based on a component identification
    `static <T> T` | `privateContextExecute​(java.lang.String componentName, java.util.concurrent.Callable<T> callable)` | Like `ThreadUtil.cleanContextExceptionExecute(ClassLoader, Callable)` but simply based on a component identification
    `static <T> T` | `privateContextWrap​(java.lang.String cn, T t, java.lang.Class<T> intf)` | Creates a context class loader switching invocation wrapper by passing an interface, an implementation, and a component name.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### JavaComponentUtil

          public JavaComponentUtil()

  - ### Method Detail

    - #### getJavaComponent

          public static IResourceHandle getJavaComponent​(java.lang.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 java.lang.String getJavaComponentName​(java.lang.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 java.lang.String fixJavaComponentName​(java.lang.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​(java.lang.String componentName,
                                                                  java.lang.String clzNameProp,
                                                                  IResourceHandle r,
                                                                  java.lang.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 java.lang.Class<?> loadImplementationClassFromJavaComponent​(java.lang.String componentName,
                                                                                    java.lang.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 java.lang.ClassLoader getPrivateLoaderOfJavaComponent​(java.lang.String componentName,
                                                                              java.lang.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 java.lang.ClassLoader getPrivateLoaderOfJavaComponent​(java.lang.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 java.lang.String getCompilerComponentById​(java.lang.String compilerID)
                                                           throws java.io.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:
        `java.io.IOException`

    - #### privateContextWrap

          public static <T> T privateContextWrap​(java.lang.String cn,
                                                 T t,
                                                 java.lang.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​(java.lang.String componentName,
                                                             java.util.concurrent.Callable<T> callable)
                                                      throws java.lang.Exception

      Like `ThreadUtil.cleanContextExceptionExecute(ClassLoader, Callable)` but simply based on a component identification
      Throws:
        `java.lang.Exception`

    - #### privateContextExecute

          public static <T> T privateContextExecute​(java.lang.String componentName,
                                                    java.util.concurrent.Callable<T> callable)

      Like `ThreadUtil.cleanContextExceptionExecute(ClassLoader, Callable)` but simply based on a component identification

    - #### parseDependencies

          public static java.util.Collection<java.lang.String> parseDependencies​(java.lang.String s)

      Parse a reference and includes list and normalize component names.

    - #### _parseDependencies

          public static java.util.Collection<java.lang.String> _parseDependencies​(java.lang.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 java.io.File getInstanceFolder​(java.io.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.