static void processConfiguration(ContainerConfig config, Object classLoader, Object context) throws InvocationTargetException, ConfigurationException, IllegalArgumentException, InstantiationException, ClassNotFoundException, IllegalAccessException, NoSuchMethodException, MalformedURLException, Exception { Method putMethod = context.getClass().getMethod(Strings.PUT, new Class[] {Object.class}); Method putByNameMethod = context.getClass().getMethod(Strings.PUT, new Class[] {String.class, Object.class}); /* Add the classpath urls found in the configuration into the classloader. Note that we have to do this by reflection because the classloader we're handed may not be the same classloader that loaded this instance of the Bootstrap class. In particular, this occurs when we are loading the profile configuration by calling out ProfileConfigReader in core-config.xml. In that case, the container classloader is created by the original Bootstrap class inside the original classloader, but ProfileConfigReader and hence another Bootstrap class gets loaded by the container class loader. */ /* Not really sure about this.... would be required if we wanted the profile configs to add jar files to the classpath. Not sure if that is really "on", seeing as how we don't really want users attempting to extend the container. Having said that, it's possible that certain deployers might be in a different project, hence different jar files, so we might want to let the profiles add to the classpath. Needs more thought. for (URL url : findClasspathURLS(config)) { new Statement(classLoader, Strings.ADD_URL, new Object[]{url}).execute(); } */ for (Object element : config.getElements()) { processElement(element, (ClassLoader) classLoader, putMethod, context, putByNameMethod); } }
private static Map<String, ClassLoader> createClassLoaders(ContainerConfig config) throws MalformedURLException { Map<String, ClassLoader> classLoaders = new HashMap<String, ClassLoader>(); classLoaders.put(Strings.BOOTSTRAP_CLASS_LOADER, Bootstrap.class.getClassLoader()); /* Setup the classloaders according to the config file. */ List<String> seen = new LinkedList<String>(); Map<String, Classpath> classpaths = new HashMap<String, Classpath>(); for (Classpath classpath : config.getClasspath()) { if (classpaths.containsKey(classpath.getId())) { throw new ConfigurationException(MessageNames.DUPLICATE_CLASSPATH, classpath.getId()); } classpaths.put(classpath.getId(), classpath); } for (String id : classpaths.keySet()) { resolveClassLoader(classLoaders, seen, classpaths, id); } return classLoaders; }