public class JSONDatasource extends AbstractListDatasource
JSONDatasource
provides a IListDatasource
implementation to manage and represent a data model based on JSON data to be
used in ListView
s.Constructor and Description |
---|
JSONDatasource(java.lang.String jsonData,
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. |
JSONDatasource(java.lang.String jsonData,
java.lang.String expression,
java.lang.String filterExpression)
|
Modifier and Type | Method and Description |
---|---|
DatasourceException |
getException()
Use this method to get the last exception that has been caught while
reloading the datasource.
|
java.lang.Object |
getExpressionValue(java.lang.String rootExpression)
This method is used to retrieve an object from the data model using an
expression.
An expression can be any String an IDatasource
implementation uses to reference an object. |
java.lang.Object |
getExpressionValue(java.lang.String relativeExpression,
int index)
This method is used to get the object from 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 IDatasource
implementation uses to reference an object. |
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.
|
boolean |
hasException()
Use this method to check for exceptions that might have been caught while
reloading the datasource.
|
void |
init(org.json.me.JSONObject jsonObject)
Initializes the data source with a
JSONObject representing the
JSON data structure.. |
void |
init(java.lang.String jsonData)
Initializes the data source with a JSON data structure as String.
|
boolean |
isFilteredElement(java.lang.Object object)
Returns
true if the given object matches the filter for this
datasource returned by IListDatasource.getFilterExpression() . |
boolean |
matchesExpression(java.lang.String filterExpression,
int elementIndex)
Returns a boolean value indicating whether the passed
filterExpression is applicable for the underlying element,
represented by it's elementIndex . |
void |
reloadElements()
Use to reload the objects managed by the datasource.
|
void |
setExpressionValue(java.lang.String rootExpression,
java.lang.Object value)
This method is used to update an object in the data model.
An expression can be any String an IDatasource
implementation uses to reference an object. |
void |
setExpressionValue(java.lang.String relativeExpression,
java.lang.Object value,
int index)
This method is used to set the object in 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 IDatasource
implementation uses to reference an object. |
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, getFilteredElements, getFilterExpression, getNumberOfElements, getSelectedElement, removeAllElements, removeElement, removeElementAtIndex, resort, setComparator, setElements, setFilterExpression, setSelectedElement
addObserver, deleteObserver, notifyObservers, notifyObservers
public JSONDatasource(java.lang.String jsonData, 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.
jsonData
- the json data to be used to initialize the datasource.expression
- a JPath
expression to set the root object for the
datasourcepublic JSONDatasource(java.lang.String jsonData, java.lang.String expression, java.lang.String filterExpression)
public void init(java.lang.String jsonData)
Initializes the data source with a JSON data structure as String.
jsonData
- 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()
IListDatasource
reloadElements
in interface IListDatasource
reloadElements
in class AbstractListDatasource
public boolean hasException()
IListDatasource
hasException
in interface IListDatasource
hasException
in class AbstractListDatasource
true
if there was an exception when initializing the
elements.public DatasourceException getException()
IListDatasource
getException
in interface IListDatasource
getException
in class AbstractListDatasource
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 boolean isFilteredElement(java.lang.Object object)
IListDatasource
true
if the given object matches the filter for this
datasource returned by IListDatasource.getFilterExpression()
. You need to
implement this method specifically for your datasource and the object
types managed.isFilteredElement
in interface IListDatasource
isFilteredElement
in class AbstractListDatasource
object
- the object to test if it matches
IListDatasource.getFilterExpression()
true
if the filter returned by
IListDatasource.getFilterExpression()
matches the object,
false
if it does notpublic java.lang.Object getExpressionValue(java.lang.String rootExpression) throws java.lang.Exception
IDatasource
IDatasource
implementation uses to reference an object.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
IListDatasource
IDatasource
implementation uses to reference an object.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 setExpressionValue(java.lang.String rootExpression, java.lang.Object value) throws java.lang.Exception
IDatasource
IDatasource
implementation uses to reference an object.rootExpression
- String that references an object in the data modelvalue
- new object value for the given expressionjava.lang.Exception
- if an error occured evaluating the given expressionpublic void setExpressionValue(java.lang.String relativeExpression, java.lang.Object value, int index) throws java.lang.Exception
IListDatasource
IDatasource
implementation uses to reference an object.relativeExpression
- String that references an object in the data modelvalue
- the new value for the given expressionindex
- the index of the object to be used to evaluate the given
expressionjava.lang.Exception
- if an error occured evaluating the given expressionpublic boolean matchesExpression(java.lang.String filterExpression, int elementIndex)
IListDatasource
filterExpression
is applicable for the underlying element,
represented by it's elementIndex
. elementIndex
is out of range.
This method is used to determine the expression to template mapping used in ContentAdapter.
filterExpression
- String that references an object in the data modelelementIndex
- the index of the object to be used to evaluate the given
expression