User: andreas 
  Date: 00/11/23 12:56:15

  Modified:    examples/jboss.admin/src/org/jboss/jBossAdmin
                        RemoteResource.java RemoteServer.java
  Added:       examples/jboss.admin/src/org/jboss/jBossAdmin
                        RemoteAttribute.java RemoteFeature.java
  Log:
  The jBoss Admin GUI now lists all the remote MBeans,
  the detail pane shows all the attributes and operations
  and it contains a list of attributes in the left hand tree.
  
  Revision  Changes    Path
  1.2       +119 -40   
ejx/examples/jboss.admin/src/org/jboss/jBossAdmin/RemoteResource.java
  
  Index: RemoteResource.java
  ===================================================================
  RCS file: 
/products/cvs/ejboss/ejx/examples/jboss.admin/src/org/jboss/jBossAdmin/RemoteResource.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- RemoteResource.java       2000/11/19 23:28:58     1.1
  +++ RemoteResource.java       2000/11/23 20:56:14     1.2
  @@ -1,6 +1,8 @@
   /*
  - * Copyright 1999 by dreamBean Software,
  - * All rights reserved.
  + * jBoss, the OpenSource EJB server
  + *
  + * Distributable under GPL license.
  + * See terms of license at gnu.org.
    */
   package org.jboss.jBossAdmin;
   
  @@ -11,9 +13,18 @@
   import java.util.*;
   import java.lang.reflect.*;
   
  +import javax.management.MBeanInfo;
  +import javax.management.MBeanAttributeInfo;
  +import javax.management.MBeanOperationInfo;
   import javax.management.ObjectInstance;
   import javax.management.ObjectName;
   
  +import javax.swing.JComponent;
  +import javax.swing.JLabel;
  +import javax.swing.JPanel;
  +import javax.swing.JScrollPane;
  +import javax.swing.JTextField;
  +
   import com.dreambean.awt.BeanContextViewer;
   import com.dreambean.awt.GenericCustomizer;
   import com.dreambean.ejx.Util;
  @@ -24,7 +35,7 @@
   *   <description> 
   *      
   * @author <A href="mailto:[EMAIL PROTECTED]">Andreas "Mad" Schaefer</A>
  -* @version $Revision: 1.1 $
  +* @version $Revision: 1.2 $
   **/
   public class RemoteResource
       extends BeanContextSupport
  @@ -37,6 +48,7 @@
       private ObjectInstance mService;
       
       private Customizer c;
  +     private JComponent mViewer;
       
       // Static --------------------------------------------------------
       
  @@ -46,36 +58,20 @@
       public void setReference( JMXConnector pConnector, ObjectInstance pReference ) {
                mConnector = pConnector;
           mService = pReference;
  +             try {
  +                     MBeanInfo lBean = mConnector.getMBeanInfo(
  +                             mService.getObjectName()
  +                     );
  +                     MBeanAttributeInfo[] lAttributes = lBean.getAttributes();
  +                     for( int i = 0; i < lAttributes.length; i++ ) {
  +                             createAttribute( lAttributes[ i ] );
  +                     }
  +             }
  +             catch( Exception e ) {
  +                     e.printStackTrace();
  +             }
       }
   
  -     public String getName() {
  -        String lName = "";
  -        try {
  -            lName = (String) mConnector.getAttribute(
  -                     mService.getObjectName(),
  -                     "Name"
  -                 );
  -        }
  -        catch( Exception e ) {
  -            e.printStackTrace();
  -        }
  -        return lName;
  -     }
  -     
  -     public String getDescription() {
  -        String lDescription = "";
  -        try {
  -            lDescription = (String) mConnector.getAttribute(
  -                mService.getObjectName(),
  -                "Description"
  -            );
  -        }
  -        catch( Exception e ) {
  -            e.printStackTrace();
  -        }
  -        return lDescription;
  -     }
  -
       public String toString() {
           return ( mService == null ? "" : mService.getObjectName().toString() );
       }
  @@ -93,15 +89,27 @@
                throw new IllegalArgumentException("No such bean");
        }
   */
  +    
  +    public void createAttribute( MBeanAttributeInfo pFeature )
  +        throws IOException, ClassNotFoundException
  +    {
  +        System.out.println( "Create new Feature: " + pFeature.getName() );
  +        addAttribute().setReference( mConnector, mService, pFeature );
  +    }
   
  +    public RemoteAttribute addAttribute()
  +        throws IOException, ClassNotFoundException
  +    {
  +        return (RemoteAttribute) instantiateChild( 
"org.jboss.jBossAdmin.RemoteAttribute" );
  +    }
  +
       public Iterator iterator() {
           return Util.sortByClass( super.iterator() );
       }
  -/*    
  -    public Iterator getServices() {
  -        return Util.getChildrenByClass( super.iterator(), RemoteService.class );
  +    
  +    public Iterator getAttributes() {
  +        return Util.getChildrenByClass( super.iterator(), RemoteAttribute.class );
       }
  -*/
       
      /**
       *   This is a wizard-style method that tries to find all CMP-fields in 
EntityBeans.
  @@ -204,18 +212,89 @@
      
       // BeanContextContainerProxy implementation -----------------
       public Component getComponent() {
  +/*
           if( c == null ) {
               c = new GenericCustomizer();
               c.setObject( this );
           }
           return (Component) c;
  +*/
  +             if( mViewer == null ) {
  +                     mViewer = new JScrollPane(
  +                             new Viewer()
  +                     );
  +             }
  +             return mViewer;
       }
  -    
  -   // Package protected ---------------------------------------------
       
  -   // Protected -----------------------------------------------------
  -    
  -   // Private -------------------------------------------------------
  +     // Package protected ---------------------------------------------
  +     
  +     // Protected -----------------------------------------------------
  +     
  +     // Private -------------------------------------------------------
  +     
  +     // Inner classes -------------------------------------------------
  +     public class Viewer
  +             extends JPanel
  +     {
  +             public Viewer() {
  +                     setLayout( new GridLayout( 0, 2 ) );
  +                     try {
  +                             MBeanInfo lBean = mConnector.getMBeanInfo(
  +                                     mService.getObjectName()
  +                             );
  +                             Iterator k = getAttributes();
  +                             while( k.hasNext() ) {
  +                                     MBeanAttributeInfo lAttribute = ( 
(RemoteAttribute) k.next() ).getInfo();
  +                                     add( new JLabel( lAttribute.getName() ) );
  +                                     if( lAttribute.isReadable() ) {
  +                                             if( lAttribute.isWritable() ) {
  +                                                     add(
  +                                                             new JTextField(
  +                                                                     
mConnector.getAttribute(
  +                                                                             
mService.getObjectName(),
  +                                                                             
lAttribute.getName()
  +                                                                     ) + ""
  +                                                             )
  +                                                     );
  +                                             }
  +                                             else {
  +                                                     add(
  +                                                             new JLabel(
  +                                                                     
mConnector.getAttribute(
  +                                                                             
mService.getObjectName(),
  +                                                                             
lAttribute.getName()
  +                                                                     ) + ""
  +                                                             )
  +                                                     );
  +                                             }
  +                                     }
  +                                     else {
  +                                             if( lAttribute.isWritable() ) {
  +                                                     add(
  +                                                             new JTextField( "" )
  +                                                     );
  +                                             }
  +                                     }
  +                             }
  +                             MBeanOperationInfo[] lOperations = 
lBean.getOperations();
  +                             for( int i = 0; i < lOperations.length; i++ ) {
  +                                     add(
  +                                             new JLabel(
  +                                                     lOperations[ i ].getName()
  +                                             )
  +                                     );
  +                                     add(
  +                                             new JLabel(
  +                                                     lOperations[ i 
].getDescription()
  +                                             )
  +                                     );
  +                             }
  +                     }
  +                     catch( Exception e ) {
  +                             e.printStackTrace();
  +                     }
  +             }
  +     }
   
  -   // Inner classes -------------------------------------------------
   }
  
  
  
  1.2       +4 -2      
