Package com.composum.sling.core
Interface BeanContext
-
- All Superinterfaces:
org.apache.sling.api.adapter.Adaptable
- All Known Implementing Classes:
BeanContext.AbstractContext,BeanContext.AbstractScriptContext,BeanContext.Map,BeanContext.Page,BeanContext.Service,BeanContext.Servlet,BeanContext.Wrapper
@Adaptable(adaptableClass=BeanContext.class, adapters=@Adapter(condition="If the context contains an entity of the requested type",value={org.apache.sling.api.resource.Resource.class,org.apache.sling.api.resource.ResourceResolver.class,org.apache.sling.api.SlingHttpServletRequest.class,org.apache.sling.api.SlingHttpServletResponse.class})) public interface BeanContext extends org.apache.sling.api.adapter.Adaptable
The interface for the different scripting contexts (JSP, Groovy, ...) and the basic implementations for this interface. This serves as a container for the basic objects often used to initialize models.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static classBeanContext.AbstractContextthe base class of the context interface with general methodsstatic classBeanContext.AbstractScriptContextthe enhancement of the base for scripting contextsstatic classBeanContext.Mapa Map based implementation of the context interface (e.g.static classBeanContext.Pagea JSP PageContext based implementation of the context interfacestatic classBeanContext.Scopethe Scope enumeration according to the JSPs PageContextstatic classBeanContext.Servicea Service based implementation for a background service or a job executionstatic classBeanContext.Servleta servlet API based implementation of the context interface for Beans in a Servlet contextstatic classBeanContext.Wrappera wrapper implementation base
-
Field Summary
Fields Modifier and Type Field Description static StringATTR_LOCALEstatic StringATTR_REQUESTstatic StringATTR_RESOLVERstatic StringATTR_RESOURCEstatic StringATTR_RESPONSE
-
Method Summary
All Methods Instance Methods Abstract 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 asgetAttribute(String, Class)(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
-
ATTR_RESOURCE
static final String ATTR_RESOURCE
- See Also:
- Constant Field Values
-
ATTR_RESOLVER
static final String ATTR_RESOLVER
- See Also:
- Constant Field Values
-
ATTR_REQUEST
static final String ATTR_REQUEST
- See Also:
- Constant Field Values
-
ATTR_RESPONSE
static final String ATTR_RESPONSE
- See Also:
- Constant Field Values
-
ATTR_LOCALE
static final String ATTR_LOCALE
- See Also:
- Constant Field Values
-
-
Method Detail
-
getResource
org.apache.sling.api.resource.Resource getResource()
Returns the resource declared in the context.
-
getResolver
org.apache.sling.api.resource.ResourceResolver getResolver()
Returns the resolver declared in the context.
-
getRequest
org.apache.sling.api.SlingHttpServletRequest getRequest()
Returns the request declared in the context.
-
getResponse
org.apache.sling.api.SlingHttpServletResponse getResponse()
Returns the response declared in the context.
-
getLocale
Locale getLocale()
Returns the locale declared determined using the context, determined and cached asgetAttribute(String, Class)(ATTR_LOCALE).
-
getAttribute
<T> T getAttribute(String name, Class<T> T)
Returns an attribute value from the context.
-
setAttribute
void setAttribute(String name, Object value, BeanContext.Scope scope)
Stores an attribute in the context in th given scope.
-
getService
<T> T getService(Class<T> type)
retrieves a service implementation using the 'sling' script helper
-
getServices
<T> T[] getServices(Class<T> serviceType, String filter) throws org.osgi.framework.InvalidSyntaxException
retrieves a set of services appropriate to the filter- Throws:
org.osgi.framework.InvalidSyntaxException
-
getType
Class<?> getType(String className) throws ClassNotFoundException
retrieves a class using the Slings DynamicClassLoaderManager implementation- Throws:
ClassNotFoundException
-
adaptTo
<AdapterType> AdapterType adaptTo(@NotNull @NotNull Class<AdapterType> type)Adapts 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- 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
BeanContext withResource(org.apache.sling.api.resource.Resource resource)
Returns 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.- Parameters:
resource- the resource- Returns:
- a context with the
getResource()resource, everything else (except possibly resolver) unchanged. Might bethis.
-
withLocale
BeanContext withLocale(Locale locale)
Returns 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.- Parameters:
locale- the locale; if this is nullgetLocale()will take this from the attributes.- Returns:
- a context with this locale, otherwise sharing everything else. Might be
this.
-
-