public class JSONDatasource extends AbstractListViewDatasource implements IServiceDelegate
A JSONDatasource
provides a IListViewDatasource
implementation
to manage and represent a data model based on JSON data to be used in ListView
s.
Constructor and Description |
---|
JSONDatasource(AbstractRestOperation jsonRequest,
java.lang.String expression)
Creates a new
JSONDatasource from a given AbstractRestOperation and
a JPath expression referencing the root object within the
JSON data structure. |
JSONDatasource(java.lang.String restData)
Creates a new
JSONDatasource with a String of JSON formatted
data. |
JSONDatasource(java.lang.String restData,
java.lang.String expression)
Creates a new
JSONDatasource with a String of JSON formatted
data and a JPath expression referencing the root object within the
JSON data structure. |
Modifier and Type | Method and Description |
---|---|
java.lang.Object |
getExpressionValue(java.lang.String rootExpression)
Call this method to get the object of the data model using an expression.
|
java.lang.Object |
getExpressionValue(java.lang.String relativeExpression,
int index)
Call this method to get the object of the data model using an expression that is
relative to on object in the data model with the given row index.
|
JPath |
getRootJPath()
Get the
JPath object representing the root expression. |
java.lang.String |
getRootPathExpression()
Returns the expression used to identify the root object within the
JSON data structure.
|
void |
init(org.json.me.JSONObject jsonObject)
Initializes the data source with a
JSONObject representing the
JSON data structure.. |
void |
init(java.lang.String restData)
Initializes the data source with a JSON data structure as String.
|
void |
onOperationFailed(AbstractRestOperation operation)
Notifies this listener that the watched
AbstractRestOperation
failed. |
void |
onOperationFinished(AbstractRestOperation operation)
Notifies this listener that the watched
AbstractRestOperation
finished. |
void |
reloadElements()
Use to reload the objects managed by the datasource.
|
void |
setRootPathExpression(java.lang.String rootPathExpression)
Set a new expression to identify the root object within the JSON data structure.
|
addElement, addElementAtIndex, addElements, compare, getComparator, getElementAtIndex, getElements, getFilterExpression, getNumberOfElements, getSelectedElement, removeAllElements, removeElement, removeElementAtIndex, resort, setComparator, setFilterExpression, setSelectedElement
addObserver, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers, notifyObservers
public JSONDatasource(java.lang.String restData)
Creates a new JSONDatasource
with a String of JSON formatted
data.
restData
- the json data to be used to initialize the datasource.public JSONDatasource(java.lang.String restData, java.lang.String expression)
Creates a new JSONDatasource
with a String of JSON formatted
data and a JPath
expression referencing the root object within the
JSON data structure. The root object will be used for all other expressions.
restData
- the json data to be used to initialize the datasource.expression
- a JPath
expression to set the root object for the datasourcepublic JSONDatasource(AbstractRestOperation jsonRequest, java.lang.String expression)
Creates a new JSONDatasource
from a given AbstractRestOperation
and
a JPath
expression referencing the root object within the
JSON data structure. The root object will be used for all other expressions. As soon
as the service request finished loading the datasource will be initialized and
all Observer
objects will be notified of the changes available.
jsonRequest
- the request to load the JSON dataexpression
- a JPath
expression to set the root object for the datasourcepublic void init(java.lang.String restData)
Initializes the data source with a JSON data structure as String.
restData
- the JSON data to be usedpublic void init(org.json.me.JSONObject jsonObject)
Initializes the data source with a JSONObject
representing the
JSON data structure..
jsonObject
- the JSONObject
to be used to initialize the datasource.public void reloadElements()
IListViewDatasource
Use to reload the objects managed by the datasource.
reloadElements
in interface IListViewDatasource
reloadElements
in class AbstractListViewDatasource
public java.lang.String getRootPathExpression()
Returns the expression used to identify the root object within the
JSON data structure. Use JPath
expressions and syntax.
public void setRootPathExpression(java.lang.String rootPathExpression)
Set a new expression to identify the root object within the JSON data structure.
If null
, the expressions are evaluated on the entire data structue.
rootPathExpression
- the new JPath
root expressionpublic JPath getRootJPath()
Get the JPath
object representing the root expression. Use this object
to get data from the JSON data structure.
JPath
object representing the root objectpublic java.lang.Object getExpressionValue(java.lang.String rootExpression) throws java.lang.Exception
IListViewDatasource
Call this method to get the object of the data model using an expression.
An expression can be any String an IListViewDatasource
implementation
uses to reference an object.
getExpressionValue
in interface IListViewDatasource
getExpressionValue
in class AbstractListViewDatasource
rootExpression
- String that references an object in the data modelnull
if there was no objectjava.lang.Exception
- if an error occured evaluating the given expressionpublic java.lang.Object getExpressionValue(java.lang.String relativeExpression, int index) throws java.lang.Exception
IListViewDatasource
Call this method to get the object of the data model using an expression that is
relative to on object in the data model with the given row index.
An expression can be any String an IListViewDatasource
implementation
uses to reference an object.
getExpressionValue
in interface IListViewDatasource
getExpressionValue
in class AbstractListViewDatasource
index
- the index of the object to be used to evaluate the given expressionnull
if there was no objectjava.lang.Exception
- if an error occured evaluating the given expressionpublic void onOperationFinished(AbstractRestOperation operation)
IServiceDelegate
AbstractRestOperation
finished. AbstractRestOperation.getResponseCode()
to validate the
success of the operation. E.g.:
switch (operation.getResponseCode()) { caseHttpConnection.HTTP_OK
: break; caseHttpConnection.HTTP_FORBIDDEN
: break; }
onOperationFinished
in interface IServiceDelegate
operation
- The watched AbstractRestOperation
.public void onOperationFailed(AbstractRestOperation operation)
IServiceDelegate
AbstractRestOperation
failed. This only indicates an exception during the communication and
does not represent the HTTP status code.onOperationFailed
in interface IServiceDelegate
operation
- The watched AbstractRestOperation
.