use of org.osgi.framework.Bundle in project opennms by OpenNMS.
the class Activator method createAndRegisterVaadinResourceServlet.
private void createAndRegisterVaadinResourceServlet() {
Bundle vaadin = null;
for (Bundle bundle : bundleContext.getBundles()) {
if ("com.vaadin.client-compiled".equals(bundle.getSymbolicName())) {
vaadin = bundle;
break;
}
}
Dictionary<String, String> props;
props = new Hashtable<String, String>();
props.put("alias", VaadinResourceServlet.VAADIN);
HttpServlet vaadinResourceServlet = new VaadinResourceServlet(vaadin);
resourceService = bundleContext.registerService(Servlet.class.getName(), vaadinResourceServlet, props);
bundleContext.registerService(VaadinResourceService.class.getName(), vaadinResourceServlet, null);
}
use of org.osgi.framework.Bundle in project azure-tools-for-java by Microsoft.
the class SDKJarsFilter method getClasspathEntriesOfAzureLibabries.
public IClasspathEntry[] getClasspathEntriesOfAzureLibabries(IPath containerPath) {
String sdkID = "com.microsoft.azuretools.sdk";
Bundle bundle = Platform.getBundle(sdkID);
// Search the available SDKs
Bundle[] bundles = Platform.getBundles(sdkID, null);
List<IClasspathEntry> listEntries = new ArrayList<IClasspathEntry>();
if (bundles != null) {
for (Bundle bundle2 : bundles) {
if (bundle2.getVersion().toString().startsWith(containerPath.segment(1))) {
bundle = bundle2;
break;
}
}
// Get the SDK jar.
URL sdkJar = FileLocator.find(bundle, new Path("azure-1.0.0.jar"), null);
URL resSdkJar = null;
IClasspathAttribute[] attr = null;
try {
if (sdkJar != null) {
resSdkJar = FileLocator.resolve(sdkJar);
// create classpath attribute for java doc, if present
}
if (resSdkJar == null) {
/*
* if sdk jar is not present then create an place holder for
* sdk jar so that it would be shown as missing file
*/
URL bundleLoc = new URL(bundle.getLocation());
StringBuffer strBfr = new StringBuffer(bundleLoc.getPath());
strBfr.append(File.separator).append("azure-1.0.0.jar");
URL jarLoc = new URL(strBfr.toString());
IPath jarPath = new Path(FileLocator.resolve(jarLoc).getPath());
File jarFile = jarPath.toFile();
listEntries.add(JavaCore.newLibraryEntry(new Path(jarFile.getAbsolutePath()), null, null, null, attr, true));
} else {
File directory = new File(resSdkJar.getPath());
// create the library entry for sdk jar
listEntries.add(JavaCore.newLibraryEntry(new Path(directory.getAbsolutePath()), null, null, null, attr, true));
FilenameFilter sdkJarsFilter = new SDKJarsFilter();
File[] jars = new File(String.format("%s%s%s", directory.getParent(), File.separator, Messages.depLocation)).listFiles(sdkJarsFilter);
for (int i = 0; i < jars.length; i++) {
listEntries.add(JavaCore.newLibraryEntry(new Path(jars[i].getAbsolutePath()), null, null, null, attr, true));
}
}
} catch (Exception e) {
listEntries = new ArrayList<IClasspathEntry>();
Activator.getDefault().log(Messages.excp, e);
}
}
IClasspathEntry[] entries = new IClasspathEntry[listEntries.size()];
// Return the classpath entries.
return listEntries.toArray(entries);
}
use of org.osgi.framework.Bundle 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.Bundle in project aries by apache.
the class ConfigurationTests method testConfiguration.
@SuppressWarnings({ "rawtypes", "unchecked" })
public void testConfiguration() throws Exception {
Bundle tb3Bundle = installBundle("tb3.jar");
Configuration configurationA = null, configurationB = null;
try {
Filter filter = bundleContext.createFilter("(&(objectClass=" + CdiContainer.class.getName() + ")(service.bundleid=" + tb3Bundle.getBundleId() + "))");
ServiceTracker<CdiContainer, CdiContainer> containerTracker = new ServiceTracker<>(bundleContext, filter, null);
containerTracker.open();
containerTracker.waitForService(timeout);
ServiceReference<CdiContainer> serviceReference = containerTracker.getServiceReference();
assertNotNull(serviceReference);
assertEquals(CdiEvent.Type.WAITING_FOR_CONFIGURATIONS, serviceReference.getProperty(CdiConstants.CDI_CONTAINER_STATE));
configurationA = configurationAdmin.getConfiguration("configA", "?");
Dictionary<String, Object> properties = new Hashtable<>();
properties.put("ports", new int[] { 12, 4567 });
configurationA.update(properties);
configurationB = configurationAdmin.getConfiguration("configB", "?");
properties = new Hashtable<>();
properties.put("color", "green");
properties.put("ports", new int[] { 80 });
configurationB.update(properties);
containerTracker.close();
filter = bundleContext.createFilter("(&(objectClass=" + CdiContainer.class.getName() + ")(service.bundleid=" + tb3Bundle.getBundleId() + ")(" + CdiConstants.CDI_CONTAINER_STATE + "=CREATED))");
containerTracker = new ServiceTracker<>(bundleContext, filter, null);
containerTracker.open();
containerTracker.waitForService(timeout);
ServiceTracker<BeanService, BeanService> stA = new ServiceTracker<BeanService, BeanService>(bundleContext, bundleContext.createFilter("(&(objectClass=org.apache.aries.cdi.test.interfaces.BeanService)(bean=A))"), null);
stA.open(true);
BeanService<Callable<int[]>> beanService = stA.waitForService(timeout);
assertNotNull(beanService);
assertEquals("blue", beanService.doSomething());
assertArrayEquals(new int[] { 12, 4567 }, beanService.get().call());
ServiceTracker<BeanService, BeanService> stB = new ServiceTracker<BeanService, BeanService>(bundleContext, bundleContext.createFilter("(&(objectClass=org.apache.aries.cdi.test.interfaces.BeanService)(bean=B))"), null);
stB.open(true);
beanService = stB.waitForService(timeout);
assertNotNull(beanService);
assertEquals("green", beanService.doSomething());
assertArrayEquals(new int[] { 80 }, beanService.get().call());
} finally {
if (configurationA != null) {
try {
configurationA.delete();
} catch (Exception e) {
// ignore
}
}
if (configurationB != null) {
try {
configurationB.delete();
} catch (Exception e) {
// ignore
}
}
tb3Bundle.uninstall();
}
}
use of org.osgi.framework.Bundle in project aries by apache.
the class XAJPAEMFLocator method setupTransactionManager.
private void setupTransactionManager(BundleContext context, Map<String, Object> props, Map<String, Object> providerProps, ThreadLocal<TransactionControl> t, ServiceReference<EntityManagerFactoryBuilder> reference) {
String provider = (String) reference.getProperty(JPA_UNIT_PROVIDER);
ServiceReference<PersistenceProvider> providerRef = getPersistenceProvider(provider, context);
if (providerRef == null) {
// TODO log a warning and give up
return;
}
Bundle providerBundle = providerRef.getBundle();
Bundle txControlProviderBundle = context.getBundle();
try {
if ("org.hibernate.jpa.HibernatePersistenceProvider".equals(provider)) {
try {
providerBundle.loadClass("org.hibernate.resource.transaction.TransactionCoordinatorBuilder");
} catch (Exception e) {
BundleWiring wiring = providerBundle.adapt(BundleWiring.class);
providerBundle = wiring.getRequiredWires("osgi.wiring.package").stream().filter(bw -> "org.hibernate".equals(bw.getCapability().getAttributes().get("osgi.wiring.package"))).map(BundleWire::getProviderWiring).map(BundleWiring::getBundle).findFirst().get();
}
ClassLoader pluginLoader = getPluginLoader(providerBundle, txControlProviderBundle);
Class<?> pluginClazz = pluginLoader.loadClass("org.apache.aries.tx.control.jpa.xa.hibernate.impl.HibernateTxControlPlatform");
Object plugin = pluginClazz.getConstructor(ThreadLocal.class).newInstance(t);
props.put("hibernate.transaction.coordinator_class", plugin);
} else if ("org.apache.openjpa.persistence.PersistenceProviderImpl".equals(provider)) {
ClassLoader pluginLoader = getPluginLoader(providerBundle, txControlProviderBundle);
Class<?> pluginClazz = pluginLoader.loadClass("org.apache.aries.tx.control.jpa.xa.openjpa.impl.OpenJPATxControlPlatform");
Object plugin = pluginClazz.getConstructor(ThreadLocal.class).newInstance(t);
props.put("openjpa.ManagedRuntime", plugin);
} else if ("org.eclipse.persistence.jpa.PersistenceProvider".equals(provider)) {
ClassLoader pluginLoader = getPluginLoader(providerBundle, txControlProviderBundle);
Class<?> pluginClazz = pluginLoader.loadClass("org.apache.aries.tx.control.jpa.xa.eclipse.impl.EclipseTxControlPlatform");
pluginClazz.getMethod("setTransactionControl", ThreadLocal.class).invoke(null, t);
props.put("eclipselink.target-server", pluginClazz.getName());
props.put("org.apache.aries.jpa.eclipselink.plugin.types", pluginClazz);
// transactions without blowing up.
if (!props.containsKey("eclipselink.jdbc.sequence-connection-pool")) {
props.put("eclipselink.jdbc.sequence-connection-pool", "true");
}
} else {
// TODO log a warning and give up
return;
}
} catch (Exception e) {
//TODO log a warning and give up
e.printStackTrace();
}
}
Aggregations