Search in sources :

Example 1 with BundleWiring

use of org.osgi.framework.wiring.BundleWiring in project hibernate-orm by hibernate.

the class OsgiSessionFactoryService method buildSessionFactory.

private Object buildSessionFactory(Bundle requestingBundle, OsgiClassLoader osgiClassLoader) {
    final BootstrapServiceRegistryBuilder bsrBuilder = new BootstrapServiceRegistryBuilder();
    bsrBuilder.applyClassLoaderService(new OSGiClassLoaderServiceImpl(osgiClassLoader, osgiServiceUtil));
    final Integrator[] integrators = osgiServiceUtil.getServiceImpls(Integrator.class);
    for (Integrator integrator : integrators) {
        bsrBuilder.applyIntegrator(integrator);
    }
    final StrategyRegistrationProvider[] strategyRegistrationProviders = osgiServiceUtil.getServiceImpls(StrategyRegistrationProvider.class);
    for (StrategyRegistrationProvider strategyRegistrationProvider : strategyRegistrationProviders) {
        bsrBuilder.applyStrategySelectors(strategyRegistrationProvider);
    }
    final BootstrapServiceRegistry bsr = bsrBuilder.build();
    final StandardServiceRegistryBuilder ssrBuilder = new StandardServiceRegistryBuilder(bsr);
    // Allow bundles to put the config file somewhere other than the root level.
    final BundleWiring bundleWiring = (BundleWiring) requestingBundle.adapt(BundleWiring.class);
    final Collection<String> cfgResources = bundleWiring.listResources("/", "hibernate.cfg.xml", BundleWiring.LISTRESOURCES_RECURSE);
    if (cfgResources.size() == 0) {
        ssrBuilder.configure();
    } else {
        if (cfgResources.size() > 1) {
            LOG.warn("Multiple hibernate.cfg.xml files found in the persistence bundle.  Using the first one discovered.");
        }
        String cfgResource = "/" + cfgResources.iterator().next();
        ssrBuilder.configure(cfgResource);
    }
    ssrBuilder.applySetting(AvailableSettings.JTA_PLATFORM, osgiJtaPlatform);
    final StandardServiceRegistry ssr = ssrBuilder.build();
    final MetadataBuilder metadataBuilder = new MetadataSources(ssr).getMetadataBuilder();
    final TypeContributor[] typeContributors = osgiServiceUtil.getServiceImpls(TypeContributor.class);
    for (TypeContributor typeContributor : typeContributors) {
        metadataBuilder.applyTypes(typeContributor);
    }
    return metadataBuilder.build().buildSessionFactory();
}
Also used : BootstrapServiceRegistryBuilder(org.hibernate.boot.registry.BootstrapServiceRegistryBuilder) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) MetadataBuilder(org.hibernate.boot.MetadataBuilder) BundleWiring(org.osgi.framework.wiring.BundleWiring) MetadataSources(org.hibernate.boot.MetadataSources) BootstrapServiceRegistry(org.hibernate.boot.registry.BootstrapServiceRegistry) TypeContributor(org.hibernate.boot.model.TypeContributor) StrategyRegistrationProvider(org.hibernate.boot.registry.selector.StrategyRegistrationProvider) Integrator(org.hibernate.integrator.spi.Integrator) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry)

Example 2 with BundleWiring

use of org.osgi.framework.wiring.BundleWiring in project aries by apache.

the class HttpExtension method getAttributes.

private Map<String, Object> getAttributes() {
    BundleWiring bundleWiring = _bundle.adapt(BundleWiring.class);
    List<BundleWire> wires = bundleWiring.getRequiredWires(EXTENDER_NAMESPACE);
    Map<String, Object> cdiAttributes = Collections.emptyMap();
    for (BundleWire wire : wires) {
        BundleCapability capability = wire.getCapability();
        Map<String, Object> attributes = capability.getAttributes();
        String extender = (String) attributes.get(EXTENDER_NAMESPACE);
        if (extender.equals(CDI_CAPABILITY_NAME)) {
            BundleRequirement requirement = wire.getRequirement();
            cdiAttributes = requirement.getAttributes();
            break;
        }
    }
    return cdiAttributes;
}
Also used : BundleWiring(org.osgi.framework.wiring.BundleWiring) BundleCapability(org.osgi.framework.wiring.BundleCapability) BundleWire(org.osgi.framework.wiring.BundleWire) BundleRequirement(org.osgi.framework.wiring.BundleRequirement)

