Package org.jboss.mx.loading

Source Code of org.jboss.mx.loading.LoaderRepositoryFactory

/***************************************
*                                     *
*  JBoss: The OpenSource J2EE WebOS   *
*                                     *
*  Distributable under LGPL license.  *
*  See terms of license at gnu.org.   *
*                                     *
***************************************/

package org.jboss.mx.loading;

import javax.management.InstanceNotFoundException;
import javax.management.JMException;
import javax.management.ListenerNotFoundException;
import javax.management.MBeanServer;
import javax.management.NotificationBroadcasterSupport;
import javax.management.NotificationFilter;
import javax.management.NotificationListener;
import javax.management.ObjectInstance;
import javax.management.ObjectName;
import org.jboss.mx.server.ServerConstants;


/**
* LoaderRepositoryFactory.java
*
*
* Created: Fri Jul  5 15:26:00 2002
*
* @author <a href="mailto:d_jencks@users.sourceforge.net">David Jencks</a>
* @version $Revision: 1.4 $
*/

public class LoaderRepositoryFactory {

   public static ObjectName DEFAULT_LOADER_REPOSITORY;

   private static final NotificationBroadcasterSupport broadcaster = new NotificationBroadcasterSupport();


   private LoaderRepositoryFactory (){
     
   }

   public static synchronized void ensureLoaderRepository(
      MBeanServer server,
      String repositoryClassName,
      ObjectName repositoryName) throws JMException
   {
      if (DEFAULT_LOADER_REPOSITORY == null)
      {
   DEFAULT_LOADER_REPOSITORY = new ObjectName(ServerConstants.DEFAULT_LOADER_NAME);
      }
      try
      {
   ObjectInstance oi = server.getObjectInstance(repositoryName);
   if ((repositoryClassName != null) && !oi.getClassName().equals(repositoryClassName))
   {
      throw new JMException("Inconsistent LoaderRepository class specification in repository: " + repositoryName);
   } // end of if ()
      }
      catch (InstanceNotFoundException e)
      {
   //we are the first, make the repository.
   if( repositoryClassName == null )
      repositoryClassName = "org.jboss.mx.loading.HeirarchicalLoaderRepository2";
   try
   {
      // Create the repository loader
      Object[] args = {server, DEFAULT_LOADER_REPOSITORY};
      String[] sig = {"javax.management.MBeanServer", "javax.management.ObjectName"};
      server.createMBean(repositoryClassName, repositoryName,
            args, sig);
   }
   catch(Exception e2)
   {
      throw new JMException("Failed to create deployment loader repository:" + e2);
   }
      } // end of try-catch
   }

   static NotificationBroadcasterSupport getNotificationBroadcaster()
   {
      return broadcaster;
   }

   public static void addNotificationListener(NotificationListener listener,
                NotificationFilter filter,
                Object handback)
      throws IllegalArgumentException
   {
      broadcaster.addNotificationListener(listener, filter, handback);
   }

   public static void removeNotificationListener(NotificationListener listener)
      throws ListenerNotFoundException
   {
      broadcaster.removeNotificationListener(listener);
   }

   public static void removeNotificationListener(NotificationListener listener,
                                                 NotificationFilter filter,
                                                 Object handback)
      throws ListenerNotFoundException
   {
      broadcaster.removeNotificationListener(listener, filter, handback);
   }

}// LoaderRepositoryFactory
TOP

Related Classes of org.jboss.mx.loading.LoaderRepositoryFactory

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.