List of usage examples for javax.management.openmbean CompositeType getType
public OpenType<?> getType(String itemName)
null
if this CompositeType
instance does not define any item whose name is itemName. From source file:org.jolokia.converter.json.TabularDataExtractor.java
private Object getKey(CompositeType rowType, String key, String value) { OpenType keyType = rowType.getType(key); if (SimpleType.STRING == keyType) { return value; } else if (SimpleType.INTEGER == keyType) { return Integer.parseInt(value); } else if (SimpleType.LONG == keyType) { return Long.parseLong(value); } else if (SimpleType.SHORT == keyType) { return Short.parseShort(value); } else if (SimpleType.BYTE == keyType) { return Byte.parseByte(value); } else if (SimpleType.OBJECTNAME == keyType) { try {/*from ww w . j a va 2 s . co m*/ return new ObjectName(value); } catch (MalformedObjectNameException e) { throw new IllegalArgumentException("Can not convert " + value + " to an ObjectName", e); } } else { throw new IllegalArgumentException( "All keys must be a string, integer, long, short, byte or ObjectName type for accessing TabularData via a path. " + "This is not the case for '" + key + "' which is of type " + keyType); } }
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 ww .j av a2s . c o m } return false; }
From source file:org.jolokia.converter.object.CompositeTypeConverter.java
private void completeCompositeValuesWithDefaults(CompositeType pType, Map<String, Object> pCompositeValues) { /* fields that were not given in the JSON must be added with * null for Objects and the default value for primitives *//* w w w . j a v a 2 s . c om*/ for (String itemName : pType.keySet()) { if (!pCompositeValues.containsKey(itemName)) { Object itemValue = null; OpenType itemType = pType.getType(itemName); if (itemType instanceof SimpleType) { SimpleType sType = (SimpleType) itemType; itemValue = DEFAULT_PRIMITIVE_VALUES.get(sType.getClassName()); } pCompositeValues.put(itemName, itemValue); } } }
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. *///from w ww. j a v a2s. c om 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.echocat.jemoni.carbon.jmx.Jmx2CarbonBridge.java
@Nullable protected AttributeDefinition findDefinitionFor(@Nonnull ObjectName objectName, @Nonnull MBeanAttributeInfo info, @Nonnull String name, @Nonnull CompositeType compositeType) { final Set<AttributeDefinition> children = new HashSet<>(); for (String key : compositeType.keySet()) { final OpenType<?> childType = compositeType.getType(key); final AttributeDefinition child = findDefinitionFor(objectName, info, key, childType); if (child != null) { children.add(child);//from w w w .j a va 2 s . co m } } return children.isEmpty() ? null : new AttributeDefinition(objectName, name, CompositeData.class, children); }
From source file:org.jolokia.converter.object.CompositeTypeConverter.java
private void fillCompositeWithGivenValues(CompositeType pType, Map<String, Object> pCompositeValues, Map<String, Object> pSourceJson) { for (Map.Entry<String, Object> entry : pSourceJson.entrySet()) { String key = entry.getKey(); Object value = entry.getValue(); if (!pType.containsKey(key)) { throw new IllegalArgumentException("Conversion to CompositeType failed because " + key + " is not known as composite attribute key."); }/*from ww w.j ava2s . c o m*/ if (value != null) { Object convertedValue = getDispatcher().convertToObject(pType.getType(key), value); pCompositeValues.put(key, convertedValue); } } }
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 . java2 s . c o m*/ CompositeData compositeData = new CompositeDataSupport(rowType, map); tabularData.put(compositeData); } catch (OpenDataException e) { throw new IllegalArgumentException(e.getMessage(), e); } } return tabularData; }
From source file:com.appleframework.jmx.core.services.MBeanServiceImpl.java
private String getAttributeType(ServerConnection connection, ObjectAttributeInfo[] objAttributes, String attribute, ObjectName objectName) { /* first look for normal attribute */ for (int i = 0; i < objAttributes.length; i++) { if (objAttributes[i].getName().equals(attribute)) { return objAttributes[i].getType(); }/*from w w w .j a v a 2s . co m*/ } /* now look for CompositeData */ String itemName = null; final int index = attribute.indexOf(COMPOSITE_ATTR_SEPARATOR); if (index != -1) { itemName = attribute.substring(index + 1); attribute = attribute.substring(0, index); for (int i = 0; i < objAttributes.length; i++) { if (objAttributes[i].getName().equals(attribute)) { // it is a CompositeData type CompositeType type = getCompositeType(connection, objectName, objAttributes[i]); return type.getType(itemName).getClassName(); } } } throw new ServiceException(ErrorCodes.INVALID_MBEAN_ATTRIBUTE, attribute, objectName); }
From source file:com.appleframework.jmx.core.services.MBeanServiceImpl.java
/** * Expands a CompositeData object into individual attributes with the * naming convention://from w w w .j av a 2s . c om * <p> * attributeName.itemName * <p> * The items should conform to given "dataType" array. These individual * attributes are added to the <code>attributeList</code> * @param attributesList ObjectAttributeInfo instances are added to this * list */ private void handleCompositeData(ServerConnection connection, ObjectName objectName, ObjectAttributeInfo attrInfo, String[] dataTypes, List<ObjectAttributeInfo> attributesList) { CompositeType type = getCompositeType(connection, objectName, attrInfo); for (Iterator<?> it = type.keySet().iterator(); it.hasNext();) { String itemName = (String) it.next(); OpenType<?> itemType = type.getType(itemName); Class<?> itemTypeClass = getClass(itemType.getClassName(), this.getClass().getClassLoader()); for (int j = 0; j < dataTypes.length; j++) { Class<?> dataType = getClass(dataTypes[j], this.getClass().getClassLoader()); if (dataType.isAssignableFrom(itemTypeClass)) { attributesList .add(new ObjectAttributeInfo(attrInfo.getName() + COMPOSITE_ATTR_SEPARATOR + itemName, type.getDescription(itemName), itemType.getClassName(), false, true, false)); } } } }