Search in sources :

Example 6 with InvalidSyntaxException

use of org.osgi.framework.InvalidSyntaxException in project aries by apache.

the class BlueprintMBeanTest method testBlueprintMetaDataMBean.

@Test
public void testBlueprintMetaDataMBean() throws Exception {
    //find the Blueprint Sample bundle's container service id
    String filter = // no similar one in interfaces
    "(&(osgi.blueprint.container.symbolicname=" + sample.getSymbolicName() + ")(osgi.blueprint.container.version=" + sample.getVersion() + "))";
    ServiceReference[] serviceReferences = null;
    try {
        serviceReferences = bundleContext.getServiceReferences(BlueprintContainer.class.getName(), filter);
    } catch (InvalidSyntaxException e) {
        throw new RuntimeException(e);
    }
    long sampleBlueprintContainerServiceId = (Long) serviceReferences[0].getProperty(Constants.SERVICE_ID);
    //retrieve the proxy object
    BlueprintMetadataMBean metadataProxy = MBeanServerInvocationHandler.newProxyInstance(mbeanServer, new ObjectName(BlueprintMetadataMBean.OBJECTNAME), BlueprintMetadataMBean.class, false);
    // test getBlueprintContainerServiceIds
    long[] bpContainerServiceIds = metadataProxy.getBlueprintContainerServiceIds();
    assertEquals(3, bpContainerServiceIds.length);
    // test getBlueprintContainerServiceId
    assertEquals(sampleBlueprintContainerServiceId, metadataProxy.getBlueprintContainerServiceId(sample.getBundleId()));
    // test getComponentMetadata
    // bean: foo
    BeanValidator bv_foo = new BeanValidator("org.apache.aries.blueprint.sample.Foo", "init", "destroy");
    BeanPropertyValidator bpv_a = property("a", "5");
    BeanPropertyValidator bpv_b = property("b", "-1");
    BeanPropertyValidator bpv_bar = new BeanPropertyValidator("bar");
    bpv_bar.setObjectValueValidator(new RefValidator("bar"));
    BeanPropertyValidator bpv_currency = property("currency", "PLN");
    BeanPropertyValidator bpv_date = property("date", "2009.04.17");
    bv_foo.addPropertyValidators(bpv_a, bpv_b, bpv_bar, bpv_currency, bpv_date);
    bv_foo.validate(metadataProxy.getComponentMetadata(sampleBlueprintContainerServiceId, "foo"));
    // bean: bar
    BeanPropertyValidator bpv_value = property("value", "Hello FooBar");
    BeanPropertyValidator bpv_context = new BeanPropertyValidator("context");
    bpv_context.setObjectValueValidator(new RefValidator("blueprintBundleContext"));
    CollectionValidator cv = new CollectionValidator("java.util.List");
    cv.addCollectionValueValidators(new ValueValidator("a list element"), new ValueValidator("5", "java.lang.Integer"));
    BeanPropertyValidator bpv_list = new BeanPropertyValidator("list");
    bpv_list.setObjectValueValidator(cv);
    BeanValidator bv_bar = new BeanValidator("org.apache.aries.blueprint.sample.Bar");
    bv_bar.addPropertyValidators(bpv_value, bpv_context, bpv_list);
    bv_bar.validate(metadataProxy.getComponentMetadata(sampleBlueprintContainerServiceId, "bar"));
    // service: ref=foo, no componentId set. So using it to test getComponentIdsByType.
    String[] serviceComponentIds = metadataProxy.getComponentIdsByType(sampleBlueprintContainerServiceId, BlueprintMetadataMBean.SERVICE_METADATA);
    assertEquals("There should be two service components in this sample", 2, serviceComponentIds.length);
    MapEntryValidator mev = new MapEntryValidator();
    mev.setKeyValueValidator(new ValueValidator("key"), new ValueValidator("value"));
    RegistrationListenerValidator rglrv = new RegistrationListenerValidator("serviceRegistered", "serviceUnregistered");
    rglrv.setListenerComponentValidator(new RefValidator("fooRegistrationListener"));
    ServiceValidator sv = new ServiceValidator(4);
    sv.setServiceComponentValidator(new RefValidator("foo"));
    sv.addMapEntryValidator(mev);
    sv.addRegistrationListenerValidator(rglrv);
    sv.validate(metadataProxy.getComponentMetadata(sampleBlueprintContainerServiceId, serviceComponentIds[0]));
    // bean: fooRegistrationListener
    BeanValidator bv_fooRegistrationListener = new BeanValidator("org.apache.aries.blueprint.sample.FooRegistrationListener");
    bv_fooRegistrationListener.validate(metadataProxy.getComponentMetadata(sampleBlueprintContainerServiceId, "fooRegistrationListener"));
    // reference: ref2
    ReferenceListenerValidator rlrv_1 = new ReferenceListenerValidator("bind", "unbind");
    rlrv_1.setListenerComponentValidator(new RefValidator("bindingListener"));
    ReferenceValidator rv = new ReferenceValidator("org.apache.aries.blueprint.sample.InterfaceA", 100);
    rv.addReferenceListenerValidator(rlrv_1);
    rv.validate(metadataProxy.getComponentMetadata(sampleBlueprintContainerServiceId, "ref2"));
    // bean: bindingListener
    BeanValidator bv_bindingListener = new BeanValidator("org.apache.aries.blueprint.sample.BindingListener");
    bv_bindingListener.validate(metadataProxy.getComponentMetadata(sampleBlueprintContainerServiceId, "bindingListener"));
    // reference-list: ref-list
    ReferenceListenerValidator rlrv_2 = new ReferenceListenerValidator("bind", "unbind");
    rlrv_2.setListenerComponentValidator(new RefValidator("listBindingListener"));
    ReferenceListValidator rlv_ref_list = new ReferenceListValidator("org.apache.aries.blueprint.sample.InterfaceA");
    rlv_ref_list.addReferenceListenerValidator(rlrv_2);
    rlv_ref_list.validate(metadataProxy.getComponentMetadata(sampleBlueprintContainerServiceId, "ref-list"));
    // bean: listBindingListener
    BeanValidator bv_listBindingListener = new BeanValidator("org.apache.aries.blueprint.sample.BindingListener");
    bv_listBindingListener.validate(metadataProxy.getComponentMetadata(sampleBlueprintContainerServiceId, "listBindingListener"));
    // bean: circularReference
    ReferenceListenerValidator rlrv_3 = new ReferenceListenerValidator("bind", "unbind");
    rlrv_3.setListenerComponentValidator(new RefValidator("circularReference"));
    ReferenceListValidator rlv_2 = new ReferenceListValidator("org.apache.aries.blueprint.sample.InterfaceA", 2);
    rlv_2.addReferenceListenerValidator(rlrv_3);
    BeanPropertyValidator bpv_list_2 = new BeanPropertyValidator("list");
    bpv_list_2.setObjectValueValidator(rlv_2);
    BeanValidator bv_circularReference = new BeanValidator("org.apache.aries.blueprint.sample.BindingListener", "init");
    bv_circularReference.addPropertyValidators(bpv_list_2);
    bv_circularReference.validate(metadataProxy.getComponentMetadata(sampleBlueprintContainerServiceId, "circularReference"));
}
Also used : BeanPropertyValidator(org.apache.aries.jmx.test.blueprint.framework.BeanPropertyValidator) BlueprintMetadataMBean(org.apache.aries.jmx.blueprint.BlueprintMetadataMBean) BeanValidator(org.apache.aries.jmx.test.blueprint.framework.BeanValidator) ReferenceListenerValidator(org.apache.aries.jmx.test.blueprint.framework.ReferenceListenerValidator) ValueValidator(org.apache.aries.jmx.test.blueprint.framework.ValueValidator) ServiceValidator(org.apache.aries.jmx.test.blueprint.framework.ServiceValidator) ReferenceValidator(org.apache.aries.jmx.test.blueprint.framework.ReferenceValidator) RegistrationListenerValidator(org.apache.aries.jmx.test.blueprint.framework.RegistrationListenerValidator) ServiceReference(org.osgi.framework.ServiceReference) ObjectName(javax.management.ObjectName) RefValidator(org.apache.aries.jmx.test.blueprint.framework.RefValidator) ReferenceListValidator(org.apache.aries.jmx.test.blueprint.framework.ReferenceListValidator) MapEntryValidator(org.apache.aries.jmx.test.blueprint.framework.MapEntryValidator) CollectionValidator(org.apache.aries.jmx.test.blueprint.framework.CollectionValidator) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) Test(org.junit.Test) AbstractIntegrationTest(org.apache.aries.jmx.AbstractIntegrationTest)

