use of javax.management.openmbean.CompositeType in project karaf by apache.
the class BundlesMBeanImpl method getBundles.
public TabularData getBundles() throws MBeanException {
try {
CompositeType bundleType = new CompositeType("Bundle", "OSGi Bundle", new String[] { "ID", "Name", "Symbolic Name", "Version", "Start Level", "State", "Update Location" }, new String[] { "ID of the Bundle", "Name of the Bundle", "Symbolic Name of the Bundle", "Version of the Bundle", "Start Level of the Bundle", "Current State of the Bundle", "Update location of the Bundle" }, new OpenType[] { SimpleType.LONG, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.INTEGER, SimpleType.STRING, SimpleType.STRING });
TabularType tableType = new TabularType("Bundles", "Tables of all bundles", bundleType, new String[] { "ID" });
TabularData table = new TabularDataSupport(tableType);
Bundle[] bundles = bundleContext.getBundles();
for (Bundle bundle : bundles) {
try {
BundleInfo info = bundleService.getInfo(bundle);
String bundleStateString = info.getState().toString();
CompositeData data = new CompositeDataSupport(bundleType, new String[] { "ID", "Name", "Symbolic Name", "Version", "Start Level", "State", "Update Location" }, new Object[] { info.getBundleId(), info.getName(), info.getSymbolicName(), info.getVersion(), info.getStartLevel(), bundleStateString, info.getUpdateLocation() });
table.put(data);
} catch (Exception e) {
LOG.error(e.getMessage(), e);
}
}
return table;
} catch (Exception e) {
throw new MBeanException(null, e.toString());
}
}
use of javax.management.openmbean.CompositeType in project karaf by apache.
the class PackagesMBeanImpl method getExports.
public TabularData getExports() {
try {
String[] names = new String[] { "Name", "Version", "ID", "Bundle Name" };
CompositeType bundleType = new CompositeType("PackageExport", "Exported packages", names, new String[] { "Package name", "Version of the Package", "ID of the Bundle", "Bundle symbolic name" }, new OpenType[] { SimpleType.STRING, SimpleType.STRING, SimpleType.LONG, SimpleType.STRING });
TabularType tableType = new TabularType("PackageExports", "Exported packages", bundleType, new String[] { "Name", "Version", "ID" });
TabularData table = new TabularDataSupport(tableType);
List<PackageVersion> exports = packageService.getExports();
for (PackageVersion export : exports) {
for (Bundle bundle : export.getBundles()) {
Object[] data = new Object[] { export.getPackageName(), export.getVersion().toString(), bundle.getBundleId(), bundle.getSymbolicName() };
CompositeData comp = new CompositeDataSupport(bundleType, names, data);
LOGGER.debug("Adding CompositeDataSupport {}", comp);
table.put(comp);
}
}
return table;
} catch (RuntimeException e) {
// To avoid the exception gets swallowed by jmx
LOGGER.error(e.getMessage(), e);
throw e;
} catch (OpenDataException e) {
LOGGER.error(e.getMessage(), e);
throw new RuntimeException(e.getMessage(), e);
}
}
use of javax.management.openmbean.CompositeType in project karaf by apache.
the class ObrMBeanImpl method getBundles.
public TabularData getBundles() throws MBeanException {
try {
CompositeType bundleType = new CompositeType("OBR Resource", "Bundle available in the OBR", new String[] { "presentationname", "symbolicname", "version" }, new String[] { "Presentation Name", "Symbolic Name", "Version" }, new OpenType[] { SimpleType.STRING, SimpleType.STRING, SimpleType.STRING });
TabularType tableType = new TabularType("OBR Resources", "Table of all resources/bundles available in the OBR", bundleType, new String[] { "symbolicname", "version" });
TabularData table = new TabularDataSupport(tableType);
Resource[] resources = repositoryAdmin.discoverResources("(|(presentationname=*)(symbolicname=*))");
for (Resource resource : resources) {
try {
CompositeData data = new CompositeDataSupport(bundleType, new String[] { "presentationname", "symbolicname", "version" }, new Object[] { resource.getPresentationName(), resource.getSymbolicName(), resource.getVersion().toString() });
table.put(data);
} catch (Exception e) {
e.printStackTrace();
}
}
return table;
} catch (Exception e) {
throw new MBeanException(null, e.toString());
}
}
use of javax.management.openmbean.CompositeType in project tomee by apache.
the class LocalMBeanServer method tabularData.
public static TabularData tabularData(final String typeName, final String typeDescription, final String[] names, final Object[] values) {
if (names.length == 0) {
return null;
}
final OpenType<?>[] types = new OpenType<?>[names.length];
for (int i = 0; i < types.length; i++) {
types[i] = SimpleType.STRING;
}
try {
final CompositeType ct = new CompositeType(typeName, typeDescription, names, names, types);
final TabularType type = new TabularType(typeName, typeDescription, ct, names);
final TabularDataSupport data = new TabularDataSupport(type);
final CompositeData line = new CompositeDataSupport(ct, names, values);
data.put(line);
return data;
} catch (final OpenDataException e) {
return null;
}
}
use of javax.management.openmbean.CompositeType in project sling by apache.
the class AttributeResource method convertObject.
private Map<String, Object> convertObject(final CompositeData cd) {
final CompositeType type = cd.getCompositeType();
final Map<String, Object> result = new HashMap<String, Object>();
result.put(Constants.PROP_RESOURCE_SUPER_TYPE, Constants.TYPE_ATTRIBUTES);
result.put(Constants.PROP_RESOURCE_TYPE, type.getTypeName());
final Map<String, Object> attrMap = new TreeMap<String, Object>();
attrMap.put(Constants.PROP_RESOURCE_TYPE, Constants.TYPE_ATTRIBUTES);
result.put(Constants.RSRC_ATTRIBUTES, attrMap);
final Set<String> names = type.keySet();
for (final String name : names) {
final Map<String, Object> dataMap = new HashMap<String, Object>();
attrMap.put(name, dataMap);
dataMap.put(ResourceResolver.PROPERTY_RESOURCE_TYPE, type.getType(name));
dataMap.put(Constants.PROP_RESOURCE_SUPER_TYPE, Constants.TYPE_ATTRIBUTE);
if (type.getDescription() != null) {
dataMap.put(Constants.PROP_DESCRIPTION, type.getDescription());
}
dataMap.put(Constants.PROP_TYPE, type.getType(name).getTypeName());
final Object value = cd.get(name);
if (value != null) {
if (value.getClass().isArray()) {
final int length = Array.getLength(value);
final Object[] values = new Object[length];
for (int i = 0; i < length; i++) {
final Object o = Array.get(value, i);
values[i] = convert(o);
}
dataMap.put(Constants.PROP_VALUE, values);
} else if (value instanceof TabularData) {
dataMap.put(Constants.RSRC_VALUE, convertObject((TabularData) value));
} else if (value instanceof CompositeData) {
dataMap.put(Constants.RSRC_VALUE, convertObject((CompositeData) value));
} else {
dataMap.put(Constants.PROP_VALUE, convert(value));
}
}
}
return result;
}
Aggregations