Example 3 with BundleWiring

use of org.osgi.framework.wiring.BundleWiring in project aries by apache.

the class Activator method requiresCdiExtender.

private boolean requiresCdiExtender(Bundle bundle) {
    BundleWiring bundleWiring = bundle.adapt(BundleWiring.class);
    List<BundleWire> requiredBundleWires = bundleWiring.getRequiredWires(EXTENDER_NAMESPACE);
    for (BundleWire bundleWire : requiredBundleWires) {
        Map<String, Object> attributes = bundleWire.getCapability().getAttributes();
        if (attributes.containsKey(EXTENDER_NAMESPACE) && attributes.get(EXTENDER_NAMESPACE).equals(CDI_CAPABILITY_NAME)) {
            Bundle providerWiringBundle = bundleWire.getProviderWiring().getBundle();
            if (providerWiringBundle.equals(_bundleContext.getBundle())) {
                return true;
            }
        }
    }
    return false;
}
Also used : Bundle(org.osgi.framework.Bundle) BundleWiring(org.osgi.framework.wiring.BundleWiring) BundleWire(org.osgi.framework.wiring.BundleWire)

Example 4 with BundleWiring

use of org.osgi.framework.wiring.BundleWiring in project aries by apache.

the class CdiContainerTests method testGetBeanManagerFromCDI.

public void testGetBeanManagerFromCDI() throws Exception {
    Thread currentThread = Thread.currentThread();
    ClassLoader contextClassLoader = currentThread.getContextClassLoader();
    try {
        BundleWiring bundleWiring = cdiBundle.adapt(BundleWiring.class);
        currentThread.setContextClassLoader(bundleWiring.getClassLoader());
        BeanManager beanManager = CDI.current().getBeanManager();
        assertNotNull(beanManager);
        assertPojoExists(beanManager);
    } finally {
        currentThread.setContextClassLoader(contextClassLoader);
    }
}
Also used : BundleWiring(org.osgi.framework.wiring.BundleWiring) BeanManager(javax.enterprise.inject.spi.BeanManager)

Example 5 with BundleWiring

use of org.osgi.framework.wiring.BundleWiring in project aries by apache.

the class AbstractTestCase method getCdiExtenderBundle.

Bundle getCdiExtenderBundle() {
    BundleWiring bundleWiring = cdiBundle.adapt(BundleWiring.class);
    List<BundleWire> requiredWires = bundleWiring.getRequiredWires(ExtenderNamespace.EXTENDER_NAMESPACE);
    for (BundleWire wire : requiredWires) {
        Map<String, Object> attributes = wire.getCapability().getAttributes();
        String extender = (String) attributes.get(ExtenderNamespace.EXTENDER_NAMESPACE);
        if (CdiConstants.CDI_CAPABILITY_NAME.equals(extender)) {
            return wire.getProvider().getBundle();
        }
    }
    return null;
}
Also used : BundleWiring(org.osgi.framework.wiring.BundleWiring) BundleWire(org.osgi.framework.wiring.BundleWire)

Aggregations

BundleWiring (org.osgi.framework.wiring.BundleWiring)110 Bundle (org.osgi.framework.Bundle)61 BundleWire (org.osgi.framework.wiring.BundleWire)39 ArrayList (java.util.ArrayList)23 BundleRevision (org.osgi.framework.wiring.BundleRevision)23 BundleCapability (org.osgi.framework.wiring.BundleCapability)19 Test (org.junit.Test)15 HashMap (java.util.HashMap)13 Hashtable (java.util.Hashtable)12 List (java.util.List)12 BundleContext (org.osgi.framework.BundleContext)12 URL (java.net.URL)10 Dictionary (java.util.Dictionary)10 HashSet (java.util.HashSet)9 LinkedHashMap (java.util.LinkedHashMap)8 Version (org.osgi.framework.Version)7 BundleRevisions (org.osgi.framework.wiring.BundleRevisions)7 AbstractIntegrationTest (org.apache.aries.jmx.AbstractIntegrationTest)6 IAnswer (org.easymock.IAnswer)6 ServiceReference (org.osgi.framework.ServiceReference)6