Example 7 with InvalidSyntaxException

use of org.osgi.framework.InvalidSyntaxException in project aries by apache.

the class ConfigAdminContentHandler method start.

@Override
public void start(String symbolicName, String contentType, Subsystem subsystem, Coordination coordination) {
    Dictionary<String, Object> configuration = configurations.get(symbolicName);
    if (configuration == null) {
        coordination.fail(new Exception("Cannot start configuration " + symbolicName + " for subsystem " + subsystem.getSymbolicName() + " it was not previously loaded"));
        return;
    }
    try {
        ConfigurationAdmin cm = cmTracker.getService();
        if (cm == null) {
            coordination.fail(new Exception("No Configuration Admin Service found. Cannot apply configuration " + symbolicName + " to subsystem " + subsystem.getSymbolicName()));
            return;
        }
        Configuration[] matchingConfs = cm.listConfigurations(ctx.createFilter("(service.pid=" + symbolicName + ")").toString());
        if (matchingConfs == null || matchingConfs.length == 0) {
            // No configuration exists: create a new one.
            Configuration conf = cm.getConfiguration(symbolicName, "?");
            conf.update(configuration);
        }
        // Update has happened, we can forget the configuration data now
        configurations.remove(symbolicName);
    } catch (InvalidSyntaxException e) {
        // Unlikely to happen.
        coordination.fail(new Exception("Failed to list existing configurations for " + symbolicName + " in subsystem " + subsystem.getSymbolicName(), e));
    } catch (IOException e) {
        coordination.fail(new Exception("Problem applying configuration " + symbolicName + " in subsystem " + subsystem.getSymbolicName(), e));
    }
}
Also used : Configuration(org.osgi.service.cm.Configuration) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) IOException(java.io.IOException) ConfigurationAdmin(org.osgi.service.cm.ConfigurationAdmin) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) IOException(java.io.IOException)

