public interface EventContext
EventContext
provides information about the event that is emitted via Service.emit(EventContext)
.
It summarizes all information required by the handlers
implementing the event and required by the framework to process the emitting of the event.
CdsModel
or the ServiceCatalog
.
Furthermore it gives access to objects which are request-bound, like for example the UserInfo
.
getEvent()
) and the targeted service (getService()
) and entity (getTarget()
).
EventContext
interface is the super-interface of more specialized EventContext
interfaces. Examples for these are CdsReadEventContext
or CdsCreateEventContext
.
The generic interface provides access to all input and output parameters of an event via the get(String)
and put(String, Object)
methods.
However the key and type of these parameters has to be known by the implementation. When using the specialized interfaces this is taken care of.
The as(Class)
method can be used to overlay an existing generic EventContext
with a more specialized EventContext
.Modifier and Type | Method and Description |
---|---|
<T extends EventContext> |
as(Class<T> clazz)
Overlays an existing
EventContext with a specialized EventContext interface (for example CdsReadEventContext or CdsCreateEventContext )
The specialized EventContext provides typed access to the input and output parameters of the event. |
static <T extends EventContext> |
create(Class<T> clazz,
String entityName)
Creates a new specialized
EventContext of concrete type T |
static EventContext |
create(String event,
String entityName)
Creates a new
EventContext |
Object |
get(String key)
Returns an input or output parameter, which was stored under the given key.
|
AuthenticationInfo |
getAuthenticationInfo() |
CdsRuntime |
getCdsRuntime()
Returns the underlying
CdsRuntime . |
ChangeSetContext |
getChangeSetContext() |
String |
getEvent() |
FeatureTogglesInfo |
getFeatureTogglesInfo() |
Messages |
getMessages() |
com.sap.cds.reflect.CdsModel |
getModel()
Returns the tenant-specific
CdsModel . |
ParameterInfo |
getParameterInfo() |
Service |
getService()
Returns the
Service (Consumption API) of the service, targeted by the EventContext . |
ServiceCatalog |
getServiceCatalog()
Returns the
ServiceCatalog , populated with all available Service instances. |
com.sap.cds.reflect.CdsEntity |
getTarget()
Returns the Reflection API
CdsEntity , for which the EventContext was created. |
UserInfo |
getUserInfo() |
boolean |
isCompleted() |
Set<String> |
keySet()
Returns an unmodifiable
set containing the keys of all parameters. |
void |
put(String key,
Object value)
Stores an input or output parameter under a given key
Whenever possible it is preferred to use specialized EventContext interfaces to guarantee correct and typed access.
|
void |
setCompleted()
Marks the
EventContext as completed. |
static EventContext create(String event, String entityName)
EventContext
event
- the name of the evententityName
- the name of the entityEventContext
static <T extends EventContext> T create(Class<T> clazz, String entityName)
EventContext
of concrete type T
T
- the specialized EventContext
typeclazz
- the Class
of the specialized EventContext
typeentityName
- the name of the entityEventContext
CdsRuntime getCdsRuntime()
CdsRuntime
.CdsRuntime
instance.com.sap.cds.reflect.CdsModel getModel()
CdsModel
.
The tenant is determined based on the request-context and the tenant information available in UserInfo
.
If no tenant is specified, or if no tenant-specific model exists, the base model is returned.CdsModel
ServiceCatalog getServiceCatalog()
ServiceCatalog
, populated with all available Service
instances.ServiceCatalog
ParameterInfo getParameterInfo()
ParameterInfo
AuthenticationInfo getAuthenticationInfo()
AuthenticationInfo
FeatureTogglesInfo getFeatureTogglesInfo()
FeatureTogglesInfo
ChangeSetContext getChangeSetContext()
ChangeSetContext
Service getService()
Service
(Consumption API) of the service, targeted by the EventContext
.
This is the service, on which the Service.emit(EventContext)
method (or specialized Consumption API) was called.Service
(Consumption API) of the service, targeted by the EventContext
.String getEvent()
com.sap.cds.reflect.CdsEntity getTarget()
CdsEntity
, for which the EventContext
was created.
If the EventContext
was created without any entity information from the CdsModel
, null
will be returned.CdsEntity
, or null
if the EventContext
was created without entity information.<T extends EventContext> T as(Class<T> clazz)
EventContext
with a specialized EventContext interface (for example CdsReadEventContext
or CdsCreateEventContext
)
The specialized EventContext provides typed access to the input and output parameters of the event.
It operates directly on the original EventContext
. Therefore changes performed on the specialized EventContext instance, returned by this method, are written through to the original instance.
In the same way changes to the original EventContext
affect the specialized EventContext instance, returned by this method.T
- the type of the specialized EventContextclazz
- The interface representing the specialized EventContextEventContext
instanceObject get(String key)
key
- the key of the parameternull
if there was no value stored under the given key.void put(String key, Object value)
key
- the key of the parametervalue
- the parameter valueSet<String> keySet()
set
containing the keys of all parameters.set
containing the keys of all parameters.get(String)
,
put(String, Object)
void setCompleted()
EventContext
as completed.
As soon as a EventContext
is completed, the Service.emit(EventContext)
processing phases BEFORE and ON are finished.
Setting an EventContext
to completed, which is already completed has no effect.boolean isCompleted()
setCompleted()
was called at least once.Copyright © 2023. All rights reserved.