Class TabularDataExtractor

java.lang.Object
org.jolokia.service.serializer.json.TabularDataExtractor
All Implemented Interfaces:
Extractor

public class TabularDataExtractor extends Object implements Extractor
Since:
Apr 19, 2009
Author:
roland
  • Constructor Details

    • TabularDataExtractor

      public TabularDataExtractor()
  • Method Details

    • getType

      public Class<?> getType()
      Type for which this extractor can objects of this type
      Specified by:
      getType in interface Extractor
      Returns:
      type which can be handled
    • 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 an MXBean or 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 TabularType of 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 TabularData with 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:
      extractObject in interface Extractor
      Parameters:
      pConverter - the global converter in order to be able do dispatch for serializing inner data types
      pValue - the value to convert
      pPathParts - extra arguments which contain e.g. a path
      pJsonify - 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 always IllegalArgumentException since tabular data is immutable
      Specified by:
      setObjectValue in interface Extractor
      Parameters:
      pConverter - the global converter in order to be able do dispatch for serializing inner data types
      pInner - object on which to set the value
      pAttribute - attribute of the object to set
      pValue - the new value to set
      Returns:
      the old value
      Throws:
      IllegalAccessException - if the attribute to set to is not accessible
      InvocationTargetException - reflection error
    • canSetValue

      public boolean canSetValue()
      Whether this extractor is able to set a value.
      Specified by:
      canSetValue in interface Extractor
      Returns:
      true if this extractor can set a value, false otherwise.