Example 8 with InvalidSyntaxException

use of org.osgi.framework.InvalidSyntaxException in project aries by apache.

the class Activator method start.

public void start(BundleContext ctx) {
    context = ctx;
    // Expose blueprint namespace handler if xbean is present
    try {
        nshReg = JdbcNamespaceHandler.register(ctx);
    } catch (NoClassDefFoundError e) {
        LOGGER.warn("Unable to register JDBC blueprint namespace handler (xbean-blueprint not available).");
    } catch (Exception e) {
        LOGGER.error("Unable to register JDBC blueprint namespace handler", e);
    }
    Filter filter;
    String flt = "(&(|(objectClass=javax.sql.XADataSource)(objectClass=javax.sql.DataSource))(!(aries.managed=true)))";
    try {
        filter = context.createFilter(flt);
    } catch (InvalidSyntaxException e) {
        throw new IllegalStateException(e);
    }
    t = new ServiceTracker<CommonDataSource, ManagedDataSourceFactory>(ctx, filter, this);
    tm = new SingleServiceTracker<AriesTransactionManager>(ctx, AriesTransactionManager.class, this);
    tm.open();
}
Also used : Filter(org.osgi.framework.Filter) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) AriesTransactionManager(org.apache.aries.transaction.AriesTransactionManager) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) CommonDataSource(javax.sql.CommonDataSource)

