Package com.zfabrik.components
Class Components
- java.lang.Object
-
- com.zfabrik.components.Components
-
public class Components extends java.lang.Object
Convenience wrapper aroundIComponentsLookup
andIComponentsManager
This class provides static access methods to most used methods inIComponentsLookup
andIComponentsManager
.
-
-
Constructor Summary
Constructors Constructor Description Components()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static IResourceHandle
componentHandle(java.lang.String componentName)
Get theIResourceHandle
facet of the named component.static java.util.Collection<java.lang.String>
findComponents(X propertyExpression)
Find all components by query expression on their properties.static <T> T
getComponentAs(java.lang.String componentName, TypeRef<T> typeRef)
Get a component facet by lookup throughstatic <T> T
getComponentAs(java.lang.String componentName, TypeRef<T> typeRef, boolean required)
Get a component facet by lookup throughstatic <T> T
getComponentAs(java.lang.String componentName, java.lang.Class<T> clz)
Get a component facet by lookup throughstatic <T> T
getComponentAs(java.lang.String componentName, java.lang.Class<T> clz, boolean required)
Get a component facet by lookup throughstatic java.util.Properties
getComponentProperties(IResourceHandle component)
Get the component descriptor properties for the component supplied byIResourceHandle
.static java.util.Properties
getComponentProperties(java.lang.String componentName)
Get the component descriptor properties for the component supplied by name.static <T> T
getDependencyComponentAs(IResourceHandle dependant, java.lang.String name, TypeRef<T> typeRef, boolean required)
Add a dependency by component name and retrieve a facet of the dependency.static <T> T
getDependencyComponentAs(IResourceHandle dependant, java.lang.String name, java.lang.Class<T> clz, boolean required)
Add a dependency by component name and retrieve a facet of the dependency.static java.io.File
retrieve(java.lang.String componentName)
Get the resource folder of a component, if any.
-
-
-
Method Detail
-
getComponentAs
public static <T> T getComponentAs(java.lang.String componentName, java.lang.Class<T> clz, boolean required)
Get a component facet by lookup through
optionally requiring support of the facet.IComponentsLookup.INSTANCE.lookup(...)
- Type Parameters:
T
- Generic type of the facet- Parameters:
componentName
- Name of the componentclz
- Class of the generic typerequired
- iftrue
the lookup must result in a non-null result or anIllegalStateException
will be thrown- Returns:
- The facet as implemented by the component
-
getComponentAs
public static <T> T getComponentAs(java.lang.String componentName, TypeRef<T> typeRef, boolean required)
Get a component facet by lookup through
optionally requiring support of the facet.IComponentsLookup.INSTANCE.lookup(...)
- Type Parameters:
T
- Generic type of the facet- Parameters:
componentName
- Name of the componenttypeRef
-TypeRef
of the generic typerequired
- iftrue
the lookup must result in a non-null result or anIllegalStateException
will be thrown- Returns:
- The facet as implemented by the component
-
getComponentAs
public static <T> T getComponentAs(java.lang.String componentName, java.lang.Class<T> clz)
Get a component facet by lookup through
i.e. with a non-required result.getComponentAs(componentName, clz, false)
- Type Parameters:
T
- Generic type of the facet- Parameters:
componentName
- Name of the componentclz
- Class of the generic type- Returns:
- The facet as implemented by the component
-
getComponentAs
public static <T> T getComponentAs(java.lang.String componentName, TypeRef<T> typeRef)
Get a component facet by lookup through
i.e. with a non-required result.getComponentAs(componentName, clz, false)
- Type Parameters:
T
- Generic type of the facet- Parameters:
componentName
- Name of the componenttypeRef
-TypeRef
of the generic type- Returns:
- The facet as implemented by the component
-
componentHandle
public static IResourceHandle componentHandle(java.lang.String componentName)
Get theIResourceHandle
facet of the named component. Note: This lookup is generically supported by the system and always returns a non-null result.- Parameters:
componentName
- Name of the component- Returns:
- The component's resource handle
-
getDependencyComponentAs
public static <T> T getDependencyComponentAs(IResourceHandle dependant, java.lang.String name, java.lang.Class<T> clz, boolean required)
Add a dependency by component name and retrieve a facet of the dependency.- Type Parameters:
T
- Generic type of the facet- Parameters:
dependant
- Handle of the component that will receive the dependencyname
- Name of the dependency component that will be added as a dependencyclz
- Class of the generic typerequired
- iftrue
the lookup via the dependency must result in a non-null result or anIllegalStateException
will be thrown- Returns:
- The facet as implemented by the dependency component
-
getDependencyComponentAs
public static <T> T getDependencyComponentAs(IResourceHandle dependant, java.lang.String name, TypeRef<T> typeRef, boolean required)
Add a dependency by component name and retrieve a facet of the dependency.- Type Parameters:
T
- Generic type of the facet- Parameters:
dependant
- Handle of the component that will receive the dependencyname
- Name of the dependency component that will be added as a dependencytypeRef
-TypeRef
of the generic typerequired
- iftrue
the lookup via the dependency must result in a non-null result or anIllegalStateException
will be thrown- Returns:
- The facet as implemented by the dependency component
-
getComponentProperties
public static java.util.Properties getComponentProperties(IResourceHandle component)
Get the component descriptor properties for the component supplied byIResourceHandle
.- Parameters:
component
- Resource handle of the component to retrieve properties for- Returns:
- Properties of the supplied component
-
getComponentProperties
public static java.util.Properties getComponentProperties(java.lang.String componentName)
Get the component descriptor properties for the component supplied by name.- Parameters:
componentName
- Name of the component to retrieve properties for- Returns:
- Properties of the supplied component
-
retrieve
public static java.io.File retrieve(java.lang.String componentName) throws java.io.IOException
Get the resource folder of a component, if any. See alsoIComponentsRepository.retrieve(String)
- Parameters:
componentName
- Name of the component- Returns:
- Resource folder as
File
, ornull
, if the component has no resource folder - Throws:
java.io.IOException
-
findComponents
public static java.util.Collection<java.lang.String> findComponents(X propertyExpression) throws java.io.IOException
Find all components by query expression on their properties.- Parameters:
propertyExpression
- Search query for components. SeeIComponentsRepository.findComponents(X)
- Returns:
- Query result
- Throws:
java.io.IOException
-
-