/** * 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); } } }
/** * 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; }
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); } }
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(); } }
/** * 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); }
invoker = (HttpInvoker) ClassLoaderUtil.loadClass(invokerName).newInstance(); } catch (CmisBaseException e) { throw e;
invoker = (HttpInvoker) ClassLoaderUtil.loadClass(invokerName).newInstance(); } catch (CmisBaseException e) { throw e;
invoker = new DefaultHttpInvoker(); } else { invoker = (HttpInvoker) ClassLoaderUtil.loadClass(invokerName).newInstance();
invoker = new DefaultHttpInvoker(); } else { invoker = (HttpInvoker) ClassLoaderUtil.loadClass(invokerName).newInstance();
cache = (TypeDefinitionCache) ClassLoaderUtil.loadClass(cacheName).newInstance(); cache.initialize(session); } catch (CmisBaseException e) {
factory = (CmisServiceFactory) ClassLoaderUtil.loadClass(serviceFactoryClassname).newInstance(); factory.init(parameters); } catch (Exception e) {
cache = (TypeDefinitionCache) ClassLoaderUtil.loadClass(cacheName).newInstance(); cache.initialize(session); } catch (CmisBaseException e) {