/*
 * JBoss, Home of Professional Open Source
 * Copyright 2005, JBoss Inc., and individual contributors as indicated
 * by the @authors tag. See the copyright.txt in the distribution for a
 * full listing of individual contributors.
 *
 * This 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 (at your option) any later version.
 *
 * This software 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 software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */
package javax.management.loading;

import java.io.Serializable;
import java.util.Vector;

import org.jboss.mx.loading.LoaderRepository;

/**
 * This class provides static methods for loading classes from the MBean agent's
 * loader repository. <p>
 *
 * The implementation delegates all {@link #loadClass loadClass()} calls to
 * the loader repository initialized for this JVM. The 
 *
 * @see org.jboss.mx.loading.LoaderRepository
 * @see org.jboss.mx.loading.BasicLoaderRepository
 *
 * @author  <a href="mailto:juha@jboss.org">Juha Lindfors</a>.
 * @version $Revision: 1.3.4.2 $  
 */
public class DefaultLoaderRepository
     implements Serializable
{
   
   // Attributes ----------------------------------------------------
   
   /**
    * List of classloaders added to the repository. This reference is 
    * initialized to the corresponding <tt>loaders</tt> reference in the
    * {@link org.jboss.mx.loading.LoaderRepository#loaders LoaderRepository}
    * class.
    */
   protected static Vector loaders = null;
   
   /**
    * Reference to the actual classloader repository instance we
    * delegate to.
    */
   private static LoaderRepository repository = null;

   // Constructors --------------------------------------------------
   
   /**
    * Default constructor.
    */
   public DefaultLoaderRepository() {}

   // Static --------------------------------------------------------
   
   //
   // Initialize the DLR with the instance defined by the
   // LOADER_REPOSITORY_CLASS_PROPERTY. The default implementation for the
   // repository instance is defined by the DEFAULT_LOADER_REPOSITORY_CLASS
   // property. The static loaders reference is initialized to reference
   // the loader vector in the instantiated repository. CL repository
   // implementations should populate this vector with the classloaders 
   // added to them if they wish to maintain JMX spec compatibility.
   //
   
   static 
   {
      repository = LoaderRepository.getDefaultLoaderRepository();
      loaders = repository.getLoaders();
   }
   
   public static Class loadClass(String className) throws ClassNotFoundException
   {
      return repository.loadClass(className);
   }

   public static Class loadClassWithout(ClassLoader loader, String className) throws ClassNotFoundException
   {
      return repository.loadClassWithout(loader, className);
   }

}