ejx/examples/jboss.admin/src/org/jboss/jBossAdmin/RemoteServer.java
  
  Index: RemoteServer.java
  ===================================================================
  RCS file: 
/products/cvs/ejboss/ejx/examples/jboss.admin/src/org/jboss/jBossAdmin/RemoteServer.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- RemoteServer.java 2000/11/19 23:28:58     1.1
  +++ RemoteServer.java 2000/11/23 20:56:14     1.2
  @@ -1,6 +1,8 @@
   /*
  - * Copyright 1999 by dreamBean Software,
  - * All rights reserved.
  + * jBoss, the OpenSource EJB server
  + *
  + * Distributable under GPL license.
  + * See terms of license at gnu.org.
    */
   package org.jboss.jBossAdmin;
   
  @@ -22,7 +24,7 @@
   *   <description> 
   *      
   * @author <A href="mailto:[EMAIL PROTECTED]">Andreas "Mad" Schaefer</A>
  -* @version $Revision: 1.1 $
  +* @version $Revision: 1.2 $
   **/
   public class RemoteServer
       extends BeanContextSupport
  
  
  
  1.1                  
ejx/examples/jboss.admin/src/org/jboss/jBossAdmin/RemoteAttribute.java
  
  Index: RemoteAttribute.java
  ===================================================================
  /*
   * jBoss, the OpenSource EJB server
   *
   * Distributable under GPL license.
   * See terms of license at gnu.org.
   */
  package org.jboss.jBossAdmin;
  
  import java.awt.*;
  import java.beans.*;
  import java.beans.beancontext.*;
  import java.io.*;
  import java.util.*;
  import java.lang.reflect.*;
  
  import javax.management.MBeanInfo;
  import javax.management.MBeanAttributeInfo;
  import javax.management.MBeanOperationInfo;
  import javax.management.ObjectInstance;
  import javax.management.ObjectName;
  
  import javax.swing.JComponent;
  import javax.swing.JLabel;
  import javax.swing.JPanel;
  import javax.swing.JScrollPane;
  import javax.swing.JTextField;
  
  import com.dreambean.awt.BeanContextViewer;
  import com.dreambean.awt.GenericCustomizer;
  import com.dreambean.ejx.Util;
  
  import org.jboss.jmx.interfaces.JMXConnector;
  
  /**
  *   <description> 
  *      
  * @author <A href="mailto:[EMAIL PROTECTED]">Andreas "Mad" Schaefer</A>
  * @version $Revision: 1.1 $
  **/
  public class RemoteAttribute
      extends RemoteFeature
  {
      // Constants -----------------------------------------------------
      
      // Attributes ----------------------------------------------------
        private JMXConnector mConnector;
      private ObjectInstance mService;
        private MBeanAttributeInfo mInfo;
      
      private Customizer c;
        private JComponent mViewer;
      
      // Static --------------------------------------------------------
      
      // Constructors --------------------------------------------------
      
      // Public --------------------------------------------------------
      public void setReference( JMXConnector pConnector, ObjectInstance pReference, 
MBeanAttributeInfo pInfo ) {
                mConnector = pConnector;
          mService = pReference;
                mInfo = pInfo;
      }
        
        public MBeanAttributeInfo getInfo() {
                return mInfo;
        }
  
      public String toString() {
          return ( mInfo == null ? "" : mInfo.getName() );
      }
  
      public Iterator iterator() {
          return Util.sortByClass( super.iterator() );
      }
  
      // BeanContextContainerProxy implementation -----------------
      public Component getComponent() {
                if( mViewer == null ) {
                        mViewer = new JScrollPane(
                                new Viewer()
                        );
                }
                return mViewer;
      }
      
        // Package protected ---------------------------------------------
        
        // Protected -----------------------------------------------------
        
        // Private -------------------------------------------------------
        
        // Inner classes -------------------------------------------------
        public class Viewer
                extends JPanel
        {
                public Viewer() {
                        setLayout( new GridLayout( 0, 2 ) );
                        try {
                                add(
                                        new JLabel(
                                                mInfo.getName()
                                        )
                                );
                                add(
                                        new JLabel(
                                                mInfo.getDescription()
                                        )
                                );
                                add(
                                        new JLabel(
                                                mConnector.getAttribute(
                                                        mService.getObjectName(),
                                                        mInfo.getName()
                                                ) + ""
                                        )
                                );
                        }
                        catch( Exception e ) {
                                e.printStackTrace();
                        }
                }
        }
  
  }
  
  
  
  1.1                  
