User: andreas
Date: 00/11/28 09:29:26
Modified: examples/jboss.admin/src/org/jboss/jBossAdmin
GenericMBeanCustomizer.java RemoteAttribute.java
RemoteFeature.java RemoteResource.java
RemoteServer.java
Log:
Cosmetic changes to the remote Service overview page
and the attribute page.
Revision Changes Path
1.2 +143 -76
ejx/examples/jboss.admin/src/org/jboss/jBossAdmin/GenericMBeanCustomizer.java
Index: GenericMBeanCustomizer.java
===================================================================
RCS file:
/products/cvs/ejboss/ejx/examples/jboss.admin/src/org/jboss/jBossAdmin/GenericMBeanCustomizer.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- GenericMBeanCustomizer.java 2000/11/25 22:23:31 1.1
+++ GenericMBeanCustomizer.java 2000/11/28 17:29:24 1.2
@@ -49,22 +49,17 @@
import org.jboss.jmx.interfaces.JMXConnector;
/**
- * Generic JavaBean customizer. It creates property editors for all properties and
buttons for all methods.
- * Create a BeanInfo class for the JavaBean that you want to be able to customize
for maximum control over the
- * appearance of the customizer.
- * The GenericCustomizer has one extension to the standard JavaBeans behavior: if
a propertyeditor implements BeanContextProxy
- * the GenericCustomizer will add it to a beancontext method so that the
propertyeditor can use that contextual info to customize itself.
- * For example, the legal values of a property might depend on which object is
being edited.
- * The object being edited is made available as a BeanContext service /w the class
of the object. This allows the propertyeditors to extract
- * dynamic info for customization.
- *
- * @author Rickard �berg ([EMAIL PROTECTED])
- * @created November 24, 2000
- * @version $Revision: 1.1 $
- */
+* Generic MBean customizer to create a GUI to show and edit all the attributes
+* and invoke all operations offered by the MBean through the given JMX Connector.
+* In this customizer NO BeanInfo is used because it is completely dynamice because
+* of the nature of the manageable interface of the MBean.
+*
+* @author <A href="mailto:[EMAIL PROTECTED]">Andreas "Mad" Schaefer</A>
+* @version $Revision: 1.2 $
+**/
public class GenericMBeanCustomizer
- extends JScrollPane
- implements Customizer, BeanContextProxy
+ extends JScrollPane
+ implements Customizer, BeanContextProxy
{
// Attributes ----------------------------------------------------
@@ -136,75 +131,81 @@
c.anchor = GridBagConstraints.NORTH;
c.weighty = 1;
-/* AS No BeanInfo used here -> remove later
- BeanInfo info;
- if( object instanceof BeanInfo ) {
- info = ( BeanInfo ) object;
- }
- else {
- info = Introspector.getBeanInfo( object.getClass() );
- }
-*/
-
mGUI = new JPanel( new GridBagLayout() );
mGUI.setBorder( BorderFactory.createTitledBorder(
BorderFactory.createEtchedBorder(), mResource.getName().toString() ) );
addInfo( "Domain", lName.getDomain() );
addInfo( "Description", lInfo.getDescription() );
- addSubtitle( "Attributes" );
Iterator i = Arrays.asList( lInfo.getAttributes() ).iterator();
- while( i.hasNext() ) {
- MBeanAttributeInfo lFeature = (MBeanAttributeInfo)
i.next();
- String lType = lFeature.getType();
- Class lClass = null;
- if( lType.equals( "int" ) ) {
- lClass = Integer.TYPE;
- }
- else if( lType.equals( "short" ) ) {
- lClass = Short.TYPE;
- }
- else if( lType.equals( "long" ) ) {
- lClass = Long.TYPE;
- }
- else if( lType.equals( "byte" ) ) {
- lClass = Byte.TYPE;
- }
- else if( lType.equals( "char" ) ) {
- lClass = Character.TYPE;
- }
- else if( lType.equals( "float" ) ) {
- lClass = Float.TYPE;
- }
- else if( lType.equals( "double" ) ) {
- lClass = Double.TYPE;
- }
- else if( lType.equals( "boolean" ) ) {
- lClass = Boolean.TYPE;
- }
- if( lClass == null ) {
- lClass = Class.forName( lType );
+ if( i.hasNext() ) {
+ addSubtitle( "Attributes" );
+ while( i.hasNext() ) {
+ MBeanAttributeInfo lFeature =
(MBeanAttributeInfo) i.next();
+ String lType = lFeature.getType();
+ Class lClass = null;
+ if( lType.equals( "int" ) ) {
+ lClass = Integer.TYPE;
+ }
+ else if( lType.equals( "short" ) ) {
+ lClass = Short.TYPE;
+ }
+ else if( lType.equals( "long" ) ) {
+ lClass = Long.TYPE;
+ }
+ else if( lType.equals( "byte" ) ) {
+ lClass = Byte.TYPE;
+ }
+ else if( lType.equals( "char" ) ) {
+ lClass = Character.TYPE;
+ }
+ else if( lType.equals( "float" ) ) {
+ lClass = Float.TYPE;
+ }
+ else if( lType.equals( "double" ) ) {
+ lClass = Double.TYPE;
+ }
+ else if( lType.equals( "boolean" ) ) {
+ lClass = Boolean.TYPE;
+ }
+ if( lClass == null ) {
+ lClass = Class.forName( lType );
+ }
+ PropertyEditor lEditor =
PropertyEditorManager.findEditor(
+ lClass
+ );
+ System.out.println( "Got class: " + lClass +
", editor: " + lEditor );
+ // No editor is available therefore use just
one displaying the
+ // string representation and allowing no
editing
+ if( lEditor == null ) {
+ addInfo(
+ lFeature.getName(),
+
mResource.getConnector().getAttribute( mResource.getName(), lFeature.getName() ) + ""
+ );
+ }
+ else {
+ // If editor is null then is uses the
default string editor
+ addProperty( lEditor, lFeature );
+ }
}
- System.out.println( "Got class: " + lClass );
- PropertyEditor lEditor =
PropertyEditorManager.findEditor(
- lClass
- );
- // If editor is null then is uses the default string
editor
- addProperty( lEditor, lFeature );
}
- addSubtitle( "Operations" );
i = Arrays.asList( lInfo.getOperations() ).iterator();
- while( i.hasNext() ) {
- MBeanOperationInfo lFeature = (MBeanOperationInfo)
i.next();
- addMethod( lFeature );
+ if( i.hasNext() ) {
+ addSubtitle( "Operations" );
+ while( i.hasNext() ) {
+ MBeanOperationInfo lFeature =
(MBeanOperationInfo) i.next();
+ addMethod( lFeature );
+ }
}
- addSubtitle( "Notifications" );
i = Arrays.asList( lInfo.getNotifications() ).iterator();
- while( i.hasNext() ) {
- MBeanNotificationInfo lFeature =
(MBeanNotificationInfo) i.next();
- addMethod( lFeature );
+ if( i.hasNext() ) {
+ addSubtitle( "Notifications" );
+ while( i.hasNext() ) {
+ MBeanNotificationInfo lFeature =
(MBeanNotificationInfo) i.next();
+ addMethod( lFeature );
+ }
}
/* AS No BeanInfo used here -> remove later
// Properties
@@ -361,11 +362,80 @@
}
// Public --------------------------------------------------------
+ /**
+ * Add a description line to the GUI which contains by a description and
+ * its value.
+ *
+ * @param pDescription Description text
+ * @param pValue Value according to the description
+ **/
public void addInfo( String pDescription, String pValue ) {
+ GridBagConstraints c = new GridBagConstraints();
+ c.insets = new Insets( 5, 5, 5, 5 );
+ c.anchor = GridBagConstraints.NORTH;
+ c.weighty = 1;
+ c.gridwidth = GridBagConstraints.RELATIVE;
+ c.fill = GridBagConstraints.HORIZONTAL;
+ c.weightx = 0;
+ JLabel lDescription = new JLabel( pDescription + ":", JLabel.LEFT );
+ ( ( GridBagLayout ) mGUI.getLayout() ).setConstraints( lDescription, c
);
+ mGUI.add( lDescription );
+ c.gridwidth = GridBagConstraints.REMAINDER;
+ c.fill = GridBagConstraints.HORIZONTAL;
+ c.weightx = 1;
+ JLabel lValue = new JLabel( pValue, JLabel.LEFT );
+ ( ( GridBagLayout ) mGUI.getLayout() ).setConstraints( lValue, c );
+ mGUI.add( lValue );
}
+ /**
+ * Add a sub title line to the GUI
+ *
+ * @param pTitle Subtitle to be added
+ **/
public void addSubtitle( String pTitle ) {
+ JLabel lTitle = new JLabel( pTitle + ":", JLabel.LEFT );
+ GridBagConstraints c = new GridBagConstraints();
+ c.insets = new Insets( 5, 5, 5, 5 );
+ c.anchor = GridBagConstraints.NORTH;
+ c.weighty = 1;
+ c.gridwidth = GridBagConstraints.REMAINDER;
+ c.fill = GridBagConstraints.HORIZONTAL;
+ c.weightx = 0;
+ ( ( GridBagLayout ) mGUI.getLayout() ).setConstraints( lTitle, c );
+ mGUI.add( lTitle );
}
+ /**
+ * Add a method line to the GUI
+ *
+ * @param pInfo Info object of the method/notification to be displayed
+ */
public void addMethod( MBeanFeatureInfo pInfo ) {
+ GridBagConstraints c = new GridBagConstraints();
+ c.insets = new Insets( 5, 5, 5, 5 );
+ c.anchor = GridBagConstraints.NORTH;
+ c.weighty = 1;
+ c.gridwidth = GridBagConstraints.RELATIVE;
+ c.fill = GridBagConstraints.HORIZONTAL;
+ c.weightx = 0;
+ JLabel lName = new JLabel( pInfo.getName() + ":", JLabel.RIGHT );
+ ( ( GridBagLayout ) mGUI.getLayout() ).setConstraints( lName, c );
+ mGUI.add( lName );
+ c.gridwidth = GridBagConstraints.REMAINDER;
+ c.fill = GridBagConstraints.HORIZONTAL;
+ c.weightx = 1;
+ JButton lCall;
+ if( pInfo instanceof MBeanOperationInfo ) {
+ lCall = new JButton( "Invoke" );
+ }
+ else {
+ lCall = new JButton( "Register" );
+ }
+ lCall.setToolTipText( pInfo.getDescription() );
+ ( ( GridBagLayout ) mGUI.getLayout() ).setConstraints( lCall, c );
+ mGUI.add( lCall );
+ if( pInfo instanceof MBeanOperationInfo ) {
+ lCall.addActionListener( new MethodInvoker(
(MBeanOperationInfo) pInfo ) );
+ }
}
/**
@@ -458,6 +528,9 @@
c.gridwidth = GridBagConstraints.REMAINDER;
c.fill = GridBagConstraints.HORIZONTAL;
c.weightx = 1;
+ if( lEditorBean instanceof JComponent ) {
+ ( (JComponent) lEditorBean ).setToolTipText(
pInfo.getDescription() );
+ }
( ( GridBagLayout ) mGUI.getLayout() ).setConstraints( lEditorBean, c
);
mGUI.add( lEditorBean );
@@ -691,12 +764,6 @@
new String[] {}
);
}
-/* AS Deal with the MBean Exceptions and not with reflection one
- catch( InvocationTargetException ex ) {
- ex.getTargetException().printStackTrace();
- JOptionPane.showMessageDialog( lFrame,
ex.getTargetException().getMessage(), "Error", JOptionPane.ERROR_MESSAGE );
- }
-*/
catch( Exception ex ) {
System.err.println( ex );
JOptionPane.showMessageDialog( lFrame, "An
exception occured. Check log for details", "Error", JOptionPane.ERROR_MESSAGE );
1.3 +45 -10
ejx/examples/jboss.admin/src/org/jboss/jBossAdmin/RemoteAttribute.java
Index: RemoteAttribute.java
===================================================================
RCS file:
/products/cvs/ejboss/ejx/examples/jboss.admin/src/org/jboss/jBossAdmin/RemoteAttribute.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- RemoteAttribute.java 2000/11/24 07:51:42 1.2
+++ RemoteAttribute.java 2000/11/28 17:29:24 1.3
@@ -13,6 +13,7 @@
import java.util.*;
import java.lang.reflect.*;
+import javax.management.Attribute;
import javax.management.MBeanInfo;
import javax.management.MBeanAttributeInfo;
import javax.management.MBeanFeatureInfo;
@@ -37,20 +38,54 @@
* <description>
*
* @author <A href="mailto:[EMAIL PROTECTED]">Andreas "Mad" Schaefer</A>
-* @version $Revision: 1.2 $
+* @version $Revision: 1.3 $
**/
public class RemoteAttribute
- extends RemoteFeature
+ extends RemoteFeature
{
- // Constants -----------------------------------------------------
-
- // Attributes ----------------------------------------------------
-
- // Static --------------------------------------------------------
-
- // Constructors --------------------------------------------------
-
- // Public --------------------------------------------------------
+ // Constants -----------------------------------------------------
+
+ // Attributes ----------------------------------------------------
+ private Customizer mCustomizer;
+
+ // Static --------------------------------------------------------
+
+ // Constructors --------------------------------------------------
+
+ // Public --------------------------------------------------------
+ public Object getAttribute() {
+ try {
+ return mConnector.getAttribute( mService.getObjectName(),
mInfo.getName() );
+ }
+ catch( Exception e ) {
+ e.printStackTrace();
+ return "";
+ }
+ }
+
+ public void setAttribute( Object pNew ) {
+ try {
+ mConnector.setAttribute(
+ mService.getObjectName(),
+ new Attribute(
+ mInfo.getName(),
+ pNew
+ )
+ );
+ }
+ catch( Exception e ) {
+ }
+ }
+
+ // BeanContextContainerProxy implementation -----------------
+ public Component getComponent() {
+ if( mCustomizer == null ) {
+ mCustomizer = new GenericCustomizer(
+ this
+ );
+ }
+ return (Component) mCustomizer;
+ }
// Package protected ---------------------------------------------
1.3 +39 -32
ejx/examples/jboss.admin/src/org/jboss/jBossAdmin/RemoteFeature.java
Index: RemoteFeature.java
===================================================================
RCS file:
/products/cvs/ejboss/ejx/examples/jboss.admin/src/org/jboss/jBossAdmin/RemoteFeature.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- RemoteFeature.java 2000/11/24 07:51:42 1.2
+++ RemoteFeature.java 2000/11/28 17:29:24 1.3
@@ -37,55 +37,62 @@
* <description>
*
* @author <A href="mailto:[EMAIL PROTECTED]">Andreas "Mad" Schaefer</A>
-* @version $Revision: 1.2 $
+* @version $Revision: 1.3 $
**/
public class RemoteFeature
- extends BeanContextSupport
- implements BeanContextChildComponentProxy
+ extends BeanContextSupport
+ implements BeanContextChildComponentProxy
{
- // Constants -----------------------------------------------------
-
- // Attributes ----------------------------------------------------
- private JMXConnector mConnector;
- private ObjectInstance mService;
- private MBeanFeatureInfo mInfo;
-
- private Customizer c;
+ // Constants -----------------------------------------------------
+
+ // Attributes ----------------------------------------------------
+ protected JMXConnector mConnector;
+ protected ObjectInstance mService;
+ protected MBeanFeatureInfo mInfo;
+
private JComponent mViewer;
-
- // Static --------------------------------------------------------
-
- // Constructors --------------------------------------------------
-
- // Public --------------------------------------------------------
- public void setReference( JMXConnector pConnector, ObjectInstance pReference,
MBeanFeatureInfo pInfo ) {
+
+ // Static --------------------------------------------------------
+
+ // Constructors --------------------------------------------------
+
+ // Public --------------------------------------------------------
+ public void setReference( JMXConnector pConnector, ObjectInstance pReference,
MBeanFeatureInfo pInfo ) {
mConnector = pConnector;
- mService = pReference;
+ mService = pReference;
mInfo = pInfo;
- }
+ }
+
+ public String getName() {
+ return mInfo.getName();
+ }
+ public String getDescription() {
+ return mInfo.getDescription();
+ }
+
public MBeanFeatureInfo getInfo() {
return mInfo;
+ }
+
+ public String toString() {
+ return ( mInfo == null ? "" : mInfo.getName() );
+ }
+
+ public Iterator iterator() {
+ return Util.sortByClass( super.iterator() );
}
-
- public String toString() {
- return ( mInfo == null ? "" : mInfo.getName() );
- }
-
- public Iterator iterator() {
- return Util.sortByClass( super.iterator() );
- }
-
- // BeanContextContainerProxy implementation -----------------
- public Component getComponent() {
+
+ // BeanContextContainerProxy implementation -----------------
+ public Component getComponent() {
if( mViewer == null ) {
mViewer = new JScrollPane(
new Viewer()
);
}
return mViewer;
- }
-
+ }
+
// Package protected ---------------------------------------------
// Protected -----------------------------------------------------
1.5 +0 -0
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.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- RemoteResource.java 2000/11/25 22:23:31 1.4
+++ RemoteResource.java 2000/11/28 17:29:24 1.5
@@ -37,7 +37,7 @@
* <description>
*
* @author <A href="mailto:[EMAIL PROTECTED]">Andreas "Mad" Schaefer</A>
-* @version $Revision: 1.4 $
+* @version $Revision: 1.5 $
**/
public class RemoteResource
extends BeanContextSupport
1.4 +0 -0
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.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- RemoteServer.java 2000/11/24 07:51:43 1.3
+++ RemoteServer.java 2000/11/28 17:29:25 1.4
@@ -24,7 +24,7 @@
* <description>
*
* @author <A href="mailto:[EMAIL PROTECTED]">Andreas "Mad" Schaefer</A>
-* @version $Revision: 1.3 $
+* @version $Revision: 1.4 $
**/
public class RemoteServer
extends BeanContextSupport