/** * Return a {@code Bundle} for the specified bundle class. The returned * {@code Bundle} is the bundle associated with the bundle class loader * which defined the specified class. * * @param classFromBundle A class defined by a bundle class loader. * @return A {@code Bundle} for the specified bundle class or {@code null} * if the specified class was not defined by a bundle class loader. * @since 1.5 */ public static Bundle getBundle(final Class<?> classFromBundle) { // We use doPriv since the caller may not have permission // to call getClassLoader. Object cl = AccessController.doPrivileged(new PrivilegedAction<Object>() { public Object run() { return classFromBundle.getClassLoader(); } }); if (cl instanceof BundleReference) { return ((BundleReference) cl).getBundle(); } return null; }
@Override public long getLoadClassOrigin(long bundleID, String clazz) { Bundle b = bundleContext.getBundle(bundleID); if (b == null) throw new IllegalArgumentException("Not a valid bundle ID: " + bundleID); try { Class<?> cls = b.loadClass(clazz); ClassLoader classLoader = cls.getClassLoader(); if (classLoader instanceof BundleReference) return ((BundleReference) classLoader).getBundle().getBundleId(); else return 0; } catch (ClassNotFoundException e) { } return -1; }
@Override @SuppressWarnings("unchecked") public EntityManagerFactory createContainerEntityManagerFactory(PersistenceUnitInfo info, Map properties) { final Map settings = generateSettings( properties ); // OSGi ClassLoaders must implement BundleReference settings.put( org.hibernate.cfg.AvailableSettings.SCANNER, new OsgiScanner( ( (BundleReference) info.getClassLoader() ).getBundle() ) ); osgiClassLoader.addClassLoader( info.getClassLoader() ); return Bootstrap.getEntityManagerFactoryBuilder( info, settings, new OSGiClassLoaderServiceImpl( osgiClassLoader, osgiServiceUtil ) ).build(); }
/** * Returns the bundle associated with this plug-in. * * @return the associated bundle * @since 3.0 */ public final Bundle getBundle() { if (bundle != null) return bundle; ClassLoader cl = getClass().getClassLoader(); if (cl instanceof BundleReference) return ((BundleReference) cl).getBundle(); return null; } }
static BundleContext getBundleContext(ClassLoader loader) { if (!(loader instanceof BundleReference)) { throw new IllegalStateException("Not an OSGi ClassLoader"); } return ((BundleReference) loader).getBundle().getBundleContext(); }
private BundleContext injectBundleContext(Class<?> requestingClass, Field field) { ClassLoader classLoader = requestingClass.getClassLoader(); if (classLoader instanceof BundleReference) { BundleReference bundleReference = (BundleReference) classLoader; Bundle bundle = bundleReference.getBundle(); return bundle.getBundleContext(); } else { throw new IllegalStateException("the classloader does not provide a BundleReference"); } }
/** Obtaining BundleContext which belongs to osgi-javaee-base * @param clazz some class belongs to osgi-javaee-base * @return BundleContext which belongs to osgi-javaee-base */ private BundleContext getBundleContext(Class<?> clazz) { return BundleReference.class.cast(clazz.getClassLoader()) .getBundle().getBundleContext(); } }
Bundle getCallerBudle() { Class[] clss = getClassesOnCallStack(); for (Class<?> cls : clss) { ClassLoader cl = cls.getClassLoader(); if (cl instanceof BundleReference) { BundleReference ref = (BundleReference) cl; Bundle b = ref.getBundle(); return b; } } return null; }
@Override public <T> T register(Class<T> type) throws InvalidTypeException, TypeFilterException, DoubleIDException, InvalidMethodException, InvocationException, ControllerPersistenceException { BundleContext context = BundleReference.class.cast(type.getClassLoader()).getBundle().getBundleContext(); return register(type, context); }
public Bundle getBundle() { Object ref = getUserObject(); if (ref instanceof BundleReference) return ((BundleReference) ref).getBundle(); return null; }
public Bundle getBundle() { Object ref = getUserObject(); if (ref instanceof BundleReference) return ((BundleReference) ref).getBundle(); return null; }
public ServiceLoaderImpl() { ClassLoader cl = getClass().getClassLoader(); if (cl instanceof BundleReference) { bundleContext = getBundleContextSecured(BundleReference.class.cast(cl).getBundle()); } if (bundleContext == null) { throw new RuntimeException("There is no bundle context available yet. " + "Instatiate this class in STARTING or ACTIVE state only"); } }
public Bundle getBundle() { Object ref = getUserObject(); if (ref instanceof BundleReference) return ((BundleReference) ref).getBundle(); return null; }
@Override public <I, T extends I> I register(Class<I> type, T defaults) throws InvalidTypeException, TypeFilterException, DoubleIDException, InvalidMethodException, InvocationException, ControllerPersistenceException { BundleContext context = BundleReference.class.cast(type.getClassLoader()).getBundle().getBundleContext(); return register(type, defaults, context); }
Bundle getBundlePriv(Class<?> clazz) { ClassLoader cl = clazz.getClassLoader(); if (cl instanceof BundleReference) { return ((BundleReference) cl).getBundle(); } if (cl == getClass().getClassLoader()) { return container.getModule(0).getBundle(); } return null; }
Bundle getBundlePriv(Class<?> clazz) { ClassLoader cl = clazz.getClassLoader(); if (cl instanceof BundleReference) { return ((BundleReference) cl).getBundle(); } if (cl == getClass().getClassLoader()) { return container.getModule(0).getBundle(); } return null; }
Bundle getBundlePriv(Class<?> clazz) { ClassLoader cl = clazz.getClassLoader(); if (cl instanceof BundleReference) { return ((BundleReference) cl).getBundle(); } if (cl == getClass().getClassLoader()) { return container.getModule(0).getBundle(); } return null; }
Bundle getBundlePriv(Class<?> clazz) { ClassLoader cl = clazz.getClassLoader(); if (cl instanceof BundleReference) { return ((BundleReference) cl).getBundle(); } if (cl == getClass().getClassLoader()) { return container.getModule(0).getBundle(); } return null; }
Bundle getBundlePriv(Class<?> clazz) { ClassLoader cl = clazz.getClassLoader(); if (cl instanceof BundleReference) { return ((BundleReference) cl).getBundle(); } if (cl == getClass().getClassLoader()) { return container.getModule(0).getBundle(); } return null; }
private BundleClassLoader getBundleClassLoader() { Object o = BundleDescriptionImpl.this.getUserObject(); if (!(o instanceof BundleLoaderProxy)) { if (o instanceof BundleReference) o = ((BundleReference) o).getBundle(); if (o instanceof BundleHost) o = ((BundleHost) o).getLoaderProxy(); } if (o instanceof BundleLoaderProxy) return ((BundleLoaderProxy) o).getBundleLoader().createClassLoader(); return null; }