Package org.apache.sling.scripting.sightly.impl.engine.bundled

# Class BundledUnitManagerImpl

java.lang.Object
org.apache.sling.scripting.sightly.impl.engine.bundled.BundledUnitManagerImpl

All Implemented Interfaces:
  `BundledUnitManager`

public class BundledUnitManagerImpl extends Object implements BundledUnitManager
This service allows various components to work with `BundledRenderUnit` instance and perform dependency resolution based on their availability in the `Bindings` maps passed to the HTL Script Engine. Given the dependency on the `SightlyScriptEngineFactory`, this service will be registered by the `SightlyScriptEngineFactory` when the factory is initialised.

## Constructor Summary

Constructors
Constructor
Description
`BundledUnitManagerImpl(@NotNull SightlyScriptEngineFactory sightlyScriptEngineFactory, @NotNull org.apache.sling.scripting.api.ScriptCache scriptCache, @NotNull org.apache.sling.api.resource.ResourceResolverFactory resourceResolverFactory)`

## Method Summary

Modifier and Type
Method
Description
`@Nullable ClassLoader`
`getBundledRenderUnitClassloader(Bindings bindings)`
Given a `Bindings` map, this method will check if the `bindings` contain a value for the `BundledRenderUnit.VARIABLE` property and if the object provided by `BundledRenderUnit.getUnit()` is an instance of a `RenderUnit`.
`@Nullable org.apache.sling.scripting.sightly.render.RenderUnit`
`getRenderUnit(@NotNull Bindings bindings)`
Given a `Bindings` map, this method will check if the `bindings` contain a value for the `BundledRenderUnit.VARIABLE` property and return the object provided by `BundledRenderUnit.getUnit()` if this is an instance of a `RenderUnit`.
`@Nullable org.apache.sling.scripting.sightly.render.RenderUnit`
`getRenderUnit(@NotNull Bindings bindings, @NotNull String identifier)`
Given a `Bindings` map, this method will check if the `bindings` contain a value for the `BundledRenderUnit.VARIABLE` property and if the object provided by `BundledRenderUnit.getUnit()` is an instance of a `RenderUnit`.
`@Nullable URL`
`getScript(Bindings bindings, String identifier)`
Given a `Bindings` map, this method will check if the `bindings` contain a value for the `BundledRenderUnit.VARIABLE` property and, if a `BundledRenderUnit` is found, attempt to return the URL of dependency that the `BundledRenderUnit` needs to load.
`@NotNull SightlyScriptEngineFactory`
`getScriptEngineFactory()`
`<T> T`
`getServiceForBundledRenderUnit(Bindings bindings, Class<T> clazz)`
Given a `Bindings` map, this method will check if the `bindings` contain a value for the `BundledRenderUnit.VARIABLE` property and if the object provided by `BundledRenderUnit.getUnit()` is an instance of a `RenderUnit`.

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

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

## Constructor Details

### BundledUnitManagerImpl

public BundledUnitManagerImpl(@NotNull @NotNull SightlyScriptEngineFactory sightlyScriptEngineFactory, @NotNull @NotNull org.apache.sling.scripting.api.ScriptCache scriptCache, @NotNull @NotNull org.apache.sling.api.resource.ResourceResolverFactory resourceResolverFactory)

## Method Details

### getRenderUnit

@Nullable public @Nullable org.apache.sling.scripting.sightly.render.RenderUnit getRenderUnit(@NotNull @NotNull Bindings bindings)
Given a `Bindings` map, this method will check if the `bindings` contain a value for the `BundledRenderUnit.VARIABLE` property and return the object provided by `BundledRenderUnit.getUnit()` if this is an instance of a `RenderUnit`.

Parameters:
  `bindings` - the bindings passed initially to the HTL Script Engine
Returns:
  a `RenderUnit` if one is found, `null` otherwise

### getRenderUnit

@Nullable public @Nullable org.apache.sling.scripting.sightly.render.RenderUnit getRenderUnit(@NotNull @NotNull Bindings bindings, @NotNull @NotNull String identifier)

Given a `Bindings` map, this method will check if the `bindings` contain a value for the `BundledRenderUnit.VARIABLE` property and if the object provided by `BundledRenderUnit.getUnit()` is an instance of a `RenderUnit`. If so, this service will try to locate another `RenderUnit` based on the passed `identifier` and the coordinates of the `RenderUnit` found in the `bindings` map.

This method is suited for finding template libraries (collections of templates provided by the same `RenderUnit`).

Parameters:
  `bindings` - the bindings passed initially to the HTL Script Engine
  `identifier` - the identifier of the `RenderUnit` that has to be retrieved and returned
Returns:
  a `RenderUnit` if one is found, `null` otherwise

### getScript

@Nullable public @Nullable URL getScript(Bindings bindings, String identifier)
Description copied from interface: `BundledUnitManager`
Given a `Bindings` map, this method will check if the `bindings` contain a value for the `BundledRenderUnit.VARIABLE` property and, if a `BundledRenderUnit` is found, attempt to return the URL of dependency that the `BundledRenderUnit` needs to load. This will take into account the bundle wirings of the unit's providing bundle (see `BundledRenderUnit.getBundle()`).

Specified by:
  `getScript` in interface `BundledUnitManager`
Parameters:
  `bindings` - the bindings passed initially to the HTL Script Engine
  `identifier` - the identifier of the dependency that a `BundledRenderUnit` from the `Bindings` needs to load
Returns:
  the URL of the `identifier` dependency, if one was found

### getBundledRenderUnitClassloader

@Nullable public @Nullable ClassLoader getBundledRenderUnitClassloader(Bindings bindings)

Given a `Bindings` map, this method will check if the `bindings` contain a value for the `BundledRenderUnit.VARIABLE` property and if the object provided by `BundledRenderUnit.getUnit()` is an instance of a `RenderUnit`. If so, this service will return the `ClassLoader` of the `Bundle` providing the `BundledRenderUnit`.

Specified by:
  `getBundledRenderUnitClassloader` in interface `BundledUnitManager`
Parameters:
  `bindings` - the bindings passed initially to the HTL Script Engine
Returns:
  the `BundledRenderUnit`'s classloader if one is found, `null` otherwise

### getServiceForBundledRenderUnit

@Nullable public <T> T getServiceForBundledRenderUnit(Bindings bindings, Class<T> clazz)

Given a `Bindings` map, this method will check if the `bindings` contain a value for the `BundledRenderUnit.VARIABLE` property and if the object provided by `BundledRenderUnit.getUnit()` is an instance of a `RenderUnit`. If so, this service will try to get a reference to a service of type `clazz` and return the service object. The service will be retrieved using the bundle context of the `BundledRenderUnit` found in the `bindings` map.

Type Parameters:
  `T` - the service type
Parameters:
  `bindings` - the bindings passed initially to the HTL Script Engine
  `clazz` - the class identifying the type of the service
Returns:
  a service object, if one is found, `null` otherwise

### getScriptEngineFactory

@NotNull public @NotNull SightlyScriptEngineFactory getScriptEngineFactory()