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 * Nuxeo - initial API and implementation 016 * 017 * $Id$ 018 */ 019 020package org.nuxeo.runtime.launcher; 021 022import java.net.MalformedURLException; 023import java.rmi.server.RMIClassLoader; 024import java.rmi.server.RMIClassLoaderSpi; 025 026/* 027 * (C) Copyright 2006-2008 Nuxeo SAS (http://nuxeo.com/) and contributors. 028 * 029 * All rights reserved. This program and the accompanying materials 030 * are made available under the terms of the GNU Lesser General Public License 031 * (LGPL) version 2.1 which accompanies this distribution, and is available at 032 * http://www.gnu.org/licenses/lgpl.html 033 * 034 * This library is distributed in the hope that it will be useful, 035 * but WITHOUT ANY WARRANTY; without even the implied warranty of 036 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 037 * Lesser General Public License for more details. 038 * 039 * Contributors: 040 * bstefanescu 041 * 042 * $Id$ 043 */ 044 045/** 046 * Copied from org.jboss.system.JBossRMIClassLoader and modified getClassAnnotation to avoid delegating to default 047 * loader since it has a bug. 048 * 049 * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a> 050 */ 051public class NuxeoRMIClassLoader extends RMIClassLoaderSpi { 052 // Attributes ---------------------------------------------------- 053 054 /** 055 * The JVM implementation (we delegate most work to it) 056 */ 057 RMIClassLoaderSpi delegate = RMIClassLoader.getDefaultProviderInstance(); 058 059 // Constructors -------------------------------------------------- 060 061 /** 062 * Required constructor 063 */ 064 public NuxeoRMIClassLoader() { 065 } 066 067 // RMIClassLoaderSpi Implementation ------------------------------ 068 069 /** 070 * Ignore the JVM, use the thread context classloader for proxy caching 071 */ 072 public Class<?> loadProxyClass(String codebase, String[] interfaces, ClassLoader ignored) 073 throws MalformedURLException, ClassNotFoundException { 074 return delegate.loadProxyClass(codebase, interfaces, Thread.currentThread().getContextClassLoader()); 075 } 076 077 /** 078 * Just delegate 079 */ 080 public Class<?> loadClass(String codebase, String name, ClassLoader ignored) throws MalformedURLException, 081 ClassNotFoundException { 082 return delegate.loadClass(codebase, name, Thread.currentThread().getContextClassLoader()); 083 } 084 085 /** 086 * Just delegate 087 */ 088 public ClassLoader getClassLoader(String codebase) throws MalformedURLException { 089 return delegate.getClassLoader(codebase); 090 } 091 092 /** 093 * Try to delegate an default to the java.rmi.server.codebase on any failure. 094 */ 095 public String getClassAnnotation(Class<?> cl) { 096 return System.getProperty("java.rmi.server.codebase"); 097 } 098}