Example usage for javax.management.openmbean TabularType getIndexNames

List of usage examples for javax.management.openmbean TabularType getIndexNames

Introduction

In this page you can find the example usage for javax.management.openmbean TabularType getIndexNames.

Prototype

public List<String> getIndexNames() 

Source Link

Document

Returns, in the same order as was given to this instance's constructor, an unmodifiable List of the names of the items the values of which are used to uniquely index each row element of tabular data values described by this TabularType instance.

Usage

From source file:org.jolokia.converter.object.TabularDataConverter.java

private boolean checkForMapKey(TabularType pType) {
    List<String> indexNames = pType.getIndexNames();
    return/*ww w .jav  a2s  .c  om*/
    // Single index named "key"
    indexNames.size() == 1 && indexNames.contains(TD_KEY_KEY) &&
    // Only convert to map for simple types for all others use normal conversion. See #105 for details.
            pType.getRowType().getType(TD_KEY_KEY) instanceof SimpleType;
}

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

private boolean hasComplexKeys(TabularType pType) {
    List<String> indexes = pType.getIndexNames();
    CompositeType rowType = pType.getRowType();
    for (String index : indexes) {
        if (!(rowType.getType(index) instanceof SimpleType)) {
            return true;
        }/*www.  j  a v  a2s. c o m*/
    }
    return false;
}

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 ww w .jav  a 2 s  . c om
    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

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);/*from  w w  w. ja v a 2 s  .c  o  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   w w w.  j ava 2s .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.object.TabularDataConverter.java

private boolean checkForFullTabularDataRepresentation(JSONObject pValue, TabularType pType) {
    if (pValue.containsKey("indexNames") && pValue.containsKey("values") && pValue.size() == 2) {
        Object jsonVal = pValue.get("indexNames");
        if (!(jsonVal instanceof JSONArray)) {
            throw new IllegalArgumentException(
                    "Index names for tabular data must given as JSON array, not " + jsonVal.getClass());
        }//  w  w  w. java  2 s  . com
        JSONArray indexNames = (JSONArray) jsonVal;
        List<String> tabularIndexNames = pType.getIndexNames();
        if (indexNames.size() != tabularIndexNames.size()) {
            throw new IllegalArgumentException(
                    "Given array with index names must have " + tabularIndexNames.size() + " entries "
                            + "(given: " + indexNames + ", required: " + tabularIndexNames + ")");
        }
        for (Object index : indexNames) {
            if (!tabularIndexNames.contains(index.toString())) {
                throw new IllegalArgumentException("No index with name '" + index + "' known " + "(given: "
                        + indexNames + ", required: " + tabularIndexNames + ")");
            }
        }
        return true;
    }
    return false;
}

From source file:org.jolokia.converter.object.TabularDataConverter.java

/** {@inheritDoc} */
@Override/*w  ww  .j  a  va  2  s.  c  o  m*/
Object convertToObject(TabularType pType, Object pFrom) {

    JSONObject value = getAsJsonObject(pFrom);

    // Convert simple map representation (with rowtype "key" and "value")
    if (checkForMapAttributeWithSimpleKey(pType)) {
        return convertToTabularTypeFromMap(pType, value);
    }

    // If it is given a a full representation (with "indexNames" and "values"), then parse this
    // accordingly
    if (checkForFullTabularDataRepresentation(value, pType)) {
        return convertTabularDataFromFullRepresentation(value, pType);
    }

    // Its a plain TabularData, which is tried to convert rom a maps of maps
    TabularDataSupport tabularData = new TabularDataSupport(pType);
    // Recursively go down the map and collect the values
    putRowsToTabularData(tabularData, value, pType.getIndexNames().size());
    return tabularData;
}