use of javax.management.openmbean.CompositeData in project aries by apache.
the class BundleWiringStateMBeanTest method testRevisionsWiringClosure.
@Test
public void testRevisionsWiringClosure() throws Exception {
TabularData jmxWiringClosure = brsMBean.getRevisionsWiringClosure(bundleA.getBundleId(), BundleRevision.PACKAGE_NAMESPACE);
CompositeData jmxWiringA = jmxWiringClosure.get(new Object[] { bundleA.getBundleId(), 0 });
assertBundleWiring((BundleWiring) bundleA.adapt(BundleWiring.class), jmxWiringA);
Bundle b = context().getBundleByName("org.apache.aries.jmx.test.bundleb");
int bRevID = findRevisionID(jmxWiringA, b);
CompositeData jmxWiringB = jmxWiringClosure.get(new Object[] { b.getBundleId(), bRevID });
assertBundleWiring((BundleWiring) b.adapt(BundleWiring.class), jmxWiringB);
Bundle cm = context().getBundleByName("org.apache.felix.configadmin");
int cmRevID = findRevisionID(jmxWiringA, cm);
CompositeData jmxWiringCM = jmxWiringClosure.get(new Object[] { cm.getBundleId(), cmRevID });
assertBundleWiring((BundleWiring) cm.adapt(BundleWiring.class), jmxWiringCM);
Bundle sb = context().getBundle(0);
int sbRevID = findRevisionID(jmxWiringA, sb);
CompositeData jmxWiringSB = jmxWiringClosure.get(new Object[] { sb.getBundleId(), sbRevID });
assertBundleWiring((BundleWiring) sb.adapt(BundleWiring.class), jmxWiringSB);
}
use of javax.management.openmbean.CompositeData in project aries by apache.
the class RoleData method propertiesFrom.
/**
* Creates properties from TabularData object.
*
* @param data {@link TabularData} instance.
* @return translated tabular data to properties {@link Dictionary}.
*/
protected static Dictionary<String, Object> propertiesFrom(TabularData data) {
if (data == null) {
return null;
}
Dictionary<String, Object> props = new Hashtable<String, Object>();
for (CompositeData compositeData : (Collection<CompositeData>) data.values()) {
PropertyData property = PropertyData.from(compositeData);
props.put(property.getKey(), property.getValue());
}
return props;
}
use of javax.management.openmbean.CompositeData 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.CompositeData in project aries by apache.
the class BundleEventData method toCompositeData.
/**
* Returns CompositeData representing a BundleEvent typed by {@link BundleStateMBean#BUNDLE_EVENT_TYPE}
*
* @return
*/
public CompositeData toCompositeData() {
CompositeData result = null;
Map<String, Object> items = new HashMap<String, Object>();
items.put(IDENTIFIER, this.bundleId);
items.put(SYMBOLIC_NAME, this.bundleSymbolicName);
items.put(LOCATION, this.location);
items.put(EVENT, this.eventType);
try {
result = new CompositeDataSupport(BUNDLE_EVENT_TYPE, items);
} catch (OpenDataException e) {
throw new IllegalStateException("Failed to create CompositeData for BundleEvent for Bundle [" + this.bundleId + "]", e);
}
return result;
}
use of javax.management.openmbean.CompositeData in project aries by apache.
the class ConfigurationAdmin method updateForLocation.
/**
* @see org.osgi.jmx.service.cm.ConfigurationAdminMBean#updateForLocation(java.lang.String, java.lang.String, javax.management.openmbean.TabularData)
*/
@SuppressWarnings("unchecked")
public void updateForLocation(String pid, String location, TabularData configurationTable) throws IOException {
if (pid == null || pid.length() < 1) {
throw new IOException("Argument pid cannot be null or empty");
}
if (configurationTable == null) {
throw new IOException("Argument configurationTable cannot be null");
}
if (!PROPERTIES_TYPE.equals(configurationTable.getTabularType())) {
throw new IOException("Invalid TabularType [" + configurationTable.getTabularType() + "]");
}
Dictionary<String, Object> configurationProperties = new Hashtable<String, Object>();
Collection<CompositeData> compositeData = (Collection<CompositeData>) configurationTable.values();
for (CompositeData row : compositeData) {
PropertyData<? extends Class<?>> propertyData = PropertyData.from(row);
configurationProperties.put(propertyData.getKey(), propertyData.getValue());
}
Configuration config = configurationAdmin.getConfiguration(pid, location);
config.update(configurationProperties);
}
Aggregations