Interface BundledRenderUnit
-
@ConsumerType public interface BundledRenderUnitA
BundledRenderUnitrepresents a pre-packaged script or precompiled script (Java class) that will be executed in order to render aHttpServletRequest.The
BundledRenderUnitprovider module is responsible for defining how a unit is executed. However, when executing the unit in the context of aScriptEngine, the provider module should add the current executing unit into theScriptEngine'sScriptContextusing theVARIABLEkey.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringVARIABLEThe variable available in theBindingsassociated to aHttpServletRequestif that request is served by aBundledRenderUnit.
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description voideval(@NotNull javax.servlet.http.HttpServletRequest request, @NotNull javax.servlet.http.HttpServletResponse response)This method will execute / evaluate the wrapped script or precompiled script with the given request.@NotNull org.osgi.framework.BundlegetBundle()Returns theBundlethe publishing bundle of this unit (not to be confused with the provider module, which is the module that instantiates aBundledRenderUnit).@NotNull org.osgi.framework.BundleContextgetBundleContext()Returns theBundleContextto use for this unit.default @Nullable java.io.InputStreamgetInputStream()This method will return an input stream ifthisunit is backed by a script that can be interpreted.@NotNull java.lang.StringgetName()Returns the name ofthis BundledRenderUnit.@NotNull java.lang.StringgetPath()Returns the path of this executable in the resource type hierarchy.<T> TgetService(@NotNull java.lang.String className)Retrieves an OSGi runtime dependency of the wrapped script identified by the passedclassNameparameter.<T> @Nullable T[]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.@NotNull java.util.Set<TypeProvider>getTypeProviders()Returns theSetofTypeProviders which are related to this unit.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
-
getBundle
@NotNull @NotNull org.osgi.framework.Bundle getBundle()
Returns theBundlethe publishing bundle of this unit (not to be confused with the provider module, which is the module that instantiates aBundledRenderUnit). 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();
- Returns:
- the bundle providing this unit
-
getBundleContext
@NotNull @NotNull org.osgi.framework.BundleContext getBundleContext()
Returns theBundleContextto use for this unit. This method can be useful for getting an instance of the publishing bundle's context, when needed to load dependencies at run-time.- Returns:
- the bundle context of the bundle publishing this unit
-
getTypeProviders
@NotNull @NotNull java.util.Set<TypeProvider> getTypeProviders()
Returns theSetofTypeProviders which are related to this unit.- Returns:
- the set of providers; if the unit doesn't have any inheritance chains, then the set will contain only one
TypeProvider
-
getService
@Nullable <T> T getService(@NotNull @NotNull java.lang.String className)Retrieves an OSGi runtime dependency of the wrapped script identified by the passedclassNameparameter.- Type Parameters:
T- the expected service type- Parameters:
className- the fully qualified class name- Returns:
- an instance of the
BundledRenderUnitornull
-
getServices
@Nullable <T> @Nullable T[] 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:
T- 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
-
getPath
@NotNull @NotNull java.lang.String getPath()
Returns the path of this executable in the resource type hierarchy. The path can be relative to the search paths or absolute.- Returns:
- the path of this executable in the resource type hierarchy
-
eval
void eval(@NotNull @NotNull javax.servlet.http.HttpServletRequest request, @NotNull @NotNull javax.servlet.http.HttpServletResponse response) throws javax.script.ScriptExceptionThis method will execute / evaluate the wrapped script or precompiled script with the given request.- Parameters:
request- the requestresponse- the response- Throws:
javax.script.ScriptException- if the execution leads to an error
-
getInputStream
@Nullable default @Nullable java.io.InputStream getInputStream()
This method will return an input stream ifthisunit is backed by a script that can be interpreted.- Returns:
- an
InputStreamproviding the source code of the backing script; ifthisunit is backed by a precompiled script (essentially a Java class), then this method will returnnull
-
-