use of javax.management.openmbean.TabularData in project aries by apache.
the class BundleState method listBundles.
private TabularData listBundles(Collection<String> items) throws IOException {
Bundle[] containerBundles = bundleContext.getBundles();
List<BundleData> bundleDatas = new ArrayList<BundleData>();
if (containerBundles != null) {
for (Bundle containerBundle : containerBundles) {
bundleDatas.add(new BundleData(bundleContext, containerBundle, packageAdmin, startLevel));
}
}
TabularData bundleTable = new TabularDataSupport(BUNDLES_TYPE);
for (BundleData bundleData : bundleDatas) {
bundleTable.put(bundleData.toCompositeData(items));
}
return bundleTable;
}
use of javax.management.openmbean.TabularData in project aries by apache.
the class BundleState method getHeaders.
private TabularData getHeaders(Dictionary<String, String> bundleHeaders) {
List<Header> headers = new ArrayList<Header>();
Enumeration<String> keys = bundleHeaders.keys();
while (keys.hasMoreElements()) {
String key = keys.nextElement();
headers.add(new Header(key, bundleHeaders.get(key)));
}
TabularData headerTable = new TabularDataSupport(HEADERS_TYPE);
for (Header header : headers) {
headerTable.put(header.toCompositeData());
}
return headerTable;
}
use of javax.management.openmbean.TabularData in project aries by apache.
the class BundleData method from.
/**
* Constructs a <code>BundleData</code> object from the given <code>CompositeData</code>
*
* @param compositeData
* @return
* @throws IlleglArgumentException
* if compositeData is null or not of type {@link BundleStateMBean#BUNDLE_TYPE}
*/
@SuppressWarnings("unchecked")
public static BundleData from(CompositeData compositeData) throws IllegalArgumentException {
if (compositeData == null) {
throw new IllegalArgumentException("Argument compositeData cannot be null");
}
if (!compositeData.getCompositeType().equals(BUNDLE_TYPE)) {
throw new IllegalArgumentException("Invalid CompositeType [" + compositeData.getCompositeType() + "]");
}
BundleData bundleData = new BundleData();
bundleData.exportedPackages = (String[]) compositeData.get(EXPORTED_PACKAGES);
bundleData.fragment = (Boolean) compositeData.get(FRAGMENT);
bundleData.fragments = toPrimitive((Long[]) compositeData.get(FRAGMENTS));
bundleData.hosts = toPrimitive((Long[]) compositeData.get(HOSTS));
bundleData.identifier = (Long) compositeData.get(IDENTIFIER);
bundleData.importedPackages = (String[]) compositeData.get(IMPORTED_PACKAGES);
bundleData.lastModified = (Long) compositeData.get(LAST_MODIFIED);
bundleData.location = (String) compositeData.get(LOCATION);
bundleData.persistentlyStarted = (Boolean) compositeData.get(PERSISTENTLY_STARTED);
bundleData.registeredServices = toPrimitive((Long[]) compositeData.get(REGISTERED_SERVICES));
bundleData.removalPending = (Boolean) compositeData.get(REMOVAL_PENDING);
bundleData.required = (Boolean) compositeData.get(REQUIRED);
bundleData.requiredBundles = toPrimitive((Long[]) compositeData.get(REQUIRED_BUNDLES));
bundleData.requiringBundles = toPrimitive((Long[]) compositeData.get(REQUIRING_BUNDLES));
bundleData.servicesInUse = toPrimitive((Long[]) compositeData.get(SERVICES_IN_USE));
bundleData.bundleStartLevel = (Integer) compositeData.get(START_LEVEL);
bundleData.state = (String) compositeData.get(STATE);
bundleData.symbolicName = (String) compositeData.get(SYMBOLIC_NAME);
bundleData.version = (String) compositeData.get(VERSION);
TabularData headerTable = (TabularData) compositeData.get(HEADERS);
Collection<CompositeData> headerData = (Collection<CompositeData>) headerTable.values();
for (CompositeData headerRow : headerData) {
bundleData.headers.add(Header.from(headerRow));
}
return bundleData;
}
use of javax.management.openmbean.TabularData in project aries by apache.
the class RoleData method toTabularData.
/**
* Creates TabularData from Dictionary.
*
* @param props Dictionary instance.
* @return TabularData instance.
*/
protected static TabularData toTabularData(Dictionary<String, Object> props) {
if (props == null) {
return null;
}
TabularData data = new TabularDataSupport(JmxConstants.PROPERTIES_TYPE);
for (Enumeration<String> keys = props.keys(); keys.hasMoreElements(); ) {
String key = keys.nextElement();
data.put(PropertyData.newInstance(key, props.get(key)).toCompositeData());
}
return data;
}
use of javax.management.openmbean.TabularData in project aries by apache.
the class ServiceDataTest method testToCompositeData.
@Test
public void testToCompositeData() throws Exception {
ServiceReference<?> reference = mock(ServiceReference.class);
Bundle bundle = mock(Bundle.class);
String[] interfaces = new String[] { "org.apache.aries.jmx.Test", "org.apache.aries.jmx.Mock" };
Bundle b1 = mock(Bundle.class);
when(b1.getBundleId()).thenReturn(new Long(6));
Bundle b2 = mock(Bundle.class);
when(b2.getBundleId()).thenReturn(new Long(9));
when(reference.getProperty(Constants.SERVICE_ID)).thenReturn(new Long(98));
when(reference.getBundle()).thenReturn(bundle);
when(bundle.getBundleId()).thenReturn(new Long(34));
when(reference.getProperty(Constants.OBJECTCLASS)).thenReturn(interfaces);
when(reference.getUsingBundles()).thenReturn(new Bundle[] { b1, b2 });
when(reference.getPropertyKeys()).thenReturn(new String[] { "x.vendor", "x.domain", "x.index", "x.optimized" });
when(reference.getProperty("x.vendor")).thenReturn("aries");
when(reference.getProperty("x.domain")).thenReturn("test");
when(reference.getProperty("x.index")).thenReturn(new Long(67));
when(reference.getProperty("x.optimized")).thenReturn(true);
ServiceData serviceData = new ServiceData(reference);
CompositeData compositeData = serviceData.toCompositeData();
assertEquals(new Long(98), compositeData.get(IDENTIFIER));
assertEquals(new Long(34), compositeData.get(BUNDLE_IDENTIFIER));
assertArrayEquals(new Long[] { new Long(6), new Long(9) }, (Long[]) compositeData.get(USING_BUNDLES));
assertArrayEquals(interfaces, (String[]) compositeData.get(OBJECT_CLASS));
TabularData propertiesTable = (TabularData) compositeData.get(PROPERTIES);
@SuppressWarnings("unchecked") Collection<CompositeData> propertyData = (Collection<CompositeData>) propertiesTable.values();
assertEquals(4, propertyData.size());
for (CompositeData propertyRow : propertyData) {
String key = (String) propertyRow.get(KEY);
if (key.equals("x.vendor")) {
assertEquals("aries", propertyRow.get(VALUE));
assertEquals(STRING, propertyRow.get(TYPE));
} else if (key.equals("x.domain")) {
assertEquals("test", propertyRow.get(VALUE));
assertEquals(STRING, propertyRow.get(TYPE));
} else if (key.equals("x.index")) {
assertEquals("67", propertyRow.get(VALUE));
assertEquals(LONG, propertyRow.get(TYPE));
} else if (key.equals("x.optimized")) {
assertEquals("true", propertyRow.get(VALUE));
assertEquals(BOOLEAN, propertyRow.get(TYPE));
} else {
fail("unknown key parsed from properties");
}
}
}
Aggregations