Example 9 with InvalidSyntaxException

use of org.osgi.framework.InvalidSyntaxException in project aries by apache.

the class BlueprintMetadata method getBlueprintContainer.

private BlueprintContainer getBlueprintContainer(long containerServiceId) throws IOException {
    String filter = "(" + Constants.SERVICE_ID + "=" + containerServiceId + ")";
    ServiceReference[] serviceReferences = null;
    try {
        serviceReferences = bundleContext.getServiceReferences(BlueprintContainer.class.getName(), filter);
    } catch (InvalidSyntaxException e) {
        throw new IOException(e);
    }
    if (serviceReferences == null || serviceReferences.length < 1) {
        throw new IOException("Invalid BlueprintContainer service id: " + containerServiceId);
    }
    return (BlueprintContainer) bundleContext.getService(serviceReferences[0]);
}
Also used : BlueprintContainer(org.osgi.service.blueprint.container.BlueprintContainer) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) IOException(java.io.IOException) ServiceReference(org.osgi.framework.ServiceReference)

Example 10 with InvalidSyntaxException

use of org.osgi.framework.InvalidSyntaxException in project aries by apache.

the class AbstractIntegrationTest method getOsgiService.

protected <T> T getOsgiService(BundleContext bc, Class<T> type, String filter, long timeout) {
    ServiceTracker tracker = null;
    try {
        String flt;
        if (filter != null) {
            if (filter.startsWith("(")) {
                flt = "(&(" + Constants.OBJECTCLASS + "=" + type.getName() + ")" + filter + ")";
            } else {
                flt = "(&(" + Constants.OBJECTCLASS + "=" + type.getName() + ")(" + filter + "))";
            }
        } else {
            flt = "(" + Constants.OBJECTCLASS + "=" + type.getName() + ")";
        }
        Filter osgiFilter = FrameworkUtil.createFilter(flt);
        tracker = new ServiceTracker(bc == null ? bundleContext : bc, osgiFilter, null);
        tracker.open();
        // add tracker to the list of trackers we close at tear down
        srs.add(tracker);
        Object x = tracker.waitForService(timeout);
        Object svc = type.cast(x);
        if (svc == null) {
            throw new RuntimeException("Gave up waiting for service " + flt);
        }
        return type.cast(svc);
    } catch (InvalidSyntaxException e) {
        throw new IllegalArgumentException("Invalid filter", e);
    } catch (InterruptedException e) {
        throw new RuntimeException(e);
    }
}
Also used : ServiceTracker(org.osgi.util.tracker.ServiceTracker) Filter(org.osgi.framework.Filter) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException)

Aggregations

InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)105 ServiceReference (org.osgi.framework.ServiceReference)54 Filter (org.osgi.framework.Filter)26 ArrayList (java.util.ArrayList)22 IOException (java.io.IOException)20 BundleContext (org.osgi.framework.BundleContext)16 ServiceTracker (org.osgi.util.tracker.ServiceTracker)14 HashMap (java.util.HashMap)12 Configuration (org.osgi.service.cm.Configuration)12 Map (java.util.Map)10 Test (org.junit.Test)9 Dictionary (java.util.Dictionary)8 Hashtable (java.util.Hashtable)8 List (java.util.List)6 ConfigurationException (org.osgi.service.cm.ConfigurationException)6 Metacard (ddf.catalog.data.Metacard)4 ConfigurationAdmin (org.osgi.service.cm.ConfigurationAdmin)4 CatalogFramework (ddf.catalog.CatalogFramework)3 CatalogTransformerException (ddf.catalog.transform.CatalogTransformerException)3 InputTransformer (ddf.catalog.transform.InputTransformer)3