Interface BundledRenderUnit
-
- All Known Implementing Classes:
PrecompiledScript
@ProviderType public interface BundledRenderUnitA
BundledRenderUnitrepresents a pre-packaged script or precompiled script that will be executed in order to render aSlingHttpServletRequest.If the current
SlingHttpServletRequestis served by aBundledRenderUnit, theorg.apache.sling.scripting.bundle.trackerwill set theBundledRenderUnitin theBindingsmap associated to the request, under theVARIABLEkey.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringVARIABLEThe variable available in theBindingsassociated to aSlingHttpServletRequestif that request is served by aBundledRenderUnit.
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description voideval(@NotNull javax.script.ScriptContext context)Provided aScriptContext, this method will execute / evaluate the wrapped script or precompiled script.@NotNull org.osgi.framework.BundlegetBundle()Returns theBundlein which the script or precompiled script is packaged.@NotNull java.lang.StringgetName()Returns the name ofthis BundledRenderUnit.@NotNull javax.script.ScriptEnginegetScriptEngine()Returns an instance of theScriptEnginethat can execute the wrapped script or precompiled script, if the latter needs a specific runtime.<ServiceType>
ServiceTypegetService(@NotNull java.lang.String className)Retrieves an OSGi runtime dependency of the wrapped script identified by the passedclassNameparameter.<ServiceType>
@Nullable ServiceType[]getServices(@NotNull java.lang.String className, @Nullable java.lang.String filter)Retrieves multiple instances of an OSGi runtime dependency of the wrapped script identified by the passedclassNameparameter, filtered according to the passedfilter.default @Nullable java.lang.ObjectgetUnit()In case thisBundledRenderUnitwraps a precompiled script, this method will return an instance of that object.
-
-
-
Method Detail
-
getUnit
@Nullable default @Nullable java.lang.Object getUnit()
In case thisBundledRenderUnitwraps a precompiled script, this method will return an instance of that object.- Returns:
- a precompiled unit, if
thisunit wraps a precompiled script;nullotherwise
-
getName
@NotNull @NotNull java.lang.String getName()
Returns the name ofthis BundledRenderUnit. This can be the name of the wrapped script or precompiled script.- Returns:
- the name
this BundledRenderUnit
-
getScriptEngine
@NotNull @NotNull javax.script.ScriptEngine getScriptEngine()
Returns an instance of theScriptEnginethat can execute the wrapped script or precompiled script, if the latter needs a specific runtime.- Returns:
- an instance of the script's or precompiled script's associated
ScriptEngine
-
getBundle
@NotNull @NotNull org.osgi.framework.Bundle getBundle()
Returns theBundlein which the script or precompiled script is packaged. This method can be useful for getting an instance of the bundle's classloader, when needed to load dependencies at run time. To do so the following code example can help:Bundle bundle = bundledRenderUnit.getBundle(); Classloader bundleClassloader = bundle.adapt(BundleWiring.class).getClassLoader();
-
eval
void eval(@NotNull @NotNull javax.script.ScriptContext context) throws javax.script.ScriptExceptionProvided aScriptContext, this method will execute / evaluate the wrapped script or precompiled script.- Parameters:
context- theScriptContext- Throws:
javax.script.ScriptException- if the execution leads to an error
-
getService
@Nullable <ServiceType> ServiceType getService(@NotNull @NotNull java.lang.String className)Retrieves an OSGi runtime dependency of the wrapped script identified by the passedclassNameparameter.- Type Parameters:
ServiceType- the expected service type- Parameters:
className- the fully qualified class name- Returns:
- an instance of the
BundledRenderUnitornull
-
getServices
@Nullable <ServiceType> @Nullable ServiceType[] getServices(@NotNull @NotNull java.lang.String className, @Nullable @Nullable java.lang.String filter)Retrieves multiple instances of an OSGi runtime dependency of the wrapped script identified by the passedclassNameparameter, filtered according to the passedfilter.- Type Parameters:
ServiceType- the expected service type- Parameters:
className- the fully qualified class namefilter- a filter expression ornullif all the instances should be returned; for more details about thefilter's syntax checkBundleContext.getServiceReferences(String, String)- Returns:
- an instance of the
BundledRenderUnitornull
-
-