Package com.composum.sling.core
Class BeanContext.Wrapper
- java.lang.Object
-
- com.composum.sling.core.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
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface com.composum.sling.core.BeanContext
BeanContext.AbstractContext, BeanContext.AbstractScriptContext, BeanContext.Map, BeanContext.Page, BeanContext.Scope, BeanContext.Service, BeanContext.Servlet, BeanContext.Wrapper
-
-
Field Summary
Fields Modifier and Type Field Description protected BeanContextbeanContextprotected org.apache.sling.api.resource.ResourceResolverresolverprotected org.apache.sling.api.resource.Resourceresource-
Fields inherited from interface com.composum.sling.core.BeanContext
ATTR_LOCALE, ATTR_REQUEST, ATTR_RESOLVER, ATTR_RESOURCE, ATTR_RESPONSE
-
-
Constructor Summary
Constructors Constructor Description Wrapper(BeanContext beanContext)Wrapper(BeanContext beanContext, org.apache.sling.api.resource.Resource resourceToUse)Wrapper(BeanContext beanContext, org.apache.sling.api.resource.ResourceResolver resolverToUse)Wrapper(BeanContext beanContext, org.apache.sling.api.resource.ResourceResolver resolverToUse, org.apache.sling.api.resource.Resource resourceToUse)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <AdapterType>
AdapterTypeadaptTo(@NotNull Class<AdapterType> type)Adapts to the componentsResource,ResourceResolver,SlingHttpServletRequest,SlingHttpServletResponse,Locale,BeanContextitself, aValueMapfor the request,SlingBeans or possibly more if defined in Sling.<T> TgetAttribute(String name, Class<T> T)Returns an attribute value from the context.LocalegetLocale()Returns the locale declared determined using the context, determined and cached asBeanContext.getAttribute(String, Class)(BeanContext.ATTR_LOCALE).org.apache.sling.api.SlingHttpServletRequestgetRequest()Returns the request declared in the context.org.apache.sling.api.resource.ResourceResolvergetResolver()Returns the resolver declared in the context.org.apache.sling.api.resource.ResourcegetResource()Returns the resource declared in the context.org.apache.sling.api.SlingHttpServletResponsegetResponse()Returns the response declared in the context.<T> TgetService(Class<T> type)retrieves a service implementation using the 'sling' script helper<T> T[]getServices(Class<T> serviceType, String filter)retrieves a set of services appropriate to the filterClass<?>getType(String className)retrieves a class using the Slings DynamicClassLoaderManager implementationvoidsetAttribute(String name, Object value, BeanContext.Scope scope)Stores an attribute in the context in th given scope.BeanContextwithLocale(Locale locale)Returns a clone of this context with the locale overridden, orthisif it already had this locale.BeanContextwithResource(org.apache.sling.api.resource.Resource resource)Returns a clone of this context with the resource overridden, orthisif it already had this resource.
-
-
-
Field Detail
-
beanContext
protected BeanContext beanContext
-
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)
-
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:BeanContextReturns the resource declared in the context.- Specified by:
getResourcein interfaceBeanContext
-
getResolver
public org.apache.sling.api.resource.ResourceResolver getResolver()
Description copied from interface:BeanContextReturns the resolver declared in the context.- Specified by:
getResolverin interfaceBeanContext
-
getRequest
public org.apache.sling.api.SlingHttpServletRequest getRequest()
Description copied from interface:BeanContextReturns the request declared in the context.- Specified by:
getRequestin interfaceBeanContext
-
getResponse
public org.apache.sling.api.SlingHttpServletResponse getResponse()
Description copied from interface:BeanContextReturns the response declared in the context.- Specified by:
getResponsein interfaceBeanContext
-
getLocale
public Locale getLocale()
Description copied from interface:BeanContextReturns the locale declared determined using the context, determined and cached asBeanContext.getAttribute(String, Class)(BeanContext.ATTR_LOCALE).- Specified by:
getLocalein interfaceBeanContext
-
getAttribute
public <T> T getAttribute(String name, Class<T> T)
Description copied from interface:BeanContextReturns an attribute value from the context.- Specified by:
getAttributein interfaceBeanContext
-
setAttribute
public void setAttribute(String name, Object value, BeanContext.Scope scope)
Description copied from interface:BeanContextStores an attribute in the context in th given scope.- Specified by:
setAttributein interfaceBeanContext
-
getService
public <T> T getService(Class<T> type)
Description copied from interface:BeanContextretrieves a service implementation using the 'sling' script helper- Specified by:
getServicein interfaceBeanContext
-
getServices
public <T> T[] getServices(Class<T> serviceType, String filter) throws org.osgi.framework.InvalidSyntaxException
Description copied from interface:BeanContextretrieves a set of services appropriate to the filter- Specified by:
getServicesin interfaceBeanContext- Throws:
org.osgi.framework.InvalidSyntaxException
-
getType
public Class<?> getType(String className) throws ClassNotFoundException
Description copied from interface:BeanContextretrieves a class using the Slings DynamicClassLoaderManager implementation- Specified by:
getTypein interfaceBeanContext- Throws:
ClassNotFoundException
-
adaptTo
public <AdapterType> AdapterType adaptTo(@NotNull @NotNull Class<AdapterType> type)Description copied from interface:BeanContextAdapts to the components
Resource,ResourceResolver,SlingHttpServletRequest,SlingHttpServletResponse,Locale,BeanContextitself, aValueMapfor the request,SlingBeans or possibly more if defined in Sling.In case of
SlingBeanwe try the basic sling mechanism (possibly calling Sling-Models) and, failing that, try to instantiate andSlingBean.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
ValueMapandSlingBeans.- Specified by:
adaptToin interfaceorg.apache.sling.api.adapter.Adaptable- Specified by:
adaptToin interfaceBeanContext- 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:BeanContextReturns a clone of this context with the resource overridden, orthisif it already had this resource. All other internal structures of this will be referenced by the copy, too.- Specified by:
withResourcein interfaceBeanContext- Parameters:
resource- the resource- Returns:
- a context with the
BeanContext.getResource()resource, everything else (except possibly resolver) unchanged. Might bethis.
-
withLocale
public BeanContext withLocale(Locale locale)
Description copied from interface:BeanContextReturns a clone of this context with the locale overridden, orthisif it already had this locale. All other internal structures of this will be referenced by the copy, too.- Specified by:
withLocalein interfaceBeanContext- Parameters:
locale- the locale; if this is nullBeanContext.getLocale()will take this from the attributes.- Returns:
- a context with this locale, otherwise sharing everything else. Might be
this.
-
-