Class TabularDataExtractor
- All Implemented Interfaces:
Extractor
- Since:
- Apr 19, 2009
- Author:
- roland
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanWhether this extractor is able to set a value.extractObject(ObjectToJsonConverter pConverter, Object pValue, Deque<String> pPathParts, boolean pJsonify) Extract aTabularData.Class<?>getType()Type for which this extractor can objects of this typesetObjectValue(StringToObjectConverter pConverter, Object pInner, String pAttribute, Object pValue) Throws alwaysIllegalArgumentExceptionsince tabular data is immutable
-
Constructor Details
-
TabularDataExtractor
public TabularDataExtractor()
-
-
Method Details
-
getType
Type for which this extractor can objects of this type -
extractObject
public Object extractObject(ObjectToJsonConverter pConverter, Object pValue, Deque<String> pPathParts, boolean pJsonify) throws AttributeNotFoundException Extract a
TabularData. The JSON representation of a tabular data is different, depending on whether it represents a map for anMXBeanor is a regular data.I.e. for an tabular data which have a row type with two column "key" and "value", then a map is returned (with the "key" values as map keys and "value" values as map values).
Otherwise a map of (one or more) maps is returned, where the map keys are taken from
TabularTypeof the presented data. E.g. if there is a single valued key"key", then the returned JSON looks like{ "mykey1" : { "key" : "mkey1", "item" : "value1", .... } "mykey2" : { "key" : "mkey2", "item" : "value2", .... } .... }For multi valued keys of simple open types (i.e.TabularType.getIndexNames()is a list with more than one element), the returned JSON structure looks like (index names here are "key" and "innerkey"){ "mykey1" : { "myinner1" : { "key" : "mkey1", "innerkey" : "myinner1", "item" : "value1", .... } "myinner2" : { "key" : "mkey1", "innerkey" : "myinner2", "item" : "value1", .... } .... } "mykey2" : { "second1" : { "key" : "mkey2", "innerkey" : "second1", "item" : "value1", .... } "second2" : { "key" : "mkey2", "innerkey" : "second2", "item" : "value1", .... } .... } .... }If keys are used, which themselves are complex objects (like composite data), this hierarchical map structure can not be used. In this case an object with two keys is returned: "indexNames" holds the name of the key index and "values" is an array of all rows which are represented as JSON objects:{ "indexNames" : [ "key", "innerkey" ], "values" : [ { "key" : "mykey1", "innerkey" : { "name" : "a", "number" : 4711 }, "item" : "value1", .... }, { "key" : "mykey2", "innerkey" : { "name" : "b", "number" : 815 }, "item" : "value2", .... }, ... ] }Accessing
TabularDatawith a path is only supported for simple type keys, i.e. each index name must point to a string representation of a simple open type. As many path elements must be provided as index names for the tabular type exists (i.e.pExtraArgs.size() >= pValue.getTabularType().getIndexNames().size()) For TabularData representing maps, a path access with the single "key" value will return the content of the "value" value. For all other TabularData, the complete row to which the path points is returned.- Specified by:
extractObjectin interfaceExtractor- Parameters:
pConverter- the global converter in order to be able do dispatch for serializing inner data typespValue- the value to convertpPathParts- extra arguments which contain e.g. a pathpJsonify- whether to convert to a JSON object/list or whether the plain object should be returned. The later is required for writing an inner value- Returns:
- the extracted object
- Throws:
AttributeNotFoundException
-
setObjectValue
public Object setObjectValue(StringToObjectConverter pConverter, Object pInner, String pAttribute, Object pValue) throws IllegalAccessException, InvocationTargetException Throws alwaysIllegalArgumentExceptionsince tabular data is immutable- Specified by:
setObjectValuein interfaceExtractor- Parameters:
pConverter- the global converter in order to be able do dispatch for serializing inner data typespInner- object on which to set the valuepAttribute- attribute of the object to setpValue- the new value to set- Returns:
- the old value
- Throws:
IllegalAccessException- if the attribute to set to is not accessibleInvocationTargetException- reflection error
-
canSetValue
public boolean canSetValue()Whether this extractor is able to set a value.- Specified by:
canSetValuein interfaceExtractor- Returns:
- true if this extractor can set a value, false otherwise.
-