use of javax.management.openmbean.CompositeDataSupport in project aries by apache.
the class PropertyDataTest method testFromCompositeDataForWrapperTypes.
@Test
public void testFromCompositeDataForWrapperTypes() throws Exception {
Map<String, Object> items = new HashMap<String, Object>();
items.put(KEY, "key");
items.put(VALUE, "1");
items.put(TYPE, INTEGER);
CompositeData compositeData = new CompositeDataSupport(PROPERTY_TYPE, items);
PropertyData<Integer> intData = PropertyData.from(compositeData);
assertEquals("key", intData.getKey());
assertEquals(new Integer(1), intData.getValue());
assertEquals(INTEGER, intData.getEncodedType());
assertFalse(intData.isEncodingPrimitive());
items.clear();
items.put(KEY, "key");
items.put(VALUE, "1.0");
items.put(TYPE, DOUBLE);
compositeData = new CompositeDataSupport(PROPERTY_TYPE, items);
PropertyData<Double> doubleData = PropertyData.from(compositeData);
assertEquals("key", doubleData.getKey());
assertEquals(Double.valueOf(1.0), doubleData.getValue());
assertEquals(DOUBLE, doubleData.getEncodedType());
assertFalse(doubleData.isEncodingPrimitive());
items.clear();
items.put(KEY, "key");
items.put(VALUE, "a");
items.put(TYPE, CHARACTER);
compositeData = new CompositeDataSupport(PROPERTY_TYPE, items);
PropertyData<Character> charData = PropertyData.from(compositeData);
assertEquals("key", charData.getKey());
assertEquals(Character.valueOf('a'), charData.getValue());
assertEquals(CHARACTER, charData.getEncodedType());
assertFalse(charData.isEncodingPrimitive());
items.clear();
items.put(KEY, "key");
items.put(VALUE, "true");
items.put(TYPE, BOOLEAN);
compositeData = new CompositeDataSupport(PROPERTY_TYPE, items);
PropertyData<Boolean> booleanData = PropertyData.from(compositeData);
assertEquals("key", booleanData.getKey());
assertTrue(booleanData.getValue());
assertEquals(BOOLEAN, booleanData.getEncodedType());
assertFalse(booleanData.isEncodingPrimitive());
}
use of javax.management.openmbean.CompositeDataSupport in project deltaspike by apache.
the class DeltaSpikeConfigInfo method getConfigSources.
@Override
public TabularData getConfigSources() {
ClassLoader originalCl = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(appConfigClassLoader);
String typeName = "ConfigSources";
OpenType<?>[] types = new OpenType<?>[] { SimpleType.INTEGER, SimpleType.STRING };
String[] keys = new String[] { "Ordinal", "ConfigSource" };
CompositeType ct = new CompositeType(typeName, typeName, keys, keys, types);
TabularType type = new TabularType(typeName, typeName, ct, keys);
TabularDataSupport configSourceInfo = new TabularDataSupport(type);
ConfigSource[] configSources = ConfigResolver.getConfigSources();
for (ConfigSource configSource : configSources) {
configSourceInfo.put(new CompositeDataSupport(ct, keys, new Object[] { configSource.getOrdinal(), configSource.getConfigName() }));
}
return configSourceInfo;
} catch (OpenDataException e) {
throw new RuntimeException(e);
} finally {
// set back the original TCCL
Thread.currentThread().setContextClassLoader(originalCl);
}
}
use of javax.management.openmbean.CompositeDataSupport in project deltaspike by apache.
the class DeltaSpikeConfigInfo method getConfigEntries.
@Override
public TabularData getConfigEntries() {
ClassLoader originalCl = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(appConfigClassLoader);
List<ConfigEntry> configEntries = calculateConfigEntries();
String[] configArray = new String[configEntries.size()];
for (int i = 0; i < configEntries.size(); i++) {
ConfigEntry configEntry = configEntries.get(i);
configArray[i] = configEntry.getKey() + " = " + configEntry.getValue() + " - picked up from: " + configEntry.getFromConfigSource();
}
String typeName = "ConfigEntries";
OpenType<?>[] types = new OpenType<?>[] { SimpleType.STRING, SimpleType.STRING, SimpleType.STRING };
String[] keys = new String[] { "Key", "Value", "fromConfigSource" };
CompositeType ct = new CompositeType(typeName, typeName, keys, keys, types);
TabularType type = new TabularType(typeName, typeName, ct, keys);
TabularDataSupport configEntryInfo = new TabularDataSupport(type);
ConfigSource[] configSources = ConfigResolver.getConfigSources();
for (ConfigEntry configEntry : configEntries) {
configEntryInfo.put(new CompositeDataSupport(ct, keys, new Object[] { configEntry.getKey(), configEntry.getValue(), configEntry.getFromConfigSource() }));
}
return configEntryInfo;
} catch (OpenDataException e) {
throw new RuntimeException(e);
} finally {
// set back the original TCCL
Thread.currentThread().setContextClassLoader(originalCl);
}
}
use of javax.management.openmbean.CompositeDataSupport in project geode by apache.
the class TableConverter method toNonNullOpenValue.
Object toNonNullOpenValue(Object value) throws OpenDataException {
final Map<Object, Object> valueMap = (Map<Object, Object>) value;
if (valueMap instanceof SortedMap) {
Comparator comparator = ((SortedMap) valueMap).comparator();
if (comparator != null) {
final String msg = "Cannot convert SortedMap with non-null comparator: " + comparator;
IllegalArgumentException iae = new IllegalArgumentException(msg);
OpenDataException ode = new OpenDataException(msg);
ode.initCause(iae);
throw ode;
}
}
final TabularType tabularType = (TabularType) getOpenType();
final TabularData table = new TabularDataSupport(tabularType);
final CompositeType rowType = tabularType.getRowType();
for (Map.Entry entry : valueMap.entrySet()) {
final Object openKey = keyConverter.toOpenValue(entry.getKey());
final Object openValue = valueConverter.toOpenValue(entry.getValue());
final CompositeData row;
row = new CompositeDataSupport(rowType, keyValueArray, new Object[] { openKey, openValue });
table.put(row);
}
return table;
}
use of javax.management.openmbean.CompositeDataSupport in project geode by apache.
the class CompositeConverter method toNonNullOpenValue.
/**
* Converts to open value
*/
Object toNonNullOpenValue(Object value) throws OpenDataException {
CompositeType ct = (CompositeType) getOpenType();
if (value instanceof CompositeDataView)
return ((CompositeDataView) value).toCompositeData(ct);
if (value == null)
return null;
Object[] values = new Object[getters.length];
for (int i = 0; i < getters.length; i++) {
try {
Object got = getters[i].invoke(value, (Object[]) null);
values[i] = getterConverters[i].toOpenValue(got);
} catch (Exception e) {
throw openDataException("Error calling getter for " + itemNames[i] + ": " + e, e);
}
}
return new CompositeDataSupport(ct, itemNames, values);
}
Aggregations