001/* 002 * (C) Copyright 2006-2008 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * bstefanescu 018 */ 019package org.nuxeo.ecm.webengine.loader; 020 021import java.io.InputStream; 022import java.net.URL; 023 024import org.nuxeo.ecm.webengine.loader.store.ResourceStore; 025import org.nuxeo.ecm.webengine.loader.store.ResourceStoreClassLoader; 026 027/** 028 * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a> 029 */ 030public class ReloadingClassLoader extends ClassLoader { 031 032 private final ClassLoader parent; 033 034 private volatile ResourceStoreClassLoader delegate; 035 036 public ReloadingClassLoader(final ClassLoader pParent) { 037 super(pParent); 038 parent = pParent; 039 delegate = new ResourceStoreClassLoader(parent); 040 } 041 042 public void addResourceStore(final ResourceStore store) { 043 delegate.addStore(store); 044 } 045 046 public boolean removeResourceStore(final ResourceStore store) { 047 return delegate.removeStore(store); 048 } 049 050 public synchronized void reload() { 051 delegate = delegate.clone(); 052 } 053 054 @Override 055 public void clearAssertionStatus() { 056 delegate.clearAssertionStatus(); 057 } 058 059 @Override 060 public URL getResource(String name) { 061 return delegate.getResource(name); 062 } 063 064 @Override 065 public InputStream getResourceAsStream(String name) { 066 return delegate.getResourceAsStream(name); 067 } 068 069 @Override 070 public Class<?> loadClass(String name) throws ClassNotFoundException { 071 return delegate.loadClass(name); 072 } 073 074 @Override 075 public synchronized Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException { 076 return delegate.loadClass(name, resolve); 077 } 078 079 @Override 080 public void setClassAssertionStatus(String className, boolean enabled) { 081 delegate.setClassAssertionStatus(className, enabled); 082 } 083 084 @Override 085 public void setDefaultAssertionStatus(boolean enabled) { 086 delegate.setDefaultAssertionStatus(enabled); 087 } 088 089 @Override 090 public void setPackageAssertionStatus(String packageName, boolean enabled) { 091 delegate.setPackageAssertionStatus(packageName, enabled); 092 } 093 094}