Package com.composum.sling.core
Class BeanContext.Servlet
- java.lang.Object
-
- org.apache.sling.api.adapter.SlingAdaptable
-
- com.composum.sling.core.BeanContext.AbstractContext
-
- com.composum.sling.core.BeanContext.Servlet
-
- All Implemented Interfaces:
BeanContext
,Cloneable
,org.apache.sling.api.adapter.Adaptable
- Enclosing interface:
- BeanContext
public static class BeanContext.Servlet extends BeanContext.AbstractContext
a servlet API based implementation of the context interface for Beans in a Servlet context
-
-
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 org.osgi.framework.BundleContext
bundleContext
-
Fields inherited from class com.composum.sling.core.BeanContext.AbstractContext
locale
-
Fields inherited from interface com.composum.sling.core.BeanContext
ATTR_LOCALE, ATTR_REQUEST, ATTR_RESOLVER, ATTR_RESOURCE, ATTR_RESPONSE
-
-
Constructor Summary
Constructors Constructor Description Servlet(javax.servlet.ServletContext servletContext, org.osgi.framework.BundleContext bundleContext, org.apache.sling.api.SlingHttpServletRequest request, org.apache.sling.api.SlingHttpServletResponse response)
Servlet(javax.servlet.ServletContext servletContext, org.osgi.framework.BundleContext bundleContext, org.apache.sling.api.SlingHttpServletRequest request, org.apache.sling.api.SlingHttpServletResponse response, org.apache.sling.api.resource.Resource resource)
-
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
,BeanContext
itself, aValueMap
for the request,SlingBean
s or possibly more if defined in Sling.<T> T
getAttribute(String name, Class<T> T)
Returns an attribute value from the context.org.apache.sling.api.SlingHttpServletRequest
getRequest()
Returns the request declared in the context.org.apache.sling.api.resource.ResourceResolver
getResolver()
Returns the resolver declared in the context.org.apache.sling.api.resource.Resource
getResource()
Returns the resource declared in the context.org.apache.sling.api.SlingHttpServletResponse
getResponse()
Returns the response declared in the context.<T> T[]
getServices(Class<T> type, String filter)
retrieves a set of services appropriate to the filter<T> T
retrieveService(Class<T> type)
void
setAttribute(String name, Object value, BeanContext.Scope scope)
Stores an attribute in the context in th given scope.BeanContext.Servlet
withResource(org.apache.sling.api.resource.Resource resource)
Returns a clone of this context with the resource overridden, orthis
if it already had this resource.-
Methods inherited from class com.composum.sling.core.BeanContext.AbstractContext
cloneContext, getLocale, getService, getType, tryToInstantiateSlingBean, typeFits, withLocale
-
-
-
-
Constructor Detail
-
Servlet
public Servlet(javax.servlet.ServletContext servletContext, org.osgi.framework.BundleContext bundleContext, org.apache.sling.api.SlingHttpServletRequest request, org.apache.sling.api.SlingHttpServletResponse response)
-
Servlet
public Servlet(javax.servlet.ServletContext servletContext, org.osgi.framework.BundleContext bundleContext, org.apache.sling.api.SlingHttpServletRequest request, org.apache.sling.api.SlingHttpServletResponse response, org.apache.sling.api.resource.Resource resource)
-
-
Method Detail
-
getResource
public org.apache.sling.api.resource.Resource getResource()
Description copied from interface:BeanContext
Returns the resource declared in the context.
-
getResolver
public org.apache.sling.api.resource.ResourceResolver getResolver()
Description copied from interface:BeanContext
Returns the resolver declared in the context.
-
getRequest
public org.apache.sling.api.SlingHttpServletRequest getRequest()
Description copied from interface:BeanContext
Returns the request declared in the context.
-
getResponse
public org.apache.sling.api.SlingHttpServletResponse getResponse()
Description copied from interface:BeanContext
Returns the response declared in the context.
-
getAttribute
public <T> T getAttribute(String name, Class<T> T)
Description copied from interface:BeanContext
Returns an attribute value from the context.
-
setAttribute
public void setAttribute(String name, Object value, BeanContext.Scope scope)
Description copied from interface:BeanContext
Stores an attribute in the context in th given scope.
-
retrieveService
public <T> T retrieveService(Class<T> type)
- Specified by:
retrieveService
in classBeanContext.AbstractContext
-
getServices
public <T> T[] getServices(Class<T> type, String filter) throws org.osgi.framework.InvalidSyntaxException
Description copied from interface:BeanContext
retrieves a set of services appropriate to the filter- Throws:
org.osgi.framework.InvalidSyntaxException
-
adaptTo
public <AdapterType> AdapterType adaptTo(@NotNull @NotNull Class<AdapterType> type)
Adapts to the components
Resource
,ResourceResolver
,SlingHttpServletRequest
,SlingHttpServletResponse
,Locale
,BeanContext
itself, aValueMap
for the request,SlingBean
s 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 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
Adapts toValueMap
andSlingBean
s.ServletContext
andBundleContext
as well.- Specified by:
adaptTo
in interfaceorg.apache.sling.api.adapter.Adaptable
- Specified by:
adaptTo
in interfaceBeanContext
- Overrides:
adaptTo
in classBeanContext.AbstractContext
- 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.Servlet withResource(org.apache.sling.api.resource.Resource resource)
Description copied from interface:BeanContext
Returns a clone of this context with the resource overridden, orthis
if it already had this resource. All other internal structures of this will be referenced by the copy, too.- Parameters:
resource
- the resource- Returns:
- a context with the
BeanContext.getResource()
resource
, everything else (except possibly resolver) unchanged. Might bethis
.
-
-