[Openbus-cvs-commits] Openbus/OpenbusJBI/src/java/org/openbus/jbi/loader/impl ClassLoaderFactoryImpl
Status: Alpha
Brought to you by:
esancho
From: Esteban S. <es...@us...> - 2005-07-27 00:23:08
|
Update of /cvsroot/openbus/Openbus/OpenbusJBI/src/java/org/openbus/jbi/loader/impl In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23990/src/java/org/openbus/jbi/loader/impl Added Files: ClassLoaderFactoryImpl.java Removed Files: DefaultClassLoaderFactoryImpl.java Log Message: Adding more installation code --- NEW FILE: ClassLoaderFactoryImpl.java --- /* * Copyright 2001-2005 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.openbus.jbi.loader.impl; import java.io.File; import java.net.MalformedURLException; import java.net.URL; import java.util.Collection; import java.util.Iterator; import java.util.Map; import java.util.WeakHashMap; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.openbus.jbi.descriptor.ClassPathDesc; import org.openbus.jbi.descriptor.ComponentDesc; import org.openbus.jbi.descriptor.SharedLibraryDesc; import org.openbus.jbi.framework.ComponentRuntimeInfo; import org.openbus.jbi.framework.FrameworkException; import org.openbus.jbi.framework.JBIRegistry; import org.openbus.jbi.framework.JBIRepository; import org.openbus.jbi.framework.SharedLibraryInfo; import org.openbus.jbi.loader.ClassLoaderFactory; import org.openbus.jbi.loader.CompositeClassLoader; import org.openbus.jbi.loader.DelegateClassLoader; /** * * * @author <a href="mailto:es...@op...">Esteban Sancho </a> */ public class ClassLoaderFactoryImpl implements ClassLoaderFactory { private static final String SELF_FIRST_DELEGATION = "self-first"; private static Log log = LogFactory .getLog(ClassLoaderFactoryImpl.class); // key -> SharedLibrary // value -> ClassLoader private Map libraryLoaders = new WeakHashMap(); // key -> Component // value -> ClassLoader private Map bootstrapLoaders = new WeakHashMap(); // key -> Component // value -> ClassLoader private Map componentLoaders = new WeakHashMap(); private JBIRepository repository; public ClassLoaderFactoryImpl() { super(); } public ClassLoader getComponentClassLoader(ComponentRuntimeInfo component_) throws FrameworkException { ClassLoader loader = (ClassLoader) componentLoaders.get(component_); if (loader == null) { JBIRegistry registry = repository.retrieveRegistry(); ComponentDesc descriptor = component_.getDescriptor(); try { URL[] paths = getPathUrls(component_.getInstallRoot(), descriptor.getComponentClassPath()); Collection dependencies = descriptor.getRequiredLibraries(); CompositeClassLoader libsLoader = new CompositeClassLoader(); for (Iterator i = dependencies.iterator(); i.hasNext();) { SharedLibraryDesc libDesc = (SharedLibraryDesc) i.next(); SharedLibraryInfo lib = registry.getSharedLibrary(libDesc .getIdentification().getName(), libDesc .getVersion()); libsLoader.addClassLoader(getLibraryClassLoader(lib)); } // get loading delegation String delegation = descriptor .getComponentClassLoaderDelegation(); boolean parentFirst = !(delegation .equals(SELF_FIRST_DELEGATION)); loader = new DelegateClassLoader(paths, libsLoader, parentFirst); // store for future use componentLoaders.put(component_, loader); } catch (MalformedURLException e) { // @todo i18n throw new FrameworkException( "Unable to create component class loader", e); } } return loader; } protected DelegateClassLoader getLibraryClassLoader(SharedLibraryInfo library_) throws FrameworkException { if (library_ == null) { // @todo i18n throw new IllegalArgumentException("Parameter is null: library_"); } DelegateClassLoader loader = (DelegateClassLoader) libraryLoaders .get(library_); if (loader == null) { SharedLibraryDesc descriptor = library_.getDescriptor(); // get loading delegation String delegation = descriptor.getClassLoaderDelegation(); boolean parentFirst = !(delegation.equals(SELF_FIRST_DELEGATION)); try { URL[] paths = getPathUrls(library_.getInstallRoot(), descriptor .getClassPath()); loader = new DelegateClassLoader(paths, getJBIClassLoader(), parentFirst); libraryLoaders.put(library_, loader); } catch (MalformedURLException e) { // @todo i18n throw new FrameworkException( "Unable to create shared library class loader", e); } } return loader; } public ClassLoader getBootstrapClassLoader(ComponentRuntimeInfo component_) throws FrameworkException { ClassLoader loader = (ClassLoader) bootstrapLoaders.get(component_); if (loader == null) { ComponentDesc descriptor = component_.getDescriptor(); // get loading delegation String delegation = descriptor.getBootstrapClassLoaderDelegation(); boolean parentFirst = !(delegation.equals(SELF_FIRST_DELEGATION)); try { URL[] paths = getPathUrls(component_.getInstallRoot(), descriptor.getBootstrapClassPath()); loader = new DelegateClassLoader(paths, getJBIClassLoader(), parentFirst); bootstrapLoaders.put(component_, loader); } catch (MalformedURLException e) { // @todo i18n throw new FrameworkException( "Unable to create bootstrap class loader", e); } } return loader; } protected URL[] getPathUrls(String root_, ClassPathDesc cp_) throws MalformedURLException { Collection entries = cp_.getPathElements(); URL[] paths = new URL[entries.size()]; int counter = 0; for (Iterator i = entries.iterator(); i.hasNext(); counter++) { String entry = root_ + File.separator + (String) i.next(); if (log.isDebugEnabled()) { log.debug("Adding URL to classpath: " + entry); } paths[counter] = new URL("file", null, entry); } return paths; } protected ClassLoader getJBIClassLoader() { // @todo define appropriate class loader return ClassLoader.getSystemClassLoader(); } public JBIRepository getRepository() { return repository; } public void setRepository(JBIRepository repository_) { repository = repository_; } } --- DefaultClassLoaderFactoryImpl.java DELETED --- |