User: schaefera
  Date: 01/12/08 21:01:43

  Modified:    src/main/org/jboss/management/j2ee JDBC.java
                        JDBCDataSource.java
  Added:       src/main/org/jboss/management/j2ee JDBCDataSourceMBean.java
                        JDBCDriver.java JDBCDriverMBean.java JDBCMBean.java
  Removed:     src/main/org/jboss/management/j2ee JDBCConnection.java
                        JDBCConnectionPool.java
  Log:
  Added Notification Transport to JSR-77 which works similar to EJB-Connector
  but with the tweak of JSR-77 interface.
  Added the adjusted JDBC JSR-77 shadow objects.
  Added JSR-77 to the Connector Factory enabling JSR-77 to start and stop
  Datasources.
  Added a testsuite for JSR-77 which tests the basic stuff inclusive the
  notification delivery.
  
  Revision  Changes    Path
  1.4       +281 -30   jboss/src/main/org/jboss/management/j2ee/JDBC.java
  
  Index: JDBC.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/management/j2ee/JDBC.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- JDBC.java 2001/11/27 06:15:26     1.3
  +++ JDBC.java 2001/12/09 05:01:43     1.4
  @@ -6,68 +6,319 @@
    */
   package org.jboss.management.j2ee;
   
  +import java.util.ArrayList;
  +import java.util.Iterator;
  +import java.util.List;
  +import java.util.Set;
  +
  +import javax.management.AttributeChangeNotification;
  +import javax.management.JMException;
   import javax.management.MalformedObjectNameException;
  +import javax.management.MBeanServer;
  +import javax.management.Notification;
  +import javax.management.NotificationListener;
   import javax.management.ObjectName;
   
  -import javax.management.j2ee.JDBCConnection;
  +import org.jboss.logging.Logger;
  +import org.jboss.system.ServiceMBean;
   
   /**
  -* @author Marc Fleury
  -**/
  + * Root class of the JBoss JSR-77 implementation of
  + * {@link javax.management.j2ee.JDBC JDBC}.
  + *
  + * @author  <a href="mailto:[EMAIL PROTECTED]";>Andreas Schaefer</a>.
  + * @version $Revision: 1.4 $
  + *   
  + * <p><b>Revisions:</b>
  + *
  + * <p><b>20011126 Andreas Schaefer:</b>
  + * <ul>
  + * <li> Creation
  + * </ul>
  + **/
   public class JDBC
      extends J2EEResource
  -   implements javax.management.j2ee.JDBC
  +   implements JDBCMBean
   {
  -   // -------------------------------------------------------------------------
  -   // Members
  -   // -------------------------------------------------------------------------  
  -
  -   private JDBCConnection[] mConnections;
  -
  -   // -------------------------------------------------------------------------
  -   // Constructors
  -   // -------------------------------------------------------------------------
  -
  +   // Constants -----------------------------------------------------
  +   
  +   // Attributes ----------------------------------------------------
  +   
  +   private long mStartTime = -1;
  +   private int mState = ServiceMBean.STOPPED;
  +   private ObjectName mService;
  +   
  +   private List mDatasources = new ArrayList();
  +   
  +   // Static --------------------------------------------------------
  +   
  +   private static final String[] sTypes = new String[] {
  +                                             "j2ee.object.created",
  +                                             "j2ee.object.deleted",
  +                                             "state.stopped",
  +                                             "state.stopping",
  +                                             "state.starting",
  +                                             "state.running",
  +                                             "state.failed"
  +                                          };
  +   
  +   public static ObjectName create( MBeanServer pServer, String pName ) {
  +      Logger lLog = Logger.getLogger( JNDI.class );
  +      ObjectName lServer = null;
  +      try {
  +         lServer = (ObjectName) pServer.queryNames(
  +             new ObjectName( J2EEManagedObject.getDomainName() + 
":type=J2EEServer,*" ),
  +             null
  +         ).iterator().next();
  +      }
  +      catch( Exception e ) {
  +         lLog.error( "Could not create JSR-77 JDBC Manager", e );
  +         return null;
  +      }
  +      try {
  +         // Now create the JNDI Representant
  +         return pServer.createMBean(
  +            "org.jboss.management.j2ee.JDBC",
  +            null,
  +            new Object[] {
  +               pName,
  +               lServer
  +            },
  +            new String[] {
  +               String.class.getName(),
  +               ObjectName.class.getName()
  +            }
  +         ).getObjectName();
  +      }
  +      catch( Exception e ) {
  +         lLog.error( "Could not create JSR-77 JDBC Manager", e );
  +         return null;
  +      }
  +   }
  +   
  +   public static void destroy( MBeanServer pServer, String pName ) {
  +      Logger lLog = Logger.getLogger( JNDI.class );
  +      try {
  +         // Find the Object to be destroyed
  +         ObjectName lSearch = new ObjectName(
  +            J2EEManagedObject.getDomainName() + ":type=JDBC,name=" + pName + ",*"
  +         );
  +         Set lNames = pServer.queryNames(
  +            lSearch,
  +            null
  +         );
  +         if( !lNames.isEmpty() ) {
  +            ObjectName lJDBC = (ObjectName) lNames.iterator().next();
  +            // Now check if the JDBC Manager does not contains another DataSources
  +            ObjectName[] lDataSources = (ObjectName[]) pServer.getAttribute(
  +               lJDBC,
  +               "DataSources"
  +            );
  +            if( lDataSources.length == 0 ) {
  +               // Remove it because it does not reference any JDBC DataSources
  +               pServer.unregisterMBean( lJDBC );
  +            }
  +         }
  +      }
  +      catch( Exception e ) {
  +         lLog.error( "Could not destroy JSR-77 JDBC Manager", e );
  +      }
  +   }
  +   
  +   // Constructors --------------------------------------------------
  +   
      /**
       * @param pName Name of the JDBC
       *
       * @throws InvalidParameterException If list of nodes or ports was null or empty
       **/
  -   public JDBC( String pName, ObjectName pServer, JDBCConnection[] pConnections )
  +   public JDBC( String pName, ObjectName pServer )
         throws
            MalformedObjectNameException,
            InvalidParentException
      {
         super( "JDBC", pName, pServer );
  -      if( pConnections == null ) {
  -         mConnections = new JDBCConnection[ 0 ];
  -      }
  -      else {
  -         mConnections = pConnections;
  +   }
  +   
  +   // Public --------------------------------------------------------
  +   
  +   // javax.managment.j2ee.EventProvider implementation -------------
  +   
  +   public String[] getTypes() {
  +      return sTypes;
  +   }
  +   
  +   public String getType( int pIndex ) {
  +      if( pIndex >= 0 && pIndex < sTypes.length ) {
  +         return sTypes[ pIndex ];
  +      } else {
  +         return null;
         }
      }
  +   
  +   // javax.management.j2ee.StateManageable implementation ----------
  +   
  +   public long getStartTime() {
  +      return mStartTime;
  +   }
  +   
  +   public int getState() {
  +      return mState;
  +   }
   
  -   // -------------------------------------------------------------------------
  -   // Properties (Getters/Setters)
  -   // -------------------------------------------------------------------------  
  +   public void startService() {
  +      mState = ServiceMBean.STARTING;
  +      sendNotification(
  +         new Notification(
  +            sTypes[ 4 ],
  +            getName(),
  +            1,
  +            System.currentTimeMillis(),
  +            "JDBC Manager starting"
  +         )
  +      );
  +      mState = ServiceMBean.STARTED;
  +      sendNotification(
  +         new Notification(
  +            sTypes[ 5 ],
  +            getName(),
  +            2,
  +            System.currentTimeMillis(),
  +            "JDBC Manager started"
  +         )
  +      );
  +   }
   
  -   public JDBCConnection[] getJDBCConnections() {
  -      return mConnections;
  +   public void startRecursive() {
  +      // No recursive start here
  +      start();
  +      Iterator i = mDatasources.iterator();
  +      ObjectName lDataSource = null;
  +      while( i.hasNext() ) {
  +         lDataSource = (ObjectName) i.next();
  +         try {
  +            getServer().invoke(
  +               lDataSource,
  +               "start",
  +               new Object[] {},
  +               new String[] {}
  +            );
  +         }
  +         catch( JMException jme ) {
  +            getLog().error( "Could not stop JSR-77 JDBC-DataSource: " + 
lDataSource, jme );
  +         }
  +      }
  +   }
  +
  +   public void stopService() {
  +      Iterator i = mDatasources.iterator();
  +      while( i.hasNext() ) {
  +         ObjectName lDataSource = (ObjectName) i.next();
  +         try {
  +            getServer().invoke(
  +               lDataSource,
  +               "stop",
  +               new Object[] {},
  +               new String[] {}
  +            );
  +         }
  +         catch( JMException jme ) {
  +            getLog().error( "Could not stop JSR-77 JDBC-DataSource: " + 
lDataSource, jme );
  +         }
  +      }
  +      mState = ServiceMBean.STOPPING;
  +      sendNotification(
  +         new Notification(
  +            sTypes[ 2 ],
  +            getName(),
  +            1,
  +            System.currentTimeMillis(),
  +            "JDBC Manager stopping"
  +         )
  +      );
  +      mState = ServiceMBean.STOPPED;
  +      sendNotification(
  +         new Notification(
  +            sTypes[ 3 ],
  +            getName(),
  +            2,
  +            System.currentTimeMillis(),
  +            "JDBC Manager stopped"
  +         )
  +      );
  +   }
  +   
  +   // org.jboss.ServiceMBean overrides ------------------------------------
  +   
  +   public void postRegister( Boolean pRegisterationDone ) {
  +      super.postRegister( pRegisterationDone );
  +      sendNotification(
  +         new J2EEManagementEvent(
  +            sTypes[ 0 ],
  +            getName(),
  +            1,
  +            System.currentTimeMillis(),
  +            "JDBC Resource created"
  +         ).getNotification()
  +      );
  +   }
  +   
  +   public void preDeregister() {
  +      sendNotification(
  +         new J2EEManagementEvent(
  +            sTypes[ 1 ],
  +            getName(),
  +            1,
  +            System.currentTimeMillis(),
  +            "JDBC Resource deleted"
  +         ).getNotification()
  +      );
      }
      
  -   public JDBCConnection getJDBCConnection( int pIndex ) {
  -      if( pIndex >= 0 && pIndex < mConnections.length ) {
  -         return mConnections[ pIndex ];
  +   // javax.management.j2ee.JDBC implementation ---------------------
  +   
  +   public ObjectName[] getDataSources() {
  +      return (ObjectName[]) mDatasources.toArray( new ObjectName[ 
mDatasources.size() ] );
  +   }
  +   
  +   public ObjectName getDataSource( int pIndex ) {
  +      if( pIndex >= 0 && pIndex < mDatasources.size() ) {
  +         return (ObjectName) mDatasources.get( pIndex );
         }
         else {
            return null;
         }
      }
      
  +   // J2EEManagedObjectMBean implementation -------------------------
  +   
  +   public void addChild( ObjectName pChild ) {
  +      String lType = J2EEManagedObject.getType( pChild );
  +      if( "JDBCDataSource".equals( lType ) ) {
  +         mDatasources.add( pChild );
  +      }
  +   }
  +   
  +   public void removeChild( ObjectName pChild ) {
  +      String lType = J2EEManagedObject.getType( pChild );
  +      if( "JDBCDataSource".equals( lType ) ) {
  +         mDatasources.remove( pChild );
  +      }
  +   }
  +
  +   // java.lang.Object overrides ------------------------------------
  +   
      public String toString() {
  -      return "JDBC[ " + super.toString() +
  -         ", JDBC Connection: " + java.util.Arrays.asList( getJDBCConnections() ) +
  +      return "JDBC { " + super.toString() + " } [ " +
  +         "Datasources: " + mDatasources +
            " ]";
      }
   
  +   // Package protected ---------------------------------------------
  +   
  +   // Protected -----------------------------------------------------
  +   
  +   // Private -------------------------------------------------------
  +   
  +   // Inner classes -------------------------------------------------
   }
  
  
  
  1.4       +282 -15   jboss/src/main/org/jboss/management/j2ee/JDBCDataSource.java
  
  Index: JDBCDataSource.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jboss/src/main/org/jboss/management/j2ee/JDBCDataSource.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- JDBCDataSource.java       2001/11/27 06:15:26     1.3
  +++ JDBCDataSource.java       2001/12/09 05:01:43     1.4
  @@ -6,15 +6,25 @@
    */
   package org.jboss.management.j2ee;
   
  +import java.util.Set;
  +
  +import javax.management.AttributeChangeNotification;
  +import javax.management.JMException;
   import javax.management.MalformedObjectNameException;
  +import javax.management.MBeanServer;
  +import javax.management.Notification;
  +import javax.management.NotificationListener;
   import javax.management.ObjectName;
   
  +import org.jboss.logging.Logger;
  +import org.jboss.system.ServiceMBean;
  +
   /**
    * Root class of the JBoss JSR-77 implementation of
    * {@link javax.management.j2ee.JDBCDataSource JDBCDataSource}.
    *
    * @author  <a href="mailto:[EMAIL PROTECTED]";>Andreas Schaefer</a>.
  - * @version $Revision: 1.3 $
  + * @version $Revision: 1.4 $
    *   
    * <p><b>Revisions:</b>
    *
  @@ -22,39 +32,296 @@
    * <ul>
    * <li> Adjustments to the JBoss Guidelines
    * </ul>
  + * <p><b>20011206 Andreas Schaefer:</b>
  + * <ul>
  + * <li> Finishing first real implementation
  + * </ul>
    **/
   public class JDBCDataSource
      extends J2EEManagedObject
  -   implements javax.management.j2ee.JDBCDataSource
  +   implements JDBCDataSourceMBean
   {
  -   // -------------------------------------------------------------------------
  -   // Members
  -   // -------------------------------------------------------------------------  
  -
  -   // -------------------------------------------------------------------------
  -   // Constructors
  -   // -------------------------------------------------------------------------
  -
  +   // Constants -----------------------------------------------------
  +   
  +   // Attributes ----------------------------------------------------
  +   
  +   private long mStartTime = -1;
  +   private int mState = ServiceMBean.STOPPED;
  +   private ObjectName mService;
  +   
  +   // Static --------------------------------------------------------
  +   
  +   private static final String[] sTypes = new String[] {
  +                                             "j2ee.object.created",
  +                                             "j2ee.object.deleted",
  +                                             "state.stopped",
  +                                             "state.stopping",
  +                                             "state.starting",
  +                                             "state.running",
  +                                             "state.failed"
  +                                          };
  +   
  +   public static ObjectName create( MBeanServer pServer, String pName, ObjectName 
pService ) {
  +      Logger lLog = Logger.getLogger( JNDI.class );
  +      ObjectName lServer = null;
  +      try {
  +         lServer = (ObjectName) pServer.queryNames(
  +             new ObjectName( J2EEManagedObject.getDomainName() + 
":type=J2EEServer,*" ),
  +             null
  +         ).iterator().next();
  +      }
  +      catch( Exception e ) {
  +         lLog.error( "Could not locate JSR-77 Server: " + pName, e );
  +         // Return because without the JDBC manager go on does not work
  +         return null;
  +      }
  +      // First create its parent the JDBC resource
  +      ObjectName lJDBC = null;
  +      try {
  +         // Check if the JDBC Manager exists and if not create one
  +         Set lNames = pServer.queryNames(
  +             new ObjectName( J2EEManagedObject.getDomainName() + ":type=JDBC,*" ),
  +             null
  +         );
  +         if( lNames.isEmpty() ) {
  +            // Now create the JDBC Manager
  +            lJDBC = JDBC.create( pServer, "JDBC" );
  +         } else {
  +            lJDBC = (ObjectName) lNames.iterator().next();
  +         }
  +      }
  +      catch( Exception e ) {
  +         lLog.error( "Could not create JSR-77 JDBC Manager", e );
  +         // Return because without the JDBC manager go on does not work
  +         return null;
  +      }
  +      
  +      try {
  +         //AS ToDo: Replace any ':' by '~' do avoid ObjectName conflicts for now
  +         //AS FixMe: look for a solution
  +         pName = pName.replace( ':', '~' );
  +         // Now create the JNDI Representant
  +         return pServer.createMBean(
  +            "org.jboss.management.j2ee.JDBCDataSource",
  +            null,
  +            new Object[] {
  +               pName,
  +               lJDBC,
  +               pService
  +            },
  +            new String[] {
  +               String.class.getName(),
  +               ObjectName.class.getName(),
  +               ObjectName.class.getName()
  +            }
  +         ).getObjectName();
  +      }
  +      catch( Exception e ) {
  +         lLog.error( "Could not create JSR-77 JDBC DataSource: " + pName, e );
  +         return null;
  +      }
  +   }
  +   
  +   public static void destroy( MBeanServer pServer, String pName ) {
  +      Logger lLog = Logger.getLogger( JNDI.class );
  +      try {
  +         // Find the Object to be destroyed
  +         ObjectName lSearch = new ObjectName(
  +            J2EEManagedObject.getDomainName() + ":type=JDBCDataSource,name=" + 
pName + ",*"
  +         );
  +         ObjectName lJNDI = (ObjectName) pServer.queryNames(
  +            lSearch,
  +            null
  +         ).iterator().next();
  +         // Now remove the J2EEApplication
  +         pServer.unregisterMBean( lJNDI );
  +         // Now let us try to destroy the JDBC Manager
  +         JDBC.destroy( pServer, "JDBC" );
  +      }
  +      catch( Exception e ) {
  +         lLog.error( "Could not destroy JSR-77 JDBC DataSource: " + pName, e );
  +      }
  +   }
  +   
  +   // Constructors --------------------------------------------------
  +   
      /**
      * @param pName Name of the JDBCDataSource
      *
      * @throws InvalidParameterException If list of nodes or ports was null or empty
      **/
  -   public JDBCDataSource( String pName, ObjectName pServer )
  +   public JDBCDataSource( String pName, ObjectName pServer, ObjectName pService )
         throws
            MalformedObjectNameException,
            InvalidParentException
      {
         super( "JDBCDataSource", pName, pServer );
  +      mService = pService;
  +   }
  +   
  +   // Public --------------------------------------------------------
  +   
  +   // javax.managment.j2ee.EventProvider implementation -------------
  +   
  +   public String[] getTypes() {
  +      return sTypes;
  +   }
  +   
  +   public String getType( int pIndex ) {
  +      if( pIndex >= 0 && pIndex < sTypes.length ) {
  +         return sTypes[ pIndex ];
  +      } else {
  +         return null;
  +      }
      }
  +   
  +   // javax.management.j2ee.StateManageable implementation ----------
  +   
  +   public long getStartTime() {
  +      return mStartTime;
  +   }
  +   
  +   public int getState() {
  +      return mState;
  +   }
   
  -   // -------------------------------------------------------------------------
  -   // Properties (Getters/Setters)
  -   // -------------------------------------------------------------------------  
  +   public void startService() {
  +      try {
  +         getServer().invoke(
  +            mService,
  +            "start",
  +            new Object[] {},
  +            new String[] {}
  +         );
  +      }
  +      catch( JMException jme ) {
  +         //AS ToDo: later on we have to define what happens when service could not 
be started
  +         jme.printStackTrace();
  +      }
  +   }
   
  +   public void startRecursive() {
  +      // No recursive start here
  +      try {
  +         start();
  +      }
  +      catch( Exception e ) {
  +         getLog().error( "start failed", e );
  +      }
  +   }
  +
  +   public void stopService() {
  +      try {
  +         getServer().invoke(
  +            mService,
  +            "stop",
  +            new Object[] {},
  +            new String[] {}
  +         );
  +      }
  +      catch( JMException jme ) {
  +         //AS ToDo: later on we have to define what happens when service could not 
be started
  +         jme.printStackTrace();
  +      }
  +   }
  +   
  +   // org.jboss.ServiceMBean overrides ------------------------------------
  +   
  +   public void postRegister( Boolean pRegisterationDone ) {
  +      super.postRegister( pRegisterationDone );
  +      // If set then register for its events
  +      try {
  +         getServer().addNotificationListener( mService, new Listener(), null, null 
);
  +      }
  +      catch( JMException jme ) {
  +         //AS ToDo: later on we have to define what happens when service is null or
  +         //AS ToDo: not found.
  +         jme.printStackTrace();
  +      }
  +      sendNotification(
  +         new J2EEManagementEvent(
  +            sTypes[ 0 ],
  +            getName(),
  +            1,
  +            System.currentTimeMillis(),
  +            "JDBC DataSource Resource created"
  +         ).getNotification()
  +      );
  +   }
  +   
  +   public void preDeregister() {
  +      getLog().info( "JDBCDataSource.preDeregister(): " + getName() );
  +      sendNotification(
  +         new J2EEManagementEvent(
  +            sTypes[ 1 ],
  +            getName(),
  +            1,
  +            System.currentTimeMillis(),
  +            "JDBC DataSource Resource deleted"
  +         ).getNotification()
  +      );
  +   }
  +   
  +   // ServiceMBeanSupport overrides ---------------------------------
  +   
  +   /**
  +    * This method is only overwriten because to catch the exception
  +    * which is not specified in {@link javax.management.j2ee.StateManageable
  +    * StateManageable} interface.
  +    **/
  +   public void start()
  +   {
  +      try {
  +         super.start();
  +      }
  +      catch( Exception e ) {
  +         getLog().error( "start failed", e );
  +      }
  +   }
  +
  +   // java.lang.Object overrides ------------------------------------
  +   
      public String toString() {
  -      return "JDBCDatasource[ " + super.toString() +
  +      return "JDBCDatasource { " + super.toString() + " } [ " +
            " ]";
      }
  -
  +   
  +   // Package protected ---------------------------------------------
  +   
  +   // Protected -----------------------------------------------------
  +   
  +   // Private -------------------------------------------------------
  +   
  +   // Inner classes -------------------------------------------------
  +   
  +   private class Listener implements NotificationListener {
  +      
  +      public void handleNotification( Notification pNotification, Object pHandback )
  +      {
  +         if( pNotification instanceof AttributeChangeNotification ) {
  +            AttributeChangeNotification lChange = (AttributeChangeNotification) 
pNotification;
  +            if( "State".equals( lChange.getAttributeName() ) )
  +            {
  +               mState = ( (Integer) lChange.getNewValue() ).intValue();
  +               if( mState == ServiceMBean.STARTED ) {
  +                  mStartTime = lChange.getTimeStamp();
  +               } else {
  +                  mStartTime = -1;
  +               }
  +               // Now send the event to the JSR-77 listeners
  +               sendNotification(
  +                  new Notification(
  +                     sTypes[ getState() + 2 ],
  +                     getName(),
  +                     1,
  +                     System.currentTimeMillis(),
  +                     "State changed"
  +                  )
  +               );
  +            }
  +         }
  +      }
  +      
  +   }
  +   
   }
  
  
  
  1.1                  
jboss/src/main/org/jboss/management/j2ee/JDBCDataSourceMBean.java
  
  Index: JDBCDataSourceMBean.java
  ===================================================================
  /*
   * JBoss, the OpenSource J2EE webOS
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */
  package org.jboss.management.j2ee;
  
  import javax.management.j2ee.JDBCDataSource;
  import javax.management.j2ee.StateManageable;
  
  /**
   * MBean Mangement Inteface for {@link org.jboss.management.j2ee.JDBCDataSource
   * JDBCDataSource}.
   *
   * @author  <a href="mailto:[EMAIL PROTECTED]";>Andreas Schaefer</a>.
   * @version $Revision: 1.1 $
   *   
   * <p><b>Revisions:</b>
   *
   * <p><b>20011206 Andreas Schaefer:</b>
   * <ul>
   * <li> Creation
   * </ul>
   **/
  public interface JDBCDataSourceMBean
     extends JDBCDataSource, StateManageable, J2EEManagedObjectMBean
  {
  }
  
  
  
  1.1                  jboss/src/main/org/jboss/management/j2ee/JDBCDriver.java
  
  Index: JDBCDriver.java
  ===================================================================
  /*
   * JBoss, the OpenSource J2EE webOS
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */
  package org.jboss.management.j2ee;
  
  import javax.management.MalformedObjectNameException;
  import javax.management.MBeanServer;
  import javax.management.ObjectName;
  
  import org.jboss.logging.Logger;
  
  /**
   * Root class of the JBoss JSR-77 implementation of
   * {@link javax.management.j2ee.JDBCDataSource JDBCDataSource}.
   *
   * @author  <a href="mailto:[EMAIL PROTECTED]";>Andreas Schaefer</a>.
   * @version $Revision: 1.1 $
   *   
   * <p><b>Revisions:</b>
   *
   * <p><b>20011126 Andreas Schaefer:</b>
   * <ul>
   * <li> Adjustments to the JBoss Guidelines
   * </ul>
   * <p><b>20011206 Andreas Schaefer:</b>
   * <ul>
   * <li> Finishing first real implementation
   * </ul>
   **/
  public class JDBCDriver
     extends J2EEManagedObject
     implements JDBCDriverMBean
  {
     // Constants -----------------------------------------------------
     
     // Attributes ----------------------------------------------------
     
     // Static --------------------------------------------------------
     
     public static ObjectName create( MBeanServer pServer, String pName, ObjectName 
pService ) {
        Logger lLog = Logger.getLogger( JNDI.class );
        ObjectName lServer = null;
        try {
           lServer = (ObjectName) pServer.queryNames(
               new ObjectName( J2EEManagedObject.getDomainName() + 
":type=J2EEServer,*" ),
               null
           ).iterator().next();
        }
        catch( Exception e ) {
  //AS         lLog.error( "Could not create JSR-77 JNDI: " + pName, e );
           return null;
        }
        try {
           // Now create the JNDI Representant
           return pServer.createMBean(
              "org.jboss.management.j2ee.JDBCDriver",
              null,
              new Object[] {
                 pName,
                 lServer
              },
              new String[] {
                 String.class.getName(),
                 ObjectName.class.getName()
              }
           ).getObjectName();
        }
        catch( Exception e ) {
  //AS         lLog.error( "Could not create JSR-77 JNDI: " + pName, e );
           return null;
        }
     }
     
     public static void destroy( MBeanServer pServer, String pName ) {
        Logger lLog = Logger.getLogger( JNDI.class );
        try {
           // Find the Object to be destroyed
           ObjectName lSearch = new ObjectName(
              J2EEManagedObject.getDomainName() + ":type=JDBCDriver,name=" + pName + 
",*"
           );
           ObjectName lJNDI = (ObjectName) pServer.queryNames(
              lSearch,
              null
           ).iterator().next();
           // Now remove the J2EEApplication
           pServer.unregisterMBean( lJNDI );
        }
        catch( Exception e ) {
  //AS         lLog.error( "Could not destroy JSR-77 JNDI: " + pName, e );
        }
     }
     
     // Constructors --------------------------------------------------
     
     /**
     * @param pName Name of the JDBCDataSource
     *
     * @throws InvalidParameterException If list of nodes or ports was null or empty
     **/
     public JDBCDriver( String pName, ObjectName pServer )
        throws
           MalformedObjectNameException,
           InvalidParentException
     {
        super( "JDBCDriver", pName, pServer );
     }
     
     // Public --------------------------------------------------------
     
     // org.jboss.ServiceMBean overrides ------------------------------------
     
     // java.lang.Object overrides ------------------------------------
     
     public String toString() {
        return "JDBCDriver { " + super.toString() + " } [ " +
           " ]";
     }
     
     // Package protected ---------------------------------------------
     
     // Protected -----------------------------------------------------
     
     // Private -------------------------------------------------------
     
     // Inner classes -------------------------------------------------
     
  }
  
  
  
  1.1                  jboss/src/main/org/jboss/management/j2ee/JDBCDriverMBean.java
  
  Index: JDBCDriverMBean.java
  ===================================================================
  /*
   * JBoss, the OpenSource J2EE webOS
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */
  package org.jboss.management.j2ee;
  
  import javax.management.j2ee.JDBCDriver;
  
  /**
   * MBean Mangement Inteface for {@link org.jboss.management.j2ee.JDBCDriver
   * JDBCDriver}.
   *
   * @author  <a href="mailto:[EMAIL PROTECTED]";>Andreas Schaefer</a>.
   * @version $Revision: 1.1 $
   *   
   * <p><b>Revisions:</b>
   *
   * <p><b>20011206 Andreas Schaefer:</b>
   * <ul>
   * <li> Creation
   * </ul>
   **/
  public interface JDBCDriverMBean
     extends JDBCDriver, J2EEManagedObjectMBean
  {
  }
  
  
  
  1.1                  jboss/src/main/org/jboss/management/j2ee/JDBCMBean.java
  
  Index: JDBCMBean.java
  ===================================================================
  /*
   * JBoss, the OpenSource J2EE webOS
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */
  package org.jboss.management.j2ee;
  
  import javax.management.j2ee.JDBC;
  import javax.management.j2ee.StateManageable;
  
  /**
   * MBean Mangement Inteface for {@link org.jboss.management.j2ee.JDBC
   * JDBC}.
   *
   * @author  <a href="mailto:[EMAIL PROTECTED]";>Andreas Schaefer</a>.
   * @version $Revision: 1.1 $
   *   
   * <p><b>Revisions:</b>
   *
   * <p><b>20011206 Andreas Schaefer:</b>
   * <ul>
   * <li> Creation
   * </ul>
   **/
  public interface JDBCMBean
     extends JDBC, StateManageable, J2EEManagedObjectMBean
  {
  }
  
  
  

_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to