List of usage examples for javax.management.openmbean TabularType getRowType
public CompositeType getRowType()
TabularType
instance. From source file:org.jolokia.converter.object.TabularDataConverter.java
private boolean checkForMapValue(TabularType pType) { CompositeType rowType = pType.getRowType(); // Two entries in the row: "key" and "value" return rowType.containsKey(TD_KEY_VALUE) && rowType.containsKey(TD_KEY_KEY) && rowType.keySet().size() == 2; }
From source file:org.jolokia.converter.object.TabularDataConverter.java
private TabularData convertToTabularTypeFromMap(TabularType pType, JSONObject pValue) { CompositeType rowType = pType.getRowType(); // A TabularData is requested for mapping a map for the call to an MXBean // as described in http://download.oracle.com/javase/6/docs/api/javax/management/MXBean.html // This means, we will convert a JSONObject to the required format TabularDataSupport tabularData = new TabularDataSupport(pType); @SuppressWarnings("unchecked") Map<String, String> jsonObj = (Map<String, String>) pValue; for (Map.Entry<String, String> entry : jsonObj.entrySet()) { Map<String, Object> map = new HashMap<String, Object>(); map.put("key", getDispatcher().convertToObject(rowType.getType("key"), entry.getKey())); map.put("value", getDispatcher().convertToObject(rowType.getType("value"), entry.getValue())); try {/*from ww w . j ava2 s. co m*/ CompositeData compositeData = new CompositeDataSupport(rowType, map); tabularData.put(compositeData); } catch (OpenDataException e) { throw new IllegalArgumentException(e.getMessage(), e); } } return tabularData; }
From source file:org.jolokia.converter.json.TabularDataExtractor.java
/** * Check whether the given tabular type represents a MXBean map. See the * {@link javax.management.MXBean} specification for * details how a map is converted to {@link TabularData} by the MXBean framework. * * @param pType type of tabular data to convert * @return true if this type represents an MXBean map, false otherwise. *//* w w w . ja v a 2s. c o m*/ private boolean checkForMxBeanMap(TabularType pType) { CompositeType rowType = pType.getRowType(); return rowType.containsKey("key") && rowType.containsKey("value") && rowType.keySet().size() == 2 // Only convert to map for simple types for all others use normal conversion. See #105 for details. && rowType.getType("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; }/* w w w. j a v a2 s . c o m*/ } return false; }
From source file:org.jolokia.converter.object.TabularDataConverter.java
private boolean checkForMapKey(TabularType pType) { List<String> indexNames = pType.getIndexNames(); return/*from ww w.ja v a 2s .c o m*/ // 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 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 ww .jav a2 s. c om*/ 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.object.TabularDataConverter.java
private void putRowsToTabularData(TabularDataSupport pTabularData, JSONObject pValue, int pLevel) { TabularType type = pTabularData.getTabularType(); for (Object value : pValue.values()) { if (!(value instanceof JSONObject)) { throw new IllegalArgumentException( "Cannot convert " + pValue + " to type " + type + " because the object values provided (" + value.getClass() + ") is not of the expected type JSONObject at level " + pLevel); }// w ww .j a v a 2 s . c o m JSONObject jsonValue = (JSONObject) value; if (pLevel > 1) { putRowsToTabularData(pTabularData, jsonValue, pLevel - 1); } else { pTabularData.put((CompositeData) getDispatcher().convertToObject(type.getRowType(), jsonValue)); } } }
From source file:org.jolokia.converter.object.TabularDataConverter.java
private TabularData convertTabularDataFromFullRepresentation(JSONObject pValue, TabularType pType) { JSONAware jsonVal;/* w ww .j av a2s.com*/ jsonVal = (JSONAware) pValue.get("values"); if (!(jsonVal instanceof JSONArray)) { throw new IllegalArgumentException("Values for tabular data of type " + pType + " must given as JSON array, not " + jsonVal.getClass()); } TabularDataSupport tabularData = new TabularDataSupport(pType); for (Object val : (JSONArray) jsonVal) { if (!(val instanceof JSONObject)) { throw new IllegalArgumentException( "Tabular-Data values must be given as JSON objects, not " + val.getClass()); } tabularData.put((CompositeData) getDispatcher().convertToObject(pType.getRowType(), val)); } return tabularData; }