public abstract class AlexaStateModel extends Object
Constructor and Description |
---|
AlexaStateModel() |
Modifier and Type | Method and Description |
---|---|
boolean |
fromJSON(String json)
Expects a json-string which contains keys with values.
|
boolean |
fromJSON(String json,
AlexaScope scope)
Expects a json-string which contains keys with values.
|
Object |
get(Field field)
Generic getter for all the fields in this model.
|
String |
getAttributeKey()
Returns the key used to save the model in the session attributes.
|
static <TModel extends AlexaStateModel> |
getAttributeKey(Class<TModel> modelClass)
Returns the key used to save the model in the session attributes.
|
static <TModel extends AlexaStateModel> |
getAttributeKey(Class<TModel> modelClass,
String id)
Returns the key used to save the model in the session attributes.
|
AlexaStateHandler |
getHandler()
Gets the AlexaStateHandler which takes care of this model when it
saveState() , removeState() . |
String |
getId()
Gets id for this model instance.
|
List<Field> |
getSaveStateFields()
Gives you all the fields of this model which are annotated with AlexaStateSave
|
List<Field> |
getSaveStateFields(AlexaScope scope)
Gives you all the fields of this model which are annotated with AlexaStateSave and whose scope is set to a scope
which at least in included in the given scope.
|
Boolean |
hasApplicationScopedField()
It returns if any AlexaStateSave field is in the model scoped in APPLICATION
|
Boolean |
hasSessionScopedField()
It returns if any AlexaStateSave field is in the model scoped in SESSION
|
Boolean |
hasUserScopedField()
It returns if any AlexaStateSave field is in the model scoped in USER
|
void |
removeState()
Asks the state handler associated with this model to remove the model from the persistence store.
|
static <TModel extends AlexaStateModel> |
resolveAttributeKeyToId(Class<TModel> modelClass,
String attributeKey) |
void |
saveState()
Asks the state handler associated with this model to save all AlexaStateSave-tagged fields in the persistence store.
|
void |
set(Field field,
Object value)
Generic setter for all the fields in this model.
|
void |
setHandler(AlexaStateHandler handler)
Sets the AlexaStateHandler which takes care of this model when it
saveState() , removeState() . |
void |
setId(String id)
Sets an id for this model instance.
|
String |
toJSON(AlexaScope scope)
Returns a json with key-value-pairs - one for each AlexaStateSave-annotated field in this model configured to be valid
in the given scope
|
Map<String,Object> |
toMap(AlexaScope scope)
Returns a map with key-value-pairs - one for each AlexaStateSave-annotated field in this model configured to be valid
in the given scope
|
String |
toString() |
AlexaStateModel |
withHandler(AlexaStateHandler handler)
Sets the AlexaStateHandler which takes care of this model when it
saveState() , removeState() . |
public static <TModel extends AlexaStateModel> String getAttributeKey(Class<TModel> modelClass)
TModel
- The model type derived from AlexaStateModel.modelClass
- The type of an AlexaStateModel.public static <TModel extends AlexaStateModel> String getAttributeKey(Class<TModel> modelClass, String id)
TModel
- The model type derived from AlexaStateModel.modelClass
- The type of an AlexaStateModel.id
- the key for a specific instance of the modelpublic static <TModel extends AlexaStateModel> String resolveAttributeKeyToId(Class<TModel> modelClass, String attributeKey)
public String getAttributeKey()
public void setId(String id)
id
- an identifier for this model instance.public String getId()
public void setHandler(AlexaStateHandler handler)
saveState()
, removeState()
.
A state handler usually is dedicated to a persistence store which stores the AlexaStateSave-tagged fields of this modelhandler
- a state handler implementationpublic AlexaStateModel withHandler(AlexaStateHandler handler)
saveState()
, removeState()
.
A state handler usually is dedicated to a persistence store which stores the AlexaStateSave-tagged fields of this modelhandler
- a state handler implementationpublic AlexaStateHandler getHandler()
saveState()
, removeState()
.
A state handler usually is dedicated to a persistence store which stores the AlexaStateSave-tagged fields of this modelpublic void saveState() throws AlexaStateException
AlexaStateException
- Wraps all inner exceptions and gives you context related to handler and modelpublic void removeState() throws AlexaStateException
AlexaStateException
- Wraps all inner exceptions and gives you context related to handler and modelpublic Object get(Field field) throws AlexaStateException
field
- The field whose value you desire.AlexaStateException
- Wraps all inner exceptions and gives you context related to handler and modelpublic void set(Field field, Object value) throws AlexaStateException
field
- The field whose value you want to set.value
- New value for the given fieldAlexaStateException
- Wraps all inner exceptions and gives you context related to handler and modelpublic boolean fromJSON(String json) throws AlexaStateException
json
- A json with key-value-pairs where the keys likely equal some of the AlexaStateSave-tagged fields in this model.AlexaStateException
- Wraps all inner exceptions and gives you context related to handler and modelpublic boolean fromJSON(String json, AlexaScope scope) throws AlexaStateException
json
- A json with key-value-pairs where the keys likely equal some of the AlexaStateSave-tagged with given scope fields in this model.scope
- The scope a AlexaStateSave-annotated field must have to be considered for value assignmentAlexaStateException
- Wraps all inner exceptions and gives you context related to handler and modelpublic String toJSON(AlexaScope scope) throws AlexaStateException
scope
- The scope a AlexaStateSave-annotated field must have or be part of to be considered in the returned jsonAlexaStateException
- Wraps all inner exceptions and gives you context related to handler and modelpublic Map<String,Object> toMap(AlexaScope scope) throws AlexaStateException
scope
- The scope a AlexaStateSave-annotated field must have or be part of to be considered in the returned mapAlexaStateException
- Wraps all inner exceptions and gives you context related to handler and modelpublic Boolean hasSessionScopedField()
public Boolean hasUserScopedField()
public Boolean hasApplicationScopedField()
public List<Field> getSaveStateFields()
public List<Field> getSaveStateFields(AlexaScope scope)
scope
- Defines the scope which is used to filter all the AlexaStateSave-annotated fieldsCopyright © 2017. All rights reserved.