/** * Loads a {@code CallContextHandler} if it is configured in for this * servlet. */ public static CallContextHandler loadCallContextHandler(ServletConfig config) throws ServletException { String callContextHandlerClass = config.getInitParameter(PARAM_CALL_CONTEXT_HANDLER); if (callContextHandlerClass != null) { try { return (CallContextHandler) ClassLoaderUtil.loadClass(callContextHandlerClass).newInstance(); } catch (Exception e) { throw new ServletException("Could not load call context handler: " + e, e); } } return null; }
/** * Loads a class. If the context class loader is set, it is used. */ public static Class<?> loadClass(String className) throws ClassNotFoundException { ClassLoader ccl = Thread.currentThread().getContextClassLoader(); if (ccl == null) { try { return loadClass(className, null); } catch (ClassNotFoundException cnf) { return loadClassWithRegisteredClassLoaders(className); } } try { return loadClass(className, ccl); } catch (ClassNotFoundException cnf) { try { return loadClass(className, null); } catch (ClassNotFoundException cnf2) { return loadClassWithRegisteredClassLoaders(className); } } }
@Override public void stop(final BundleContext context) { // remove bundle listener context.removeBundleListener(this); // forget our bundle context bundleContext = null; // unregister all classloaders ClassLoaderUtil.unregisterAllBundleClassLoaders(); // The SessionFactory service will be unregistered automatically }
private void unregister(final long bundleId) { ClassLoaderUtil.unregisterBundleClassLoader(bundleId); }
private void register(final Bundle bundle) { BundleWiring bundleWiring = bundle.adapt(BundleWiring.class); if (bundleWiring == null) { return; } ClassLoader classLoader = bundleWiring.getClassLoader(); if (classLoader == null) { return; } List<String> classes = getOpenCmisSpiHeader(bundle); if (classes != null) { ClassLoaderUtil.registerBundleClassLoader(bundle.getBundleId(), classLoader, classes); } }
private ObjectFactory createObjectFactory() { try { String classname = parameters.get(SessionParameter.OBJECT_FACTORY_CLASS); Class<?> objectFactoryClass; if (classname == null) { objectFactoryClass = ObjectFactoryImpl.class; } else { objectFactoryClass = ClassLoaderUtil.loadClass(classname); } Object of = objectFactoryClass.newInstance(); if (!(of instanceof ObjectFactory)) { throw new InstantiationException("Class does not implement ObjectFactory!"); } ((ObjectFactory) of).initialize(this, parameters); return (ObjectFactory) of; } catch (Exception e) { throw new IllegalArgumentException("Unable to create object factory: " + e, e); } }
/** * Loads a class. If the context class loader is set, it is used. */ public static Class<?> loadClass(String className) throws ClassNotFoundException { ClassLoader ccl = Thread.currentThread().getContextClassLoader(); if (ccl == null) { try { return loadClass(className, null); } catch (ClassNotFoundException cnf) { return loadClassWithRegisteredClassLoaders(className); } } try { return loadClass(className, ccl); } catch (ClassNotFoundException cnf) { try { return loadClass(className, null); } catch (ClassNotFoundException cnf2) { return loadClassWithRegisteredClassLoaders(className); } } }
private Cache createCache() { try { String classname = parameters.get(SessionParameter.CACHE_CLASS); Class<?> cacheClass; if (classname == null) { cacheClass = CacheImpl.class; } else { cacheClass = ClassLoaderUtil.loadClass(classname); } Object of = cacheClass.newInstance(); if (!(of instanceof Cache)) { throw new InstantiationException("Class does not implement Cache!"); } ((Cache) of).initialize(this, parameters); return (Cache) of; } catch (Exception e) { throw new IllegalArgumentException("Unable to create cache: " + e, e); } }
private Cache createCache() { try { String classname = parameters.get(SessionParameter.CACHE_CLASS); Class<?> cacheClass; if (classname == null) { cacheClass = CacheImpl.class; } else { cacheClass = ClassLoaderUtil.loadClass(classname); } Object of = cacheClass.newInstance(); if (!(of instanceof Cache)) { throw new InstantiationException("Class does not implement Cache!"); } ((Cache) of).initialize(this, parameters); return (Cache) of; } catch (Exception e) { throw new IllegalArgumentException("Unable to create cache: " + e, e); } }
/** * Loads a class with the reigistered class loaders. */ private static Class<?> loadClassWithRegisteredClassLoaders(String className) throws ClassNotFoundException { if (className == null) { throw new ClassNotFoundException("Class name is null!"); } LOCK.readLock().lock(); try { if (CLASSLOADER_MAP == null) { throw new ClassNotFoundException(); } for (Map<String, ClassLoader> clm : CLASSLOADER_MAP.values()) { for (Map.Entry<String, ClassLoader> cle : clm.entrySet()) { if (cle.getKey().equals(className)) { return loadClass(className, cle.getValue()); } } } throw new ClassNotFoundException(); } finally { LOCK.readLock().unlock(); } }
private ObjectFactory createObjectFactory() { try { String classname = parameters.get(SessionParameter.OBJECT_FACTORY_CLASS); Class<?> objectFactoryClass; if (classname == null) { objectFactoryClass = ObjectFactoryImpl.class; } else { objectFactoryClass = ClassLoaderUtil.loadClass(classname); } Object of = objectFactoryClass.newInstance(); if (!(of instanceof ObjectFactory)) { throw new InstantiationException("Class does not implement ObjectFactory!"); } ((ObjectFactory) of).initialize(this, parameters); return (ObjectFactory) of; } catch (Exception e) { throw new IllegalArgumentException("Unable to create object factory: " + e, e); } }
/** * Loads a class with the reigistered class loaders. */ private static Class<?> loadClassWithRegisteredClassLoaders(String className) throws ClassNotFoundException { if (className == null) { throw new ClassNotFoundException("Class name is null!"); } LOCK.readLock().lock(); try { if (CLASSLOADER_MAP == null) { throw new ClassNotFoundException(); } for (Map<String, ClassLoader> clm : CLASSLOADER_MAP.values()) { for (Map.Entry<String, ClassLoader> cle : clm.entrySet()) { if (cle.getKey().equals(className)) { return loadClass(className, cle.getValue()); } } } throw new ClassNotFoundException(); } finally { LOCK.readLock().unlock(); } }
private void addLevel(String className, String parameters) { // get the class Class<?> clazz; try { clazz = ClassLoaderUtil.loadClass(className, this.getClass().getClassLoader()); } catch (ClassNotFoundException e) { throw new IllegalArgumentException("Class '" + className + "' not found!", e); } // check the class if (!CacheLevel.class.isAssignableFrom(clazz)) { throw new IllegalArgumentException("Class '" + className + "' does not implement the CacheLevel interface!"); } levels.add(clazz); // process parameters if (parameters == null) { levelParameters.add(null); } else { Map<String, String> parameterMap = new HashMap<String, String>(); levelParameters.add(parameterMap); for (String pair : parameters.split(",")) { String[] keyValue = pair.split("="); if (keyValue.length == 1) { parameterMap.put(keyValue[0], ""); } else { parameterMap.put(keyValue[0], keyValue[1]); } } } }
private void addLevel(String className, String parameters) { // get the class Class<?> clazz; try { clazz = ClassLoaderUtil.loadClass(className, this.getClass().getClassLoader()); } catch (ClassNotFoundException e) { throw new IllegalArgumentException("Class '" + className + "' not found!", e); } // check the class if (!CacheLevel.class.isAssignableFrom(clazz)) { throw new IllegalArgumentException("Class '" + className + "' does not implement the CacheLevel interface!"); } levels.add(clazz); // process parameters if (parameters == null) { levelParameters.add(null); } else { Map<String, String> parameterMap = new HashMap<String, String>(); levelParameters.add(parameterMap); for (String pair : parameters.split(",")) { String[] keyValue = pair.split("="); if (keyValue.length == 1) { parameterMap.put(keyValue[0], ""); } else { parameterMap.put(keyValue[0], keyValue[1]); } } } }
public void addGroup(String groupClass) throws Exception { if (groupClass == null) { return; } groupClass = groupClass.trim(); if (groupClass.length() == 0) { return; } Class<?> clazz = ClassLoaderUtil.loadClass(groupClass); Object o = clazz.newInstance(); CmisTestGroup group = null; if (o instanceof CmisTestGroup) { group = (CmisTestGroup) o; } else if (o instanceof CmisTest) { group = new WrapperCmisTestGroup((CmisTest) o); } else { throw new InstantiationException("Not a CmisTestGroup or CmisTest class!"); } addGroup(group); }
object = ClassLoaderUtil.loadClass(className).newInstance(); } catch (Exception e) { LOG.warn("Could not create a services factory instance: {}", e.toString(), e);
Class<?> wrapperClass = null; try { wrapperClass = ClassLoaderUtil.loadClass(value[0]); } catch (ClassNotFoundException e) { throw new CmisRuntimeException("Service wrapper class not found: " + value[0], e);
authProviderObj = ClassLoaderUtil.loadClass(authProviderClassName).newInstance(); } catch (Exception e) { throw new IllegalArgumentException("Could not load authentication provider: " + e, e);
authProviderObj = ClassLoaderUtil.loadClass(authProviderClassName).newInstance(); } catch (Exception e) { throw new IllegalArgumentException("Could not load authentication provider: " + e, e);