org.inria.ns.reflex.xml.json
Class Context

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractList
          extended by org.inria.ns.reflex.xml.json.Context
All Implemented Interfaces:
Iterable, Collection, List

public class Context
extends AbstractList

A data set context for JSON.

Author:
Philippe Poulard
See Also:
DataSet.feedContext(Object)

Constructor Summary
Context(JSONContext context)
          Create a new context.
 
Method Summary
 void add(int index, Object element)
          Add an element to the current item of the JSON structure.
 Object get(int index)
          Get the child of the current item of the JSON structure at the specified position.
 boolean remove(Object element)
          Remove an element in the current item of the JSON structure.
 Object set(int index, Object element)
          Set an element to the current item of the JSON structure.
 int size()
          Get the size of the current item of the JSON structure.
 
Methods inherited from class java.util.AbstractList
add, addAll, clear, equals, hashCode, indexOf, iterator, lastIndexOf, listIterator, listIterator, remove, subList
 
Methods inherited from class java.util.AbstractCollection
addAll, contains, containsAll, isEmpty, removeAll, retainAll, toArray, toArray, toString
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.List
addAll, contains, containsAll, isEmpty, removeAll, retainAll, toArray, toArray
 

Constructor Detail

Context

public Context(JSONContext context)
Create a new context. The JSON context should be built with a Configuration instance from this package, but this is not mandatory.

Parameters:
context - The underlying JSON context.
See Also:
Configuration
Method Detail

get

public Object get(int index)
Get the child of the current item of the JSON structure at the specified position.

Specified by:
get in interface List
Specified by:
get in class AbstractList
Parameters:
index - The index of the child.
Returns:
The child at the index specified.

size

public int size()
Get the size of the current item of the JSON structure.

Specified by:
size in interface Collection
Specified by:
size in interface List
Specified by:
size in class AbstractCollection
Returns:
The size of the current JSON item.

set

public Object set(int index,
                  Object element)
Set an element to the current item of the JSON structure.

Specified by:
set in interface List
Overrides:
set in class AbstractList
Parameters:
index - The index of the element.
element - If it is a QName and the current item of the JSON structure is a JSON object, it is set to the JSON context, if it is a named item attribute, it is set as an attribute of the current item of the JSON structure, otherwise as a child.
See Also:
QName, NamedItem

add

public void add(int index,
                Object element)
Add an element to the current item of the JSON structure.

Specified by:
add in interface List
Overrides:
add in class AbstractList
Parameters:
index - The index of the element to add.
element - If it is a string, it is considered as a parsable JSON structure, if it is a QName and the current item of the JSON structure is a JSON object, it is set to the JSON context, if it is a named item attribute, it is set as an attribute of the current item of the JSON structure, otherwise as a child.
See Also:
QName, NamedItem

remove

public boolean remove(Object element)
Remove an element in the current item of the JSON structure.

Specified by:
remove in interface Collection
Specified by:
remove in interface List
Overrides:
remove in class AbstractCollection
Parameters:
element - A named item attribute is removed from the attributes of the current item of the JSON structure, otherwise it is removed from its children.
Returns:
true if the object was removed, false otherwise.