public void register(Object factory) { // set parent for each factory so they can do proper delegation try { Class<?> clazz = factory.getClass(); Method setParentFactory = clazz.getMethod("setParentFactory", new Class[] {Object.class}); //$NON-NLS-1$ setParentFactory.invoke(factory, new Object[] {getParentFactory()}); } catch (Exception e) { container.getLogServices().log(MultiplexingFactory.class.getName(), FrameworkLogEntry.ERROR, "register", e); //$NON-NLS-1$ throw new RuntimeException(e.getMessage(), e); } addFactory(factory); }
public boolean isMultiplexing() { return getFactories() != null; }
private static Object getURLStreamHandlerFactoryLock() throws IllegalAccessException { Object lock; try { Field streamHandlerLockField = URL.class.getDeclaredField("streamHandlerLock"); //$NON-NLS-1$ MultiplexingFactory.setAccessible(streamHandlerLockField); lock = streamHandlerLockField.get(null); } catch (NoSuchFieldException noField) { // could not find the lock, lets sync on the class object lock = URL.class; } return lock; }
public Object designateSuccessor() { List<Object> released = releaseFactories(); // Note that we do this outside of the sync block above. // This is only possible because we do additional locking outside of // this class to ensure no other threads are trying to manipulate the // list of registered factories. See Framework class the following methods: // Framework.installURLStreamHandlerFactory(BundleContext, FrameworkAdaptor) // Framework.installContentHandlerFactory(BundleContext, FrameworkAdaptor) // Framework.uninstallURLStreamHandlerFactory // Framework.uninstallContentHandlerFactory() if (released == null || released.isEmpty()) return getParentFactory(); Object successor = released.remove(0); try { Class<?> clazz = successor.getClass(); Method register = clazz.getMethod("register", new Class[] {Object.class}); //$NON-NLS-1$ for (Object r : released) { register.invoke(successor, new Object[] {r}); } } catch (Exception e) { container.getLogServices().log(MultiplexingFactory.class.getName(), FrameworkLogEntry.ERROR, "designateSuccessor", e); //$NON-NLS-1$ throw new RuntimeException(e.getMessage(), e); } closePackageAdminTracker(); // close tracker return successor; }
public Object findAuthorizedFactory(List<Class<?>> ignoredClasses) { List<Object> current = getFactories(); Class<?>[] classStack = internalSecurityManager.getClassContext(); for (int i = 0; i < classStack.length; i++) { Class<?> clazz = classStack[i]; if (clazz == InternalSecurityManager.class || clazz == MultiplexingFactory.class || ignoredClasses.contains(clazz)) continue; if (hasAuthority(clazz)) return this; if (current == null) continue; for (Object factory : current) { try { Method hasAuthorityMethod = factory.getClass().getMethod("hasAuthority", new Class[] {Class.class}); //$NON-NLS-1$ if (((Boolean) hasAuthorityMethod.invoke(factory, new Object[] {clazz})).booleanValue()) { return factory; } } catch (Exception e) { container.getLogServices().log(MultiplexingFactory.class.getName(), FrameworkLogEntry.ERROR, "findAuthorizedURLStreamHandler-loop", e); //$NON-NLS-1$ throw new RuntimeException(e.getMessage(), e); } } } // Instead of returning null here, this factory is returned; // This means the root factory may provide protocol handlers for call stacks // that have no classes loaded by an bundle class loader. return this; }
public void unregister(Object factory) { removeFactory(factory); // close the service tracker try { // this is brittle; if class does not directly extend MultplexingFactory then this method will not exist, but we do not want a public method here Method closeTracker = factory.getClass().getSuperclass().getDeclaredMethod("closePackageAdminTracker", (Class[]) null); //$NON-NLS-1$ closeTracker.setAccessible(true); // its a private method closeTracker.invoke(factory, (Object[]) null); } catch (Exception e) { container.getLogServices().log(MultiplexingFactory.class.getName(), FrameworkLogEntry.ERROR, "unregister", e); //$NON-NLS-1$ throw new RuntimeException(e.getMessage(), e); } }
public Object designateSuccessor() { List<Object> released = releaseFactories(); // Note that we do this outside of the sync block above. // This is only possible because we do additional locking outside of // this class to ensure no other threads are trying to manipulate the // list of registered factories. See Framework class the following methods: // Framework.installURLStreamHandlerFactory(BundleContext, FrameworkAdaptor) // Framework.installContentHandlerFactory(BundleContext, FrameworkAdaptor) // Framework.uninstallURLStreamHandlerFactory // Framework.uninstallContentHandlerFactory() if (released == null || released.isEmpty()) return getParentFactory(); Object successor = released.remove(0); try { Class<?> clazz = successor.getClass(); Method register = clazz.getMethod("register", new Class[] {Object.class}); //$NON-NLS-1$ for (Object r : released) { register.invoke(successor, new Object[] {r}); } } catch (Exception e) { container.getLogServices().log(MultiplexingFactory.class.getName(), FrameworkLogEntry.ERROR, "designateSuccessor", e); //$NON-NLS-1$ throw new RuntimeException(e.getMessage(), e); } closePackageAdminTracker(); // close tracker return successor; }
public Object findAuthorizedFactory(List<Class<?>> ignoredClasses) { List<Object> current = getFactories(); Class<?>[] classStack = internalSecurityManager.getClassContext(); for (int i = 0; i < classStack.length; i++) { Class<?> clazz = classStack[i]; if (clazz == InternalSecurityManager.class || clazz == MultiplexingFactory.class || ignoredClasses.contains(clazz)) continue; if (hasAuthority(clazz)) return this; if (current == null) continue; for (Object factory : current) { try { Method hasAuthorityMethod = factory.getClass().getMethod("hasAuthority", new Class[] {Class.class}); //$NON-NLS-1$ if (((Boolean) hasAuthorityMethod.invoke(factory, new Object[] {clazz})).booleanValue()) { return factory; } } catch (Exception e) { container.getLogServices().log(MultiplexingFactory.class.getName(), FrameworkLogEntry.ERROR, "findAuthorizedURLStreamHandler-loop", e); //$NON-NLS-1$ throw new RuntimeException(e.getMessage(), e); } } } // Instead of returning null here, this factory is returned; // This means the root factory may provide protocol handlers for call stacks // that have no classes loaded by an bundle class loader. return this; }
public void unregister(Object factory) { removeFactory(factory); // close the service tracker try { // this is brittle; if class does not directly extend MultplexingFactory then this method will not exist, but we do not want a public method here Method closeTracker = factory.getClass().getSuperclass().getDeclaredMethod("closePackageAdminTracker", (Class[]) null); //$NON-NLS-1$ closeTracker.setAccessible(true); // its a private method closeTracker.invoke(factory, (Object[]) null); } catch (Exception e) { container.getLogServices().log(MultiplexingFactory.class.getName(), FrameworkLogEntry.ERROR, "unregister", e); //$NON-NLS-1$ throw new RuntimeException(e.getMessage(), e); } }
public Object designateSuccessor() { List<Object> released = releaseFactories(); // Note that we do this outside of the sync block above. // This is only possible because we do additional locking outside of // this class to ensure no other threads are trying to manipulate the // list of registered factories. See Framework class the following methods: // Framework.installURLStreamHandlerFactory(BundleContext, FrameworkAdaptor) // Framework.installContentHandlerFactory(BundleContext, FrameworkAdaptor) // Framework.uninstallURLStreamHandlerFactory // Framework.uninstallContentHandlerFactory() if (released == null || released.isEmpty()) return getParentFactory(); Object successor = released.remove(0); try { Class<?> clazz = successor.getClass(); Method register = clazz.getMethod("register", new Class[] {Object.class}); //$NON-NLS-1$ for (Object r : released) { register.invoke(successor, new Object[] {r}); } } catch (Exception e) { container.getLogServices().log(MultiplexingFactory.class.getName(), FrameworkLogEntry.ERROR, "designateSuccessor", e); //$NON-NLS-1$ throw new RuntimeException(e.getMessage(), e); } closePackageAdminTracker(); // close tracker return successor; }
public void register(Object factory) { // set parent for each factory so they can do proper delegation try { Class<?> clazz = factory.getClass(); Method setParentFactory = clazz.getMethod("setParentFactory", new Class[] {Object.class}); //$NON-NLS-1$ setParentFactory.invoke(factory, new Object[] {getParentFactory()}); } catch (Exception e) { container.getLogServices().log(MultiplexingFactory.class.getName(), FrameworkLogEntry.ERROR, "register", e); //$NON-NLS-1$ throw new RuntimeException(e.getMessage(), e); } addFactory(factory); }
public Object findAuthorizedFactory(List<Class<?>> ignoredClasses) { List<Object> current = getFactories(); Class<?>[] classStack = internalSecurityManager.getClassContext(); for (int i = 0; i < classStack.length; i++) { Class<?> clazz = classStack[i]; if (clazz == InternalSecurityManager.class || clazz == MultiplexingFactory.class || ignoredClasses.contains(clazz)) continue; if (hasAuthority(clazz)) return this; if (current == null) continue; for (Object factory : current) { try { Method hasAuthorityMethod = factory.getClass().getMethod("hasAuthority", new Class[] {Class.class}); //$NON-NLS-1$ if (((Boolean) hasAuthorityMethod.invoke(factory, new Object[] {clazz})).booleanValue()) { return factory; } } catch (Exception e) { container.getLogServices().log(MultiplexingFactory.class.getName(), FrameworkLogEntry.ERROR, "findAuthorizedURLStreamHandler-loop", e); //$NON-NLS-1$ throw new RuntimeException(e.getMessage(), e); } } } // Instead of returning null here, this factory is returned; // This means the root factory may provide protocol handlers for call stacks // that have no classes loaded by an bundle class loader. return this; }
public boolean isMultiplexing() { return getFactories() != null; }
public void unregister(Object factory) { removeFactory(factory); // close the service tracker try { // this is brittle; if class does not directly extend MultplexingFactory then this method will not exist, but we do not want a public method here Method closeTracker = factory.getClass().getSuperclass().getDeclaredMethod("closePackageAdminTracker", (Class[]) null); //$NON-NLS-1$ closeTracker.setAccessible(true); // its a private method closeTracker.invoke(factory, (Object[]) null); } catch (Exception e) { container.getLogServices().log(MultiplexingFactory.class.getName(), FrameworkLogEntry.ERROR, "unregister", e); //$NON-NLS-1$ throw new RuntimeException(e.getMessage(), e); } }
private static Object getURLStreamHandlerFactoryLock() throws IllegalAccessException { Object lock; try { Field streamHandlerLockField = URL.class.getDeclaredField("streamHandlerLock"); //$NON-NLS-1$ MultiplexingFactory.setAccessible(streamHandlerLockField); lock = streamHandlerLockField.get(null); } catch (NoSuchFieldException noField) { // could not find the lock, lets sync on the class object lock = URL.class; } return lock; }
public Object designateSuccessor() { List<Object> released = releaseFactories(); // Note that we do this outside of the sync block above. // This is only possible because we do additional locking outside of // this class to ensure no other threads are trying to manipulate the // list of registered factories. See Framework class the following methods: // Framework.installURLStreamHandlerFactory(BundleContext, FrameworkAdaptor) // Framework.installContentHandlerFactory(BundleContext, FrameworkAdaptor) // Framework.uninstallURLStreamHandlerFactory // Framework.uninstallContentHandlerFactory() if (released == null || released.isEmpty()) return getParentFactory(); Object successor = released.remove(0); try { Class<?> clazz = successor.getClass(); Method register = clazz.getMethod("register", new Class[] {Object.class}); //$NON-NLS-1$ for (Object r : released) { register.invoke(successor, new Object[] {r}); } } catch (Exception e) { container.getLogServices().log(MultiplexingFactory.class.getName(), FrameworkLogEntry.ERROR, "designateSuccessor", e); //$NON-NLS-1$ throw new RuntimeException(e.getMessage(), e); } closePackageAdminTracker(); // close tracker return successor; }
public void register(Object factory) { // set parent for each factory so they can do proper delegation try { Class<?> clazz = factory.getClass(); Method setParentFactory = clazz.getMethod("setParentFactory", new Class[] {Object.class}); //$NON-NLS-1$ setParentFactory.invoke(factory, new Object[] {getParentFactory()}); } catch (Exception e) { container.getLogServices().log(MultiplexingFactory.class.getName(), FrameworkLogEntry.ERROR, "register", e); //$NON-NLS-1$ throw new RuntimeException(e.getMessage(), e); } addFactory(factory); }
public Object findAuthorizedFactory(List<Class<?>> ignoredClasses) { List<Object> current = getFactories(); Class<?>[] classStack = internalSecurityManager.getClassContext(); for (int i = 0; i < classStack.length; i++) { Class<?> clazz = classStack[i]; if (clazz == InternalSecurityManager.class || clazz == MultiplexingFactory.class || ignoredClasses.contains(clazz)) continue; if (hasAuthority(clazz)) return this; if (current == null) continue; for (Object factory : current) { try { Method hasAuthorityMethod = factory.getClass().getMethod("hasAuthority", new Class[] {Class.class}); //$NON-NLS-1$ if (((Boolean) hasAuthorityMethod.invoke(factory, new Object[] {clazz})).booleanValue()) { return factory; } } catch (Exception e) { container.getLogServices().log(MultiplexingFactory.class.getName(), FrameworkLogEntry.ERROR, "findAuthorizedURLStreamHandler-loop", e); //$NON-NLS-1$ throw new RuntimeException(e.getMessage(), e); } } } // Instead of returning null here, this factory is returned; // This means the root factory may provide protocol handlers for call stacks // that have no classes loaded by an bundle class loader. return this; }
public boolean isMultiplexing() { return getFactories() != null; }
public void unregister(Object factory) { removeFactory(factory); // close the service tracker try { // this is brittle; if class does not directly extend MultplexingFactory then this method will not exist, but we do not want a public method here Method closeTracker = factory.getClass().getSuperclass().getDeclaredMethod("closePackageAdminTracker", (Class[]) null); //$NON-NLS-1$ closeTracker.setAccessible(true); // its a private method closeTracker.invoke(factory, (Object[]) null); } catch (Exception e) { container.getLogServices().log(MultiplexingFactory.class.getName(), FrameworkLogEntry.ERROR, "unregister", e); //$NON-NLS-1$ throw new RuntimeException(e.getMessage(), e); } }