Class BeanContext.Wrapper

  • All Implemented Interfaces:
    BeanContext, org.apache.sling.api.adapter.Adaptable
    Enclosing interface:
    BeanContext

    public static class BeanContext.Wrapper
    extends Object
    implements BeanContext
    a wrapper implementation base
    • Field Detail

      • resolver

        protected final org.apache.sling.api.resource.ResourceResolver resolver
      • resource

        protected final org.apache.sling.api.resource.Resource resource
    • Constructor Detail

      • Wrapper

        public Wrapper​(BeanContext beanContext,
                       org.apache.sling.api.resource.ResourceResolver resolverToUse)
      • Wrapper

        public Wrapper​(BeanContext beanContext,
                       org.apache.sling.api.resource.Resource resourceToUse)
      • Wrapper

        public Wrapper​(BeanContext beanContext,
                       org.apache.sling.api.resource.ResourceResolver resolverToUse,
                       org.apache.sling.api.resource.Resource resourceToUse)
    • Method Detail

      • getResource

        public org.apache.sling.api.resource.Resource getResource()
        Description copied from interface: BeanContext
        Returns the resource declared in the context.
        Specified by:
        getResource in interface BeanContext
      • getResolver

        public org.apache.sling.api.resource.ResourceResolver getResolver()
        Description copied from interface: BeanContext
        Returns the resolver declared in the context.
        Specified by:
        getResolver in interface BeanContext
      • getRequest

        public org.apache.sling.api.SlingHttpServletRequest getRequest()
        Description copied from interface: BeanContext
        Returns the request declared in the context.
        Specified by:
        getRequest in interface BeanContext
      • getResponse

        public org.apache.sling.api.SlingHttpServletResponse getResponse()
        Description copied from interface: BeanContext
        Returns the response declared in the context.
        Specified by:
        getResponse in interface BeanContext
      • getService

        public <T> T getService​(Class<T> type)
        Description copied from interface: BeanContext
        retrieves a service implementation using the 'sling' script helper
        Specified by:
        getService in interface BeanContext
      • getServices

        public <T> T[] getServices​(Class<T> serviceType,
                                   String filter)
                            throws org.osgi.framework.InvalidSyntaxException
        Description copied from interface: BeanContext
        retrieves a set of services appropriate to the filter
        Specified by:
        getServices in interface BeanContext
        Throws:
        org.osgi.framework.InvalidSyntaxException
      • adaptTo

        public <AdapterType> AdapterType adaptTo​(@NotNull
                                                 @NotNull Class<AdapterType> type)
        Description copied from interface: BeanContext

        Adapts to the components Resource, ResourceResolver, SlingHttpServletRequest, SlingHttpServletResponse, Locale, BeanContext itself, a ValueMap for the request, SlingBeans or possibly more if defined in Sling.

        In case of SlingBean we try the basic sling mechanism (possibly calling Sling-Models) and, failing that, try to instantiate and SlingBean.initialize(BeanContext) it ourselves, if it is instantiable and the Sling-Models @Model annotation is not present.

        Cached - multiple calls will always return the same object, except for ValueMap and SlingBeans.

        Specified by:
        adaptTo in interface org.apache.sling.api.adapter.Adaptable
        Specified by:
        adaptTo in interface BeanContext
        Parameters:
        type - not null, the type to be adapted to
        Returns:
        the component of type or whatever Sling has adapters for, or null if there is nothing.
        See Also:
        SlingAdaptable.adaptTo(Class)
      • withResource

        public BeanContext withResource​(org.apache.sling.api.resource.Resource resource)
        Description copied from interface: BeanContext
        Returns a clone of this context with the resource overridden, or this if it already had this resource. All other internal structures of this will be referenced by the copy, too.
        Specified by:
        withResource in interface BeanContext
        Parameters:
        resource - the resource
        Returns:
        a context with the BeanContext.getResource() resource, everything else (except possibly resolver) unchanged. Might be this.
      • withLocale

        public BeanContext withLocale​(Locale locale)
        Description copied from interface: BeanContext
        Returns a clone of this context with the locale overridden, or this if it already had this locale. All other internal structures of this will be referenced by the copy, too.
        Specified by:
        withLocale in interface BeanContext
        Parameters:
        locale - the locale; if this is null BeanContext.getLocale() will take this from the attributes.
        Returns:
        a context with this locale, otherwise sharing everything else. Might be this.