001/* 002 * (C) Copyright 2006-2008 Nuxeo SAS (http://nuxeo.com/) and contributors. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the GNU Lesser General Public License 006 * (LGPL) version 2.1 which accompanies this distribution, and is available at 007 * http://www.gnu.org/licenses/lgpl.html 008 * 009 * This library is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 012 * Lesser General Public License for more details. 013 * 014 * Contributors: 015 * bstefanescu 016 */ 017package org.nuxeo.ecm.webengine.loader; 018 019import java.io.InputStream; 020import java.net.URL; 021 022import org.nuxeo.ecm.webengine.loader.store.ResourceStore; 023import org.nuxeo.ecm.webengine.loader.store.ResourceStoreClassLoader; 024 025/** 026 * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a> 027 */ 028public class ReloadingClassLoader extends ClassLoader { 029 030 private final ClassLoader parent; 031 032 private volatile ResourceStoreClassLoader delegate; 033 034 public ReloadingClassLoader(final ClassLoader pParent) { 035 super(pParent); 036 parent = pParent; 037 delegate = new ResourceStoreClassLoader(parent); 038 } 039 040 public void addResourceStore(final ResourceStore store) { 041 delegate.addStore(store); 042 } 043 044 public boolean removeResourceStore(final ResourceStore store) { 045 return delegate.removeStore(store); 046 } 047 048 public synchronized void reload() { 049 delegate = delegate.clone(); 050 } 051 052 @Override 053 public void clearAssertionStatus() { 054 delegate.clearAssertionStatus(); 055 } 056 057 @Override 058 public URL getResource(String name) { 059 return delegate.getResource(name); 060 } 061 062 @Override 063 public InputStream getResourceAsStream(String name) { 064 return delegate.getResourceAsStream(name); 065 } 066 067 @Override 068 public Class<?> loadClass(String name) throws ClassNotFoundException { 069 return delegate.loadClass(name); 070 } 071 072 @Override 073 public synchronized Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException { 074 return delegate.loadClass(name, resolve); 075 } 076 077 @Override 078 public void setClassAssertionStatus(String className, boolean enabled) { 079 delegate.setClassAssertionStatus(className, enabled); 080 } 081 082 @Override 083 public void setDefaultAssertionStatus(boolean enabled) { 084 delegate.setDefaultAssertionStatus(enabled); 085 } 086 087 @Override 088 public void setPackageAssertionStatus(String packageName, boolean enabled) { 089 delegate.setPackageAssertionStatus(packageName, enabled); 090 } 091 092}