Package org.apache.sling.scripting.bundle.tracker.internal

## Class PrecompiledScript

- java.lang.Object
- - org.apache.sling.scripting.bundle.tracker.internal.PrecompiledScript

All Implemented Interfaces:
  `BundledRenderUnit`

    public class PrecompiledScript
    extends java.lang.Object

### Field Summary

### Fields inherited from interface org.apache.sling.scripting.bundle.tracker.BundledRenderUnit

`VARIABLE`

### Method Summary

All Methods Instance Methods Concrete Methods
`void` `eval​(@NotNull javax.script.ScriptContext context)` Provided a `ScriptContext`, this method will execute / evaluate the wrapped script or precompiled script.
`@NotNull org.osgi.framework.Bundle` `getBundle()` Returns the `Bundle` in which the script or precompiled script is packaged.
`@NotNull java.lang.String` `getName()` Returns the name of `this BundledRenderUnit`.
`@NotNull javax.script.ScriptEngine` `getScriptEngine()` Returns an instance of the `ScriptEngine` that can execute the wrapped script or precompiled script, if the latter needs a specific runtime.
`<ServiceType> ServiceType` `getService​(@NotNull java.lang.String className)` Retrieves an OSGi runtime dependency of the wrapped script identified by the passed `className` parameter.
`<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 passed `className` parameter, filtered according to the passed `filter`.
`@NotNull java.lang.Object` `getUnit()` In case this `BundledRenderUnit` wraps a precompiled script, this method will return an instance of that object.
`void` `releaseDependencies()`

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

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

### Method Detail

#### getName

    @NotNull
    public @NotNull java.lang.String getName()

Description copied from interface: `BundledRenderUnit`
Returns the name of `this BundledRenderUnit`. This can be the name of the wrapped script or precompiled script.

Returns:
  the name `this BundledRenderUnit`

#### getScriptEngine

    @NotNull
    public @NotNull javax.script.ScriptEngine getScriptEngine()

Description copied from interface: `BundledRenderUnit`
Returns an instance of the `ScriptEngine` that 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`

#### eval

    public void eval​(@NotNull
                     @NotNull javax.script.ScriptContext context)
              throws javax.script.ScriptException

Description copied from interface: `BundledRenderUnit`
Provided a `ScriptContext`, this method will execute / evaluate the wrapped script or precompiled script.

Parameters:
  `context` - the `ScriptContext`
Throws:
  `javax.script.ScriptException` - if the execution leads to an error

#### getUnit

    @NotNull
    public @NotNull java.lang.Object getUnit()

Description copied from interface: `BundledRenderUnit`
In case this `BundledRenderUnit` wraps a precompiled script, this method will return an instance of that object.

Returns:
  a precompiled unit, if `this` unit wraps a precompiled script; `null` otherwise

#### getBundle

    @NotNull
    public @NotNull org.osgi.framework.Bundle getBundle()

Description copied from interface: `BundledRenderUnit`
Returns the `Bundle` in 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();

Specified by:
  `getBundle` in interface `BundledRenderUnit`

#### getService

    @Nullable
    public <ServiceType> ServiceType getService​(@NotNull
                                                @NotNull java.lang.String className)

Description copied from interface: `BundledRenderUnit`
Retrieves an OSGi runtime dependency of the wrapped script identified by the passed `className` parameter.

Specified by:
  `getService` in interface `BundledRenderUnit`
Type Parameters:
  `ServiceType` - the expected service type
Parameters:
  `className` - the fully qualified class name
Returns:
  an instance of the `BundledRenderUnit` or `null`

#### getServices

    @Nullable
    public <ServiceType> @Nullable ServiceType[] getServices​(@NotNull
                                                             @NotNull java.lang.String className,
                                                             @Nullable
                                                             @Nullable java.lang.String filter)

Description copied from interface: `BundledRenderUnit`
Retrieves multiple instances of an OSGi runtime dependency of the wrapped script identified by the passed `className` parameter, filtered according to the passed `filter`.

Specified by:
  `getServices` in interface `BundledRenderUnit`
Type Parameters:
  `ServiceType` - the expected service type
Parameters:
  `className` - the fully qualified class name
  `filter` - a filter expression or `null` if all the instances should be returned; for more details about the `filter`'s syntax check `BundleContext.getServiceReferences(String, String)`
Returns:
  an instance of the `BundledRenderUnit` or `null`

#### releaseDependencies

    public void releaseDependencies()