Search in sources :

Example 61 with CompositeData

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);
}
Also used : Bundle(org.osgi.framework.Bundle) CompositeData(javax.management.openmbean.CompositeData) TabularData(javax.management.openmbean.TabularData) Test(org.junit.Test) AbstractIntegrationTest(org.apache.aries.jmx.AbstractIntegrationTest)

Example 62 with CompositeData

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;
}
Also used : Hashtable(java.util.Hashtable) CompositeData(javax.management.openmbean.CompositeData) Collection(java.util.Collection)

Example 63 with CompositeData

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;
}
Also used : CompositeData(javax.management.openmbean.CompositeData) Collection(java.util.Collection) TabularData(javax.management.openmbean.TabularData)

Example 64 with CompositeData

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;
}
Also used : HashMap(java.util.HashMap) OpenDataException(javax.management.openmbean.OpenDataException) CompositeData(javax.management.openmbean.CompositeData) CompositeDataSupport(javax.management.openmbean.CompositeDataSupport)

Example 65 with CompositeData

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);
}
Also used : Configuration(org.osgi.service.cm.Configuration) Hashtable(java.util.Hashtable) CompositeData(javax.management.openmbean.CompositeData) Collection(java.util.Collection) IOException(java.io.IOException)

Aggregations

CompositeData (javax.management.openmbean.CompositeData)229 TabularData (javax.management.openmbean.TabularData)91 Test (org.junit.Test)73 CompositeDataSupport (javax.management.openmbean.CompositeDataSupport)68 TabularDataSupport (javax.management.openmbean.TabularDataSupport)51 CompositeType (javax.management.openmbean.CompositeType)50 HashMap (java.util.HashMap)31 ArrayList (java.util.ArrayList)27 Map (java.util.Map)27 Bundle (org.osgi.framework.Bundle)24 ObjectName (javax.management.ObjectName)21 OpenDataException (javax.management.openmbean.OpenDataException)18 IOException (java.io.IOException)17 Collection (java.util.Collection)16 AbstractIntegrationTest (org.apache.aries.jmx.AbstractIntegrationTest)16 AuditEvent (org.nhindirect.common.audit.AuditEvent)15 TabularType (javax.management.openmbean.TabularType)13 MBeanServer (javax.management.MBeanServer)12 DefaultAuditContext (org.nhindirect.common.audit.DefaultAuditContext)11 MBeanException (javax.management.MBeanException)8