Package com.zfabrik.components.java
Class JavaComponentUtil
java.lang.Object
com.zfabrik.components.java.JavaComponentUtil
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 -
Method Summary
Modifier and TypeMethodDescriptionstatic Collection<String>
_parseDependencies
(String s, boolean applyQuery) static String
fixJavaComponentName
(String forModuleOrComponent) Given a module name or a component name, determine a java component name.static String
getCompilerComponentById
(String compilerID) Gets a java compiler implementation component by id.static File
getInstanceFolder
(File componentFolder) Given a component folder, compute the instance folder.static IResourceHandle
getJavaComponent
(String forComponent) Given a component name return the default Java component for it.static String
getJavaComponentName
(String forComponent) Given a component name return the default Java component name for it.static ClassLoader
getPrivateLoaderOfJavaComponent
(String componentName) Gets the private class loader of the default java component for the given component name.static ClassLoader
getPrivateLoaderOfJavaComponent
(String componentName, ClassLoader defaultLoader) Gets the private class loader of the default java component for the given component name.static boolean
Given a Java component descriptor, check, if no build is requiredstatic 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 componentstatic <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 componentstatic Collection<String>
Parse a reference and includes list and normalize component names.static <T> T
privateContextExceptionExecute
(String componentName, Callable<T> callable) LikeThreadUtil.cleanContextExceptionExecute(ClassLoader, Callable)
but simply based on a component identificationstatic <T> T
privateContextExecute
(String componentName, Callable<T> callable) LikeThreadUtil.cleanContextExceptionExecute(ClassLoader, Callable)
but simply based on a component identificationstatic <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.
-
Constructor Details
-
JavaComponentUtil
public JavaComponentUtil()
-
-
Method Details
-
getJavaComponent
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
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
Given a module name or a component name, determine a java component name. This is not about the default java component name. UsegetJavaComponentName(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 nameclzNameProp
- A property declaring a class name in the component's descriptorr
- A resource handle that will be dependent on the loading Java componenttype
- 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 nameclzNameProp
- A property declaring a class name in the component's descriptorr
- 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
Gets the private class loader of the default java component for the given component name. Defaults to the core class loader -
getCompilerComponentById
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
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 LikeThreadUtil.cleanContextExceptionExecute(ClassLoader, Callable)
but simply based on a component identification- Throws:
Exception
-
privateContextExecute
LikeThreadUtil.cleanContextExceptionExecute(ClassLoader, Callable)
but simply based on a component identification -
parseDependencies
Parse a reference and includes list and normalize component names. -
_parseDependencies
-
isPreBuilt
Given a Java component descriptor, check, if no build is required -
getInstanceFolder
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.
-