Interface BundledRenderUnit

  • All Known Implementing Classes:
    PrecompiledScript

    @ProviderType
    public interface BundledRenderUnit

    A BundledRenderUnit represents a pre-packaged script or precompiled script that will be executed in order to render a SlingHttpServletRequest.

    If the current SlingHttpServletRequest is served by a BundledRenderUnit, the org.apache.sling.scripting.bundle.tracker will set the BundledRenderUnit in the Bindings map associated to the request, under the VARIABLE key.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String VARIABLE
      The variable available in the Bindings associated to a SlingHttpServletRequest if that request is served by a BundledRenderUnit.
    • Method Summary

      All Methods Instance Methods Abstract Methods Default Methods 
      Modifier and Type Method Description
      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.
      default @Nullable java.lang.Object getUnit()
      In case this BundledRenderUnit wraps a precompiled script, this method will return an instance of that object.
    • Field Detail

      • VARIABLE

        static final java.lang.String VARIABLE
        The variable available in the Bindings associated to a SlingHttpServletRequest if that request is served by a BundledRenderUnit.
    • Method Detail

      • getUnit

        @Nullable
        default @Nullable java.lang.Object getUnit()
        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
      • getName

        @NotNull
        @NotNull java.lang.String getName()
        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
        @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.
        Returns:
        an instance of the script's or precompiled script's associated ScriptEngine
      • getBundle

        @NotNull
        @NotNull org.osgi.framework.Bundle getBundle()
        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();
         
      • eval

        void eval​(@NotNull
                  @NotNull javax.script.ScriptContext context)
           throws javax.script.ScriptException
        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
      • getService

        @Nullable
        <ServiceType> ServiceType getService​(@NotNull
                                             @NotNull java.lang.String className)
        Retrieves an OSGi runtime dependency of the wrapped script identified by the passed className parameter.
        Type Parameters:
        ServiceType - the expected service type
        Parameters:
        className - the fully qualified class name
        Returns:
        an instance of the BundledRenderUnit or null
      • 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 passed className parameter, filtered according to the passed filter.
        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