Example usage for javax.management.openmbean TabularData getTabularType

List of usage examples for javax.management.openmbean TabularData getTabularType

Introduction

In this page you can find the example usage for javax.management.openmbean TabularData getTabularType.

Prototype

public TabularType getTabularType();

Source Link

Document

Returns the tabular type describing this TabularData instance.

Usage

From source file:org.apache.aries.jmx.test.blueprint.BlueprintMBeanTest.java

@Test
public void testBlueprintStateMBean() throws Exception {
    BlueprintStateMBean stateProxy = getMBean(BlueprintStateMBean.OBJECTNAME, BlueprintStateMBean.class);

    // test getBlueprintBundleIds
    long[] bpBundleIds = stateProxy.getBlueprintBundleIds();
    assertEquals("The blueprint bundle ids are: " + Arrays.toString(bpBundleIds), 3, bpBundleIds.length);
    // test getLastEvent
    BlueprintEventValidator sampleValidator = new BlueprintEventValidator(sample.getBundleId(),
            extender.getBundleId(), 2);// w  w w.  j a v  a 2s.c o m
    sampleValidator.validate(stateProxy.getLastEvent(sample.getBundleId()));
    // test getLastEvents
    TabularData lastEvents = stateProxy.getLastEvents();
    assertEquals(BlueprintStateMBean.OSGI_BLUEPRINT_EVENTS_TYPE, lastEvents.getTabularType());
    sampleValidator.validate(lastEvents.get(new Long[] { sample.getBundleId() }));
}

From source file:org.jolokia.converter.json.TabularDataExtractor.java

private Object convertTabularDataToJson(TabularData pTd, Stack<String> pExtraArgs,
        ObjectToJsonConverter pConverter) throws AttributeNotFoundException {
    TabularType type = pTd.getTabularType();
    if (hasComplexKeys(type)) {
        return convertTabularDataDirectly(pTd, pExtraArgs, pConverter);
    } else {//ww  w. j  ava 2  s .  c o  m
        return convertToMaps(pTd, pExtraArgs, pConverter);
    }
}

From source file:org.jolokia.converter.json.TabularDataExtractor.java

private CompositeData extractCompositeDataFromPath(TabularData pTd, Stack<String> pPathStack)
        throws AttributeNotFoundException {
    // We first try it as a key
    TabularType type = pTd.getTabularType();
    List<String> indexNames = type.getIndexNames();
    checkPathFitsIndexNames(pPathStack, indexNames);

    Object keys[] = new Object[indexNames.size()];
    CompositeType rowType = type.getRowType();
    List<String> pathPartsUsed = new ArrayList<String>();
    for (int i = 0; i < indexNames.size(); i++) {
        String path = pPathStack.pop();
        pathPartsUsed.add(path);/* w  ww  .j av  a  2 s.  co  m*/
        keys[i] = getKey(rowType, indexNames.get(i), path);
    }
    if (pTd.containsKey(keys)) {
        return pTd.get(keys);
    } else {
        throw new AttributeNotFoundException("No entry with " + pathPartsUsed + " found");
    }
}

From source file:org.jolokia.converter.json.TabularDataExtractor.java

private Object convertToMaps(TabularData pTd, Stack<String> pExtraArgs, ObjectToJsonConverter pConverter)
        throws AttributeNotFoundException {
    JSONObject ret = new JSONObject();
    TabularType type = pTd.getTabularType();
    List<String> indexNames = type.getIndexNames();

    boolean found = false;
    for (CompositeData cd : (Collection<CompositeData>) pTd.values()) {
        Stack<String> path = (Stack<String>) pExtraArgs.clone();
        try {/*from ww w.j a  v a  2 s.  c  om*/
            JSONObject targetJSONObject = ret;
            // TODO: Check whether all keys can be represented as simple types. If not, well
            // we dont do any magic and return the tabular data as an array.
            for (int i = 0; i < indexNames.size() - 1; i++) {
                Object indexValue = pConverter.extractObject(cd.get(indexNames.get(i)), null, true);
                targetJSONObject = getNextMap(targetJSONObject, indexValue);
            }
            Object row = pConverter.extractObject(cd, path, true);
            String finalIndex = indexNames.get(indexNames.size() - 1);
            Object finalIndexValue = pConverter.extractObject(cd.get(finalIndex), null, true);
            targetJSONObject.put(finalIndexValue, row);
            found = true;
        } catch (ValueFaultHandler.AttributeFilteredException exp) {
            // Ignoring filtered attributes
        }
    }
    if (!pTd.isEmpty() && !found) {
        throw new ValueFaultHandler.AttributeFilteredException();
    }
    return ret;
}

From source file:org.jolokia.converter.json.TabularDataExtractor.java

private Object convertTabularDataDirectly(TabularData pTd, Stack<String> pExtraArgs,
        ObjectToJsonConverter pConverter) throws AttributeNotFoundException {
    if (!pExtraArgs.empty()) {
        throw new IllegalArgumentException("Cannot use a path for converting tabular data with complex keys ("
                + pTd.getTabularType().getRowType() + ")");
    }/*from w w w. j a v  a2  s. co m*/
    JSONObject ret = new JSONObject();
    JSONArray indexNames = new JSONArray();
    TabularType type = pTd.getTabularType();
    for (String index : type.getIndexNames()) {
        indexNames.add(index);
    }
    ret.put("indexNames", indexNames);

    JSONArray values = new JSONArray();
    // Here no special handling for wildcard pathes since pathes are not supported for this use case (yet)
    for (CompositeData cd : (Collection<CompositeData>) pTd.values()) {
        values.add(pConverter.extractObject(cd, pExtraArgs, true));
    }
    ret.put("values", values);

    return ret;
}

From source file:org.jolokia.converter.json.TabularDataExtractor.java

/**
 * <p>/*  w  w w. j a  v a  2 s  . c  o  m*/
 *  Extract a {@link TabularData}. The JSON representation of a tabular data is different,
 *  depending on whether it represents a map for an {@link javax.management.MXBean} or is a regular data.
 * </p>
 * <p>
 *  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).
 * </p>
 * <p>
 *  Otherwise a map of (one or more) maps is returned, where the map keys are taken
 *  from {@link TabularType} of the presented data. E.g. if there is a single valued key
 *  <code>"key"</code>, then the returned JSON looks like
 *  <pre>
 *      {
 *         "mykey1" : { "key" : "mkey1", "item" : "value1", .... }
 *         "mykey2" : { "key" : "mkey2", "item" : "value2", .... }
 *         ....
 *      }
 *  </pre>
 *  For multi valued keys of simple open types (i.e. {@link TabularType#getIndexNames()} is a list with more than one element), the
 *  returned JSON structure looks like (index names here are "key" and "innerkey")
 *  <pre>
 *      {
 *         "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", .... }
 *                       ....
 *                    }
 *         ....
 *      }
 *  </pre>
 *  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:
 *  <pre>
 *      {
 *        "indexNames" : [ "key", "innerkey" ],
 *        "values" : [
 *           { "key" : "mykey1", "innerkey" : { "name" : "a", "number" : 4711 }, "item" : "value1", .... },
 *           { "key" : "mykey2", "innerkey" : { "name" : "b", "number" : 815 }, "item" : "value2", .... },
 *           ...
 *        ]
 *      }
 *  </pre>
 * </p>
 * <p>
 *   Accessing {@link 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. <code>pExtraArgs.size() >= pValue.getTabularType().getIndexNames().size()</code>)
 *
 *   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.
 * </p>
 * @param pConverter the global converter in order to be able do dispatch for
 *        serializing inner data types
 * @param pValue the value to convert
 * @param pPathParts extra arguments which contain e.g. a path
 * @param 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
 * @return the extracted object
 * @throws AttributeNotFoundException
 */
public Object extractObject(ObjectToJsonConverter pConverter, Object pValue, Stack<String> pPathParts,
        boolean pJsonify) throws AttributeNotFoundException {
    TabularData td = (TabularData) pValue;
    String tdPath = pPathParts.isEmpty() ? null : pPathParts.pop();
    if (tdPath != null) {
        try {
            pPathParts.push(tdPath); // Need it later on for the index
            CompositeData cd = extractCompositeDataFromPath(td, pPathParts);
            return pConverter.extractObject(
                    cd != null && checkForMxBeanMap(td.getTabularType()) ? cd.get("value") : cd, pPathParts,
                    pJsonify);
        } catch (AttributeNotFoundException exp) {
            ValueFaultHandler faultHandler = pConverter.getValueFaultHandler();
            return faultHandler.handleException(exp);
        }
    } else {
        if (pJsonify) {
            return checkForMxBeanMap(td.getTabularType()) ? convertMxBeanMapToJson(td, pPathParts, pConverter)
                    : convertTabularDataToJson(td, pPathParts, pConverter);
        } else {
            return td;
        }
    }
}