Example usage for javax.management.openmbean TabularData isEmpty

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

Introduction

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

Prototype

public boolean isEmpty();

Source Link

Document

Returns true if the number of CompositeData values (ie the number of rows) contained in this TabularData instance is zero.

Usage

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

private Object convertMxBeanMapToJson(TabularData pTd, Stack<String> pExtraArgs,
        ObjectToJsonConverter pConverter) throws AttributeNotFoundException {
    JSONObject ret = new JSONObject();
    for (Object rowObject : pTd.values()) {
        CompositeData row = (CompositeData) rowObject;
        Stack<String> path = (Stack<String>) pExtraArgs.clone();
        Object keyObject = row.get("key");
        if (keyObject != null) {
            try {
                Object value = pConverter.extractObject(row.get("value"), path, true);
                ret.put(keyObject.toString(), value);
            } catch (ValueFaultHandler.AttributeFilteredException exp) {
                // Skip to next object since attribute was filtered
            }/*from w  w  w .j ava 2 s .  c o m*/
        }
    }
    if (!pTd.isEmpty() && ret.isEmpty()) {
        // Bubble up if not a single thingy has been found
        throw new ValueFaultHandler.AttributeFilteredException();
    }
    return ret;
}

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 va  2  s. co m
            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;
}