Java Code Examples for org.osgi.framework.wiring.BundleWiring#getClassLoader()
The following examples show how to use
org.osgi.framework.wiring.BundleWiring#getClassLoader() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NetbinoxHooks.java From netbeans with Apache License 2.0 | 6 votes |
@Override public byte[] processClass(String className, byte[] bytes, ClasspathEntry ce, BundleEntry be, ClasspathManager cm) { final BaseData bd = ce.getBaseData(); if (bd == null) { return bytes; } final Bundle b = bd.getBundle(); if (b == null) { return bytes; } BundleWiring w = b.adapt(org.osgi.framework.wiring.BundleWiring.class); if (w == null) { return bytes; } ClassLoader loader = w.getClassLoader(); return archive.patchByteCode(loader, className, ce.getDomain(), bytes); }
Example 2
Source File: SiddhiExtensionLoader.java From siddhi with Apache License 2.0 | 6 votes |
private void removeExtensions(Bundle bundle) { bundleExtensions.entrySet().stream().filter(entry -> entry.getValue() == bundle.getBundleId()).forEachOrdered(entry -> { siddhiExtensionsMap.remove(entry.getKey()); }); bundleExtensions.entrySet().removeIf(entry -> entry.getValue() == bundle.getBundleId()); BundleWiring bundleWiring = bundle.adapt(BundleWiring.class); if (bundleWiring != null) { ClassLoader classLoader = bundleWiring.getClassLoader(); Iterable<Class<?>> extensions = ClassIndex.getAnnotated(Extension.class, classLoader); for (Class extension : extensions) { Extension siddhiExtensionAnnotation = (Extension) extension.getAnnotation(Extension.class); if (!siddhiExtensionAnnotation.namespace().isEmpty()) { String key = siddhiExtensionAnnotation.namespace() + SiddhiConstants.EXTENSION_SEPARATOR + siddhiExtensionAnnotation.name(); removeFromExtensionHolderMap(key, extension, extensionHolderConcurrentHashMap); } } } }
Example 3
Source File: AuthenticationHandlerSAML2.java From sling-whiteboard with Apache License 2.0 | 5 votes |
private void doClassloading(){ // Classloading BundleWiring bundleWiring = FrameworkUtil.getBundle(AuthenticationHandlerSAML2.class).adapt(BundleWiring.class); ClassLoader loader = bundleWiring.getClassLoader(); Thread thread = Thread.currentThread(); thread.setContextClassLoader(loader); }
Example 4
Source File: ClassPatcherWrappers.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Get bundle class loader at Class.getSystemClassLoader() calls. */ public static ClassLoader getSystemClassLoaderWrapper(long bid, Object context) { Bundle b = getBundle(bid); if (b == null) { throw new IllegalStateException("Undefined bid=" + bid); } BundleWiring bw = b.adapt(BundleWiring.class); if (bw == null) { throw new RuntimeException("Unable to adapt Bundle to a BundleWiring" + bid); } return bw.getClassLoader(); }
Example 5
Source File: Activator.java From sling-whiteboard with Apache License 2.0 | 4 votes |
public void start(BundleContext context) throws Exception { //Classloading BundleWiring bundleWiring = context.getBundle().adapt(BundleWiring.class); ClassLoader loader = bundleWiring.getClassLoader(); Thread thread = Thread.currentThread(); thread.setContextClassLoader(InitializationService.class.getClassLoader()); try { InitializationService.initialize(); } finally { thread.setContextClassLoader(loader); } logger.info("Activating Apache Sling SAML2 SP Bundle. And Initializing JCE, Java Cryptographic Extension"); JavaCryptoValidationInitializer jcvi = new JavaCryptoValidationInitializer(); try { jcvi.init(); for (Provider jceProvider : Security.getProviders()) { logger.info(jceProvider.getInfo()); } } catch (InitializationException e) { throw new Error("Java Cryptographic Extension could not initialize. " + "This happens when JCE implementation is incomplete, and not meeting OpenSAML standards.", e); } /* TODO: What is the proper way around this classloading problem? One suggestion in this post https://medium.com/@dehami.deshan/commencing-migration-towards-the-checked-flag-opensaml-3-cc62d3faa3b0 ...fixes a issue similar to what is discussed below https://shibboleth.1660669.n2.nabble.com/Null-returned-by-XMLObjectProviderRegistrySupport-getBuilderFactory-td7643173.html ...and here https://stackoverflow.com/questions/37948303/opensaml3-resource-not-found-default-config-xml-in-osgi-container ...and here https://stackoverflow.com/questions/2198928/better-handling-of-thread-context-classloader-in-osgi?noredirect=1&lq=1 */ }
Example 6
Source File: Whiteboard.java From aries-jax-rs-whiteboard with Apache License 2.0 | 4 votes |
private ExtensionManagerBus createBus( Map<String, ServiceTuple<Object>> extensions) { BundleWiring wiring = _bundleContext.getBundle().adapt( BundleWiring.class); Map<String, Object> properties = new HashMap<>(_configurationMap); properties.putIfAbsent( "replace.loopback.address.with.localhost", "false"); HashMap<Class<?>, Object> cxfExtensions = new HashMap<>(); if (extensions.isEmpty()) { cxfExtensions = null; } else { for (Map.Entry<String, ServiceTuple<Object>> entry : extensions.entrySet()) { String className = entry.getKey(); ServiceTuple<Object> serviceTuple = entry.getValue(); ClassLoader classLoader = getClassLoader(serviceTuple); try { Class<?> clazz = classLoader.loadClass(className); cxfExtensions.put(clazz, serviceTuple.getService()); } catch (Exception e) { if (_log.isErrorEnabled()) { _log.error("Could not load extension for CXF bus", e); } } } } if (_log.isDebugEnabled()) { _log.debug( "Creating CXF Bus with extensions {} and properties {}", extensions, properties); } ExtensionManagerBus bus = new ExtensionManagerBus( cxfExtensions, properties, wiring.getClassLoader()); bus.initialize(); if (_log.isDebugEnabled()) { _log.debug( "Created CXF Bus with extensions {} and properties {}", extensions, properties); } return bus; }