@Override public void start(BundleContext bundleContext) throws Exception { InputStream in = bundleContext.getBundle().getResource(ResourceConfigReader.CONFIG_FILE).openStream(); ClassLoader tccl = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(new BundleClassLoader(bundleContext.getBundle())); ResourceConfig config; try { config = new ResourceConfigReader(new BundleClassLoader(bundleContext.getBundle())).parse(in); } finally { Thread.currentThread().setContextClassLoader(tccl); } ConfigService configService = new ConfigServiceImpl(config); serviceRegistration = bundleContext.registerService(ConfigService.class.getName(), configService, new Hashtable()); }
/** * Return the bundle associated with this classloader. * * This method calls {@link #getBundle(boolean) getBundle(true)} and therefore always returns a regular * framework bundle. * <br><br> * Note: Some libraries use {@link BundleReference#getBundle()} to obtain a bundle for the given * classloader and expect the returned bundle instance to be work with any OSGi API. Some of these API might * not work if {@link DelegatingBundle} is returned. That is why this function will always return * a regular framework bundle. See {@link #getBundle(boolean)} for more information. * * @return The bundle associated with this classloader. */ public Bundle getBundle() { return getBundle(true); }
@Override public Enumeration<URL> findResources (String name) throws IOException { return this.getResources(name); }
@Override protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException { Class clazz = bundle.loadClass(name); if (resolve) { resolveClass(clazz); } return clazz; }
this.tempClassLoader = new TemporaryClassLoader(new BundleClassLoader(bundle,true,false)); this.bundle = bundle;
/** * The new delegating bundle classloader will make sure the resources in the wink-server bundle could be found even if * wired bundles are not searched * @return */ protected ClassLoader getContextClassLoader() { ClassLoader contextCL = Thread.currentThread().getContextClassLoader(); List<Bundle> bundles = new ArrayList<Bundle>(2); bundles.add(BundleUtils.getBundle(contextCL, false)); bundles.add(BundleUtils.getBundle(RestServlet.class.getClassLoader(), true)); return new BundleClassLoader(new DelegatingBundle(bundles)); }
/** * Builds the composite class loader for the given bundle, also including the bundle containing * this class and all extension bundles. */ protected ClassLoader buildContextClassLoader(Object environment) { List<Bundle> delegateBundles = new ArrayList<>(); delegateBundles.add(bundle); delegateBundles.addAll(additionalBundles); delegateBundles.addAll(extensionBundles); if (builder != null) { // in pax-web we may already have necessary classloader - possibly without // "additionalBundles" ClassLoader cl = builder.buildContextClassLoader(environment, bundle, extensionBundles, additionalBundles); if (cl != null) { log.info("Using provided contextClassLoader: {}", cl); return cl; } } // fallback to creating xbean classloader DelegatingBundle delegatingBundle = new DelegatingBundle(delegateBundles); BundleClassLoader classLoader = new BundleClassLoader(delegatingBundle); log.info("Using default contextClassLoader: {}", classLoader); return classLoader; }
public Object getObject(AbstractName objectName) { ClassLoader cl = null; try { cl = new BundleClassLoader(kernel.getBundleFor(objectName)); } catch(GBeanNotFoundException e) { cl = KernelManagementHelper.class.getClassLoader(); } return kernel.getProxyManager().createProxy(objectName, cl); }
return null; ClassLoader classLoader = new BundleClassLoader(kernel.getBundleFor(result)); return (J2EEDeployedObject) kernel.getProxyManager().createProxy(result, classLoader); } catch (GBeanNotFoundException e) {
ClassLoader oldCl = thread.getContextClassLoader(); thread.setContextClassLoader(new BundleClassLoader(context.getConfiguration().getBundle())); try { try {
myFacesWebAppContextData.setAttribute("faceletConfigResources", faceletsLibraries); ClassLoader deploymentClassLoader = new BundleClassLoader(bundle); ClassLoader oldContextClassLoader = Thread.currentThread().getContextClassLoader(); try {
if (earData.getAppInfo() == null) { ClassLoader bundleLoader = new BundleClassLoader(bundle);
classLoader = new BundleClassLoader(bundle, BundleResourceHelper.getSearchWiredBundles(false), BundleResourceHelper.getConvertResourceUrls(true));