public class EventInstanceBuilder extends Object
EventInstance
builder.
This class eases the creation of new EventInstance
s, and provides a fluent API to set the
EventDefinition
and output context parameter values. The builder checks that the created
EventInstance
s are valid (i.e. they are associated to a registered EventDefinition
and their
output context parameter values correspond to existing ContextParameter
s.
Modifier and Type | Method and Description |
---|---|
com.xatkit.intent.EventInstance |
build()
Creates a new
EventInstance from the provided information. |
void |
clear()
Clears the builder and reset its internal fields.
|
String |
getEventDefinitionName()
Returns the name of the
EventDefinition to bind to the created EventInstance . |
Map<String,String> |
getOutContextValues()
Returns an unmodifiable
Map containing the output context parameters to bind to the
EventInstance . |
static EventInstanceBuilder |
newBuilder(EventDefinitionRegistry registry)
Creates a new
EventInstanceBuilder from the provided registry . |
String |
prettyPrintEventDefinition()
Prints a pretty representation of the current
EventDefinition to instantiate with this builder. |
EventInstanceBuilder |
setEventDefinitionName(String eventDefinitionName)
Sets the name of the
EventDefinition to bind to the created EventInstance . |
EventInstanceBuilder |
setOutContextValue(String contextKey,
String contextValue)
Sets the created
EventInstance 's output context parameter contextKey with the given contextValue . |
public static EventInstanceBuilder newBuilder(EventDefinitionRegistry registry)
EventInstanceBuilder
from the provided registry
.
The provided EventDefinitionRegistry
is used to validate the EventDefinition
name provided by
setEventDefinitionName(String)
, and ensure that the created EventInstance
is bound to a
registered EventDefinition
.
registry
- the EventDefinitionRegistry
used to validate the EventInstance
's definition nameEventInstanceBuilder
NullPointerException
- if the provided registry
is null
public EventInstanceBuilder setEventDefinitionName(String eventDefinitionName)
EventDefinition
to bind to the created EventInstance
.
The provided eventDefinitionName
must match an existing EventDefinition
name in the provided
EventDefinitionRegistry
.
eventDefinitionName
- the name of the EventDefinition
to bind to the created EventInstance
NullPointerException
- if the provided eventDefinitionName
is null
public String getEventDefinitionName()
EventDefinition
to bind to the created EventInstance
.EventDefinition
to bind to the created EventInstance
public EventInstanceBuilder setOutContextValue(String contextKey, String contextValue)
EventInstance
's output context parameter contextKey
with the given contextValue
.
The provided contextKey
should match an existing ContextParameter
name in the associated
EventDefinition
.
contextKey
- the output context parameter namecontextValue
- the output context parameter valueNullPointerException
- if the provided contextKey
or contextValue
is null
public Map<String,String> getOutContextValues()
Map
containing the output context parameters to bind to the
EventInstance
.Map
containing the output context parameters to bind to the EventInstance
public com.xatkit.intent.EventInstance build()
EventInstance
from the provided information.
This method validates the provided information before creating the EventInstance
. The provided
EventDefinition
name is used to retrieve the associated EventDefinition
from the registry
, and the EventDefinition
's ContextParameter
s are processed and matched against the
provided output context parameters.
Note: the builder will be cleared after returning the created EventInstance
in order to allow
multiple EventInstance
creations from the same EventInstanceBuilder
(see clear()
).
EventInstance
XatkitException
- if there is no EventDefinition
associated to the provided name
, or if
the EventDefinition
does not define the ContextParameter
s representing
the provided onessetEventDefinitionName(String)
,
setOutContextValue(String, String)
,
clear()
public void clear()
Note: this method is automatically called after calling build()
.
public String prettyPrintEventDefinition()
EventDefinition
to instantiate with this builder.
This method provides a human-readable view of the builder content that is used for debugging purposes.
EventDefinition
to instantiate with this builderCopyright © 2020 SOM Research Lab. All rights reserved.