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();
}
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;
}
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;
}
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);
}
}
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;
}
Aggregations