use of javax.management.openmbean.OpenDataException 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.OpenDataException 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.OpenDataException in project geode by apache.
the class OpenMethod method invokeWithOpenReturn.
Object invokeWithOpenReturn(Object obj, Object[] params) throws MBeanException, IllegalAccessException, InvocationTargetException {
final Object[] javaParams;
try {
javaParams = fromOpenParameters(params);
} catch (InvalidObjectException e) {
final String msg = methodName() + ": cannot convert parameters " + "from open values: " + e;
throw new MBeanException(e, msg);
}
final Object javaReturn = method.invoke(obj, javaParams);
try {
return returnTypeConverter.toOpenValue(javaReturn);
} catch (OpenDataException e) {
final String msg = methodName() + ": cannot convert return " + "value to open value: " + e;
throw new MBeanException(e, msg);
}
}
use of javax.management.openmbean.OpenDataException in project geode by apache.
the class OpenTypeConverter method makeCompositeConverter.
/**
* @return the open type converrter for a given type
*/
private static OpenTypeConverter makeCompositeConverter(Class c) throws OpenDataException {
final List<Method> methods = Arrays.asList(c.getMethods());
final SortedMap<String, Method> getterMap = OpenTypeUtil.newSortedMap();
for (Method method : methods) {
final String propertyName = propertyName(method);
if (propertyName == null)
continue;
Method old = getterMap.put(OpenTypeUtil.decapitalize(propertyName), method);
if (old != null) {
final String msg = "Class " + c.getName() + " has method name clash: " + old.getName() + ", " + method.getName();
throw new OpenDataException(msg);
}
}
final int nitems = getterMap.size();
if (nitems == 0) {
throw new OpenDataException("Can't map " + c.getName() + " to an open data type");
}
final Method[] getters = new Method[nitems];
final String[] itemNames = new String[nitems];
final OpenType[] openTypes = new OpenType[nitems];
int i = 0;
for (Map.Entry<String, Method> entry : getterMap.entrySet()) {
itemNames[i] = entry.getKey();
final Method getter = entry.getValue();
getters[i] = getter;
final Type retType = getter.getGenericReturnType();
openTypes[i] = toConverter(retType).getOpenType();
i++;
}
CompositeType compositeType = new // field
CompositeType(// field
c.getName(), // field
c.getName(), // field
itemNames, // field descriptions
itemNames, openTypes);
return new CompositeConverter(c, compositeType, itemNames, getters);
}
use of javax.management.openmbean.OpenDataException 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;
}
Aggregations