ejx/examples/jboss.admin/src/org/jboss/jBossAdmin/RemoteFeature.java
  
  Index: RemoteFeature.java
  ===================================================================
  /*
   * jBoss, the OpenSource EJB server
   *
   * Distributable under GPL license.
   * See terms of license at gnu.org.
   */
  package org.jboss.jBossAdmin;
  
  import java.awt.*;
  import java.beans.*;
  import java.beans.beancontext.*;
  import java.io.*;
  import java.util.*;
  import java.lang.reflect.*;
  
  import com.dreambean.awt.BeanContextViewer;
  import com.dreambean.awt.GenericCustomizer;
  
  import com.dreambean.ejx.Util;
  
  /**
  *   <description> 
  *      
  * @author <A href="mailto:[EMAIL PROTECTED]">Andreas "Mad" Schaefer</A>
  * @version $Revision: 1.1 $
  **/
  public abstract class RemoteFeature
      extends BeanContextSupport
      implements BeanContextChildComponentProxy
  {
      // Constants -----------------------------------------------------
      
      // Attributes ----------------------------------------------------
      
      // Static --------------------------------------------------------
      
      // Constructors --------------------------------------------------
      
      // Public --------------------------------------------------------
      public Iterator iterator() {
          return Util.sortByClass( super.iterator() );
      }
  
        // Package protected ---------------------------------------------
        
        // Protected -----------------------------------------------------
        
        // Private -------------------------------------------------------
        
        // Inner classes -------------------------------------------------
  }
  
  
  

Reply via email to