All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.objectweb.jonas.server.RemoteClassLoaderSpi Maven / Gradle / Ivy

The newest version!
/**
 * JOnAS: Java(TM) Open Application Server
 * Copyright (C) 1999-2005 Bull S.A.
 * Contact: [email protected]
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
 * USA
 *
 * --------------------------------------------------------------------------
 * $Id: RemoteClassLoaderSpi.java 10822 2007-07-04 08:26:06Z durieuxp $
 * --------------------------------------------------------------------------
 */

package org.objectweb.jonas.server;

import java.net.MalformedURLException;
import java.net.URLClassLoader;
import java.rmi.server.RMIClassLoader;
import java.rmi.server.RMIClassLoaderSpi;

import org.objectweb.carol.util.configuration.CarolDefaultValues;

/**
 * Class RemoteClassLoaderSpi is the CAROL JRMP CLass Loader SPI
 * for serialization performances.
 * @author Guillaume Riviere ([email protected])
 */
public class RemoteClassLoaderSpi extends RMIClassLoaderSpi {

    /**
     * Carol was already initialized
     */
    private static boolean carolIsInitialized = false;

    /**
     * Local call optimization is set
     */
    private static boolean carolIsOptimized = false;

    /**
     * Current provider
     */
    private final RMIClassLoaderSpi defaultProvider = RMIClassLoader.getDefaultProviderInstance();

    /**
     * Loads a class from a codebase URL path, optionally using the supplied
     * loader.
     * @param codebase the list of URLs (separated by spaces) to load the class
     *        from, or null
     * @param name the name of the class to load
     * @param defaultLoader additional contextual class loader to use, or
     *        null
     * @return the Class object representing the loaded class
     * @throws MalformedURLException if codebase is non-null
     *         and contains an invalid URL, or if codebase is
     *         null and the system property
     *         java.rmi.server.codebase contains an invalid URL
     * @throws ClassNotFoundException if a definition for the class could not be
     *         found at the specified location
     */
    public Class loadClass(String codebase, String name, ClassLoader defaultLoader) throws MalformedURLException,
            ClassNotFoundException {
        return defaultProvider.loadClass(codebase, name, defaultLoader);
    }

    /**
     * Loads a dynamic proxy class (see {@link java.lang.reflect.Proxy} that
     * implements a set of interfaces with the given names from a codebase URL
     * path, optionally using the supplied loader.
     * @param codebase the list of URLs (space-separated) to load classes from,
     *        or null
     * @param interfaces the names of the interfaces for the proxy class to
     *        implement
     * @return a dynamic proxy class that implements the named interfaces
     * @param defaultLoader additional contextual class loader to use, or
     *        null
     * @throws MalformedURLException if codebase is non-null
     *         and contains an invalid URL, or if codebase is
     *         null and the system property
     *         java.rmi.server.codebase contains an invalid URL
     * @throws ClassNotFoundException if a definition for one of the named
     *         interfaces could not be found at the specified location, or if
     *         creation of the dynamic proxy class failed (such as if
     *         {@link java.lang.reflect.Proxy#getProxyClass(ClassLoader,Class[])}
     *         would throw an IllegalArgumentException for the
     *         given interface list)
     */
    public Class loadProxyClass(String codebase, String[] interfaces, ClassLoader defaultLoader)
            throws MalformedURLException, ClassNotFoundException {
        return defaultProvider.loadProxyClass(codebase, interfaces, defaultLoader);
    }

    /**
     * Returns a class loader that loads classes from the given codebase URL
     * path.
     * @param codebase the list of URLs (space-separated) from which the
     *        returned class loader will load classes from, or null
     * @return a class loader that loads classes from the given codebase URL
     *         path
     * @throws MalformedURLException if codebase is non-null
     *         and contains an invalid URL, or if codebase is
     *         null and the system property
     *         java.rmi.server.codebase contains an invalid URL
     */
    public ClassLoader getClassLoader(String codebase) throws MalformedURLException {
        return defaultProvider.getClassLoader(codebase);
    }

    /**
     * Returns the annotation string (representing a location for the class
     * definition) that RMI will use to annotate the class descriptor when
     * marshalling objects of the given class.
* By default, remove rmi annotations of JClassLoader class. Between two * JOnAS, commons classes are the same, don't need t have a bigger * annotation. When local call is set, always disable annotation. * @param cl the class to obtain the annotation for * @return a string to be used to annotate the given class when it gets * marshalled, or null */ public String getClassAnnotation(Class cl) { ClassLoader loader = cl.getClassLoader(); // Init values if (!carolIsInitialized) { String sValue = System.getProperty(CarolDefaultValues.LOCALREG_JRMP_PROPERTY, "init"); if (!sValue.equals("init")) { carolIsOptimized = new Boolean(sValue).booleanValue(); carolIsInitialized = true; } } if (loader instanceof JClassLoader) { return null; } else if ((loader instanceof URLClassLoader) && (carolIsOptimized)) { return null; } else { return defaultProvider.getClassAnnotation(cl); } } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy