Search in sources :

Example 36 with OpenDataException

use of javax.management.openmbean.OpenDataException in project aries by apache.

the class BundleWiringData method getCapabilitiesCompositeData.

public static CompositeData[] getCapabilitiesCompositeData(List<BundleCapability> bundleCapabilities) {
    try {
        CompositeData[] data = new CompositeData[bundleCapabilities.size()];
        for (int i = 0; i < bundleCapabilities.size(); i++) {
            BundleCapability requirement = bundleCapabilities.get(i);
            CompositeData cd = BundleWiringData.getCapReqCompositeData(BundleWiringStateMBean.BUNDLE_CAPABILITY_TYPE, requirement.getNamespace(), requirement.getAttributes().entrySet(), requirement.getDirectives().entrySet());
            data[i] = cd;
        }
        return data;
    } catch (OpenDataException e) {
        throw new IllegalStateException("Can't create CompositeData", e);
    }
}
Also used : OpenDataException(javax.management.openmbean.OpenDataException) CompositeData(javax.management.openmbean.CompositeData) BundleCapability(org.osgi.framework.wiring.BundleCapability)

Example 37 with OpenDataException

use of javax.management.openmbean.OpenDataException in project aries by apache.

the class PropertyData method toCompositeData.

/**
     * Returns CompositeData representing a Property typed by {@link JmxConstants#PROPERTY_TYPE}.
     * @return
     */
public CompositeData toCompositeData() {
    CompositeData result = null;
    Map<String, Object> items = new HashMap<String, Object>();
    items.put(KEY, this.key);
    items.put(VALUE, this.encodedValue);
    items.put(TYPE, this.encodedType);
    try {
        result = new CompositeDataSupport(PROPERTY_TYPE, items);
    } catch (OpenDataException e) {
        throw new IllegalStateException("Failed to create CompositeData for Property [" + this.key + ":" + this.value + "]", e);
    }
    return result;
}
Also used : HashMap(java.util.HashMap) OpenDataException(javax.management.openmbean.OpenDataException) CompositeData(javax.management.openmbean.CompositeData) CompositeDataSupport(javax.management.openmbean.CompositeDataSupport) TypeUtils.fromString(org.apache.aries.jmx.util.TypeUtils.fromString)

Example 38 with OpenDataException

use of javax.management.openmbean.OpenDataException in project aries by apache.

the class ServiceEventData method toCompositeData.

/**
     * Returns CompositeData representing a ServiceEvent typed by {@link ServiceStateMBean#SERVICE_EVENT_TYPE}.
     * @return
     */
public CompositeData toCompositeData() {
    CompositeData result = null;
    Map<String, Object> items = new HashMap<String, Object>();
    items.put(IDENTIFIER, this.serviceId);
    items.put(OBJECT_CLASS, this.serviceInterfaces);
    items.put(BUNDLE_IDENTIFIER, this.bundleId);
    items.put(BUNDLE_LOCATION, this.bundleLocation);
    items.put(BUNDLE_SYMBOLIC_NAME, this.bundleSymbolicName);
    items.put(EVENT, this.eventType);
    try {
        result = new CompositeDataSupport(SERVICE_EVENT_TYPE, items);
    } catch (OpenDataException e) {
        throw new IllegalStateException("Failed to create CompositeData for ServiceEvent for Service [" + this.serviceId + "]", 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 39 with OpenDataException

use of javax.management.openmbean.OpenDataException in project aries by apache.

the class BundleData method toCompositeData.

public CompositeData toCompositeData(Collection<String> itemNames) {
    Map<String, Object> items = new HashMap<String, Object>();
    items.put(IDENTIFIER, this.identifier);
    if (itemNames.contains(EXPORTED_PACKAGES))
        items.put(EXPORTED_PACKAGES, this.exportedPackages);
    if (itemNames.contains(FRAGMENT))
        items.put(FRAGMENT, this.fragment);
    if (itemNames.contains(FRAGMENTS))
        items.put(FRAGMENTS, toLong(this.fragments));
    if (itemNames.contains(HOSTS))
        items.put(HOSTS, toLong(this.hosts));
    if (itemNames.contains(IMPORTED_PACKAGES))
        items.put(IMPORTED_PACKAGES, this.importedPackages);
    if (itemNames.contains(LAST_MODIFIED))
        items.put(LAST_MODIFIED, this.lastModified);
    if (itemNames.contains(LOCATION))
        items.put(LOCATION, this.location);
    if (itemNames.contains(PERSISTENTLY_STARTED))
        items.put(PERSISTENTLY_STARTED, this.persistentlyStarted);
    if (itemNames.contains(REGISTERED_SERVICES))
        items.put(REGISTERED_SERVICES, toLong(this.registeredServices));
    if (itemNames.contains(REMOVAL_PENDING))
        items.put(REMOVAL_PENDING, this.removalPending);
    if (itemNames.contains(REQUIRED))
        items.put(REQUIRED, this.required);
    if (itemNames.contains(REQUIRED_BUNDLES))
        items.put(REQUIRED_BUNDLES, toLong(this.requiredBundles));
    if (itemNames.contains(REQUIRING_BUNDLES))
        items.put(REQUIRING_BUNDLES, toLong(this.requiringBundles));
    if (itemNames.contains(SERVICES_IN_USE))
        items.put(SERVICES_IN_USE, toLong(this.servicesInUse));
    if (itemNames.contains(START_LEVEL))
        items.put(START_LEVEL, this.bundleStartLevel);
    if (itemNames.contains(STATE))
        items.put(STATE, this.state);
    if (itemNames.contains(SYMBOLIC_NAME))
        items.put(SYMBOLIC_NAME, this.symbolicName);
    if (itemNames.contains(VERSION))
        items.put(VERSION, this.version);
    if (itemNames.contains(HEADERS)) {
        TabularData headerTable = new TabularDataSupport(HEADERS_TYPE);
        for (Header header : this.headers) {
            headerTable.put(header.toCompositeData());
        }
        items.put(HEADERS, headerTable);
    }
    String[] allItemNames = BUNDLE_TYPE.keySet().toArray(new String[] {});
    Object[] itemValues = new Object[allItemNames.length];
    for (int i = 0; i < allItemNames.length; i++) {
        itemValues[i] = items.get(allItemNames[i]);
    }
    try {
        return new CompositeDataSupport(BUNDLE_TYPE, allItemNames, itemValues);
    } catch (OpenDataException e) {
        throw new IllegalStateException("Failed to create CompositeData for BundleData [" + this.identifier + "]", e);
    }
}
Also used : HashMap(java.util.HashMap) CompositeDataSupport(javax.management.openmbean.CompositeDataSupport) TabularData(javax.management.openmbean.TabularData) OpenDataException(javax.management.openmbean.OpenDataException) TabularDataSupport(javax.management.openmbean.TabularDataSupport)

Example 40 with OpenDataException

use of javax.management.openmbean.OpenDataException in project deltaspike by apache.

the class DynamicMBeanWrapper method toTabularData.

private TabularData toTabularData(final String typeName, final String description, final Table table) {
    final OpenType<?>[] types = new OpenType<?>[table.getColumnNames().size()];
    for (int i = 0; i < types.length; i++) {
        types[i] = SimpleType.STRING;
    }
    try {
        final String[] keys = table.getColumnNames().toArray(new String[table.getColumnNames().size()]);
        final CompositeType ct = new CompositeType(typeName, description, keys, keys, types);
        final TabularType type = new TabularType(typeName, description, ct, keys);
        final TabularDataSupport data = new TabularDataSupport(type);
        for (final Collection<String> line : table.getLines()) {
            data.put(new CompositeDataSupport(ct, keys, line.toArray(new Object[line.size()])));
        }
        return data;
    } catch (final OpenDataException e) {
        throw new IllegalArgumentException(e);
    }
}
Also used : OpenType(javax.management.openmbean.OpenType) OpenDataException(javax.management.openmbean.OpenDataException) TabularDataSupport(javax.management.openmbean.TabularDataSupport) TabularType(javax.management.openmbean.TabularType) CompositeDataSupport(javax.management.openmbean.CompositeDataSupport) CompositeType(javax.management.openmbean.CompositeType)

Aggregations

OpenDataException (javax.management.openmbean.OpenDataException)51 CompositeDataSupport (javax.management.openmbean.CompositeDataSupport)24 TabularDataSupport (javax.management.openmbean.TabularDataSupport)22 TabularType (javax.management.openmbean.TabularType)22 CompositeType (javax.management.openmbean.CompositeType)21 CompositeData (javax.management.openmbean.CompositeData)17 OpenType (javax.management.openmbean.OpenType)15 ObjectName (javax.management.ObjectName)8 HashMap (java.util.HashMap)6 Map (java.util.Map)5 MBeanServer (javax.management.MBeanServer)5 TabularData (javax.management.openmbean.TabularData)5 ArrayType (javax.management.openmbean.ArrayType)4 InvalidObjectException (java.io.InvalidObjectException)3 SortedMap (java.util.SortedMap)3 JMException (javax.management.JMException)3 StandardMBean (javax.management.StandardMBean)3 IOException (java.io.IOException)2 GenericArrayType (java.lang.reflect.GenericArrayType)2 Method (java.lang.reflect.Method)2