my dog learned polymorphism*
The moose likes Java in General and the fly likes JMX Example (Need to improve my application) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "JMX Example (Need to improve my application) " Watch "JMX Example (Need to improve my application) " New topic
Author

JMX Example (Need to improve my application)

bobby, morkos
Ranch Hand

Joined: Jan 04, 2002
Posts: 82
I have created a JMX Application in Swing and I'm sharing my work with others. You only need to download the JMX API and the standard java API (J.D.K 1.3). If anyone want to improve on my work, please do so and post the changes. This is a beginning point to JMX and there's some work needed. Please post the bugs and any added functionality. If you want to receive my entire project, please email me and I will be glad to send you a copy.
<code>
import BaseAgent.*;
import javax.swing.JFrame;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.event.*;
import javax.swing.tree.*;
import javax.swing.*;
import javax.swing.table.*;
import java.awt.*;
import java.util.*;
import java.util.ArrayList;
import java.io.*;
import java.net.*;
import java.text.DateFormat;
// RI imports
import javax.management.ObjectName;
import javax.management.MBeanServer;
import javax.management.MBeanServerFactory;
import javax.management.MalformedObjectNameException;
import javax.management.*;
import com.sun.management.jmx.Trace;
import com.sun.jdmk.comm.HtmlAdaptorServer;
public class Filter extends JFrame implements TreeSelectionListener {
private Image background;
private static int widthVar;
private static int heightVar;
private static int count = 0;
private static String MBeanAttribute;
private static int ss =0;
private static int jj = 0;
private static MBeanServer server = null;
private static ObjectName objName = null;
private static String propertyName[];
private static String propertyView[];
private static String attrDescription;
private static JTable table;
private static JTable table2;
private JScrollPane scrollPane;
AbstractTableModel model;
private static JTable tbl1;
static final String LABEL_TEXT = "<html><FONT SIZE=+1 COLOR=blue>" +
"Agent View </FONT>";
private static Map data;
private static int in;
ArrayList listName = new ArrayList(); // Create an empty ArrayList
ArrayList listType = new ArrayList(); // Create an empty ArrayList
ArrayList listValue = new ArrayList(); // Create an empty ArrayList
ArrayList listAccess = new ArrayList(); // Create an empty ArrayList
ArrayList listDescription = new ArrayList(); // Create an empty ArrayList
private static Object arrayName[];
private static Object arrayType[];
private static Object arrayValue[];
private static Object arrayAccess[];
private static Object arrayDescription[];

public Filter() {
super("Newtrade Application");
initComponents();
pack();
}
public static MBeanServer getMBeanServer() {
return server;
}
public static void initServer() {
// CREATE the MBeanServer
System.out.println("\n\tCREATE the MBeanServer.");
server = MBeanServerFactory.createMBeanServer();
//action = 1;
// CREATE and START a new HTML adaptor
System.out.println("\n\tCREATE, REGISTER and START a new HTML adaptor:");
HtmlAdaptorServer html = new HtmlAdaptorServer();
ObjectName html_name = null;
ObjectName simDyn = null;
ObjectName myTh = null;
try {
//html_name = new ObjectName("Adaptor:name=html,port=8082");
//System.out.println("\tOBJECT NAME = " + html_name);
//server.registerMBean(html, html_name);
simDyn = new ObjectName("Mounira:state=myState, nbChanges=0");
server.registerMBean(new SimpleDynamic(), simDyn);
myTh = new ObjectName("Robert:state=myState, nbChanges=1");
server.registerMBean(new SimpleDynamic(), myTh);
myTh = new ObjectName("Ali:state=newState, nbChanges=2");
server.registerMBean(new SimpleDynamic(), myTh);
} catch(Exception e) {
System.out.println("\t!!! Could not create the HTML adaptor !!!");
e.printStackTrace();
return;
}
html.start();
}
public String MBeanInfo(String name){
// Retrieve an MBean Info
ObjectName objName = null;
MBeanInfo manipulatedObj = null;
try {
objName = new ObjectName(name);
}
catch(MalformedObjectNameException e) {
}
try {
manipulatedObj = server.getMBeanInfo(objName);
} catch(InstanceNotFoundException instancenotfoundexception) {
}
catch(IntrospectionException e) {
}
catch(ReflectionException e) {
}
// class Name
String className = manipulatedObj.getClassName();
//System.out.println("MBean className : "+ className);
return className;
}

public String MBeanDescription(String name){
// Retrieve an MBean Info
ObjectName objName = null;
MBeanInfo manipulatedObj = null;
try {
objName = new ObjectName(name);
}
catch(MalformedObjectNameException e) {
}
try {
manipulatedObj = server.getMBeanInfo(objName);
} catch(InstanceNotFoundException instancenotfoundexception) {
}
catch(IntrospectionException e) {
}
catch(ReflectionException e) {
}
// description
String description = manipulatedObj.getDescription();
//System.out.println("MBean description : "+ description);
return description;
}

public String MBeanAttributes(String name){
// Retrieve an MBean Info
MBeanInfo manipulatedObj = null;
try {
objName = new ObjectName(name);
}
catch(MalformedObjectNameException e) {
}
try {
manipulatedObj = server.getMBeanInfo(objName);
} catch(InstanceNotFoundException instancenotfoundexception) {
}
catch(IntrospectionException e) {
}
catch(ReflectionException e) {
}
// attributes
MBeanAttributeInfo attinfo[] = manipulatedObj.getAttributes();
// No attributes
if(attinfo.length == 0) {
System.out.println("No Attributes");
}
else {
String propertyName[] = new String[attinfo.length];
String propertyView[] = new String[attinfo.length];
for(ss = attinfo.length - 1; ss >= 0; ss--) {
propertyName[ss] = attinfo[ss].getName();
//System.out.println("attribute name "+ propertyName[ss]);
String attrType = usualType(attinfo[ss].getType());
String attrTypes = (attrType + " ");
String stype = attrTypes.substring(10, 25);
String read = "null";
if (attinfo[ss].isReadable()){
read = "R";
} else {
read = "";
}
String write = "null";
if (attinfo[ss].isWritable()){
write = "W";
} else {
write = "";
}
propertyView[ss] = getStringValue(objName, attinfo[ss]);
String attrDescription = attinfo[ss].getDescription();
Attributes att = new Attributes();
att.Name = propertyName[ss];
att.Type = stype.trim();
att.Value = propertyView[ss];
att.Access = read + write;
att.Description = attrDescription;
listName.add(att.Name);
listType.add(att.Type);
listValue.add(att.Value);
listAccess.add(att.Access);
listDescription.add(att.Description);
}
arrayName = listName.toArray(); // Convert into a simple array
arrayType = listType.toArray(); // Convert into a simple array
arrayValue = listValue.toArray(); // Convert into a simple array
arrayAccess = listAccess.toArray(); // Convert into a simple array
arrayDescription = listDescription.toArray(); // Convert into a simple array
}
return "null";
}
public void UpdateAttributes(String AttributeName, String oldState, String newState){
// Retrieve an MBean Info
MBeanInfo manipulatedObj = null;
try {
objName = new ObjectName(AttributeName);
}
catch(MalformedObjectNameException e) {
}
try {
manipulatedObj = server.getMBeanInfo(objName);
} catch(InstanceNotFoundException instancenotfoundexception) {
}
catch(IntrospectionException e) {
}
catch(ReflectionException e) {
}
// update attributes
AttributeList attributelist1 = null;
AttributeList attributelist = new AttributeList();
// this function replaces the old attribute state for a new state
Attribute attribute = new Attribute(oldState, newState);
// this adds the attribute to the attribute list
attributelist.add(attribute);
try {
// executed after a click on apply
attributelist1 = server.setAttributes(objName, attributelist);
}
catch(InstanceNotFoundException instancenotfoundexception) {
}
catch(ReflectionException reflectionexception) {
}
catch(JMRuntimeException jmruntimeexception) {
}
// check that the State has been updated
MBeanAttributeInfo attinfo1[] = manipulatedObj.getAttributes();
for(int i = attinfo1.length - 1; i >= 0; i--) {
String view = getStringValue(objName, attinfo1[i]);
System.out.println("attr view "+ view);
}
}
private static String usualType(String s)
{
String s1 = "";
if(s == null)
return null;
if(s.startsWith("[Z"))
s = "boolean[]";
if(s.startsWith("[C"))
s = "char[]";
if(s.startsWith("[D"))
s = "double[]";
if(s.startsWith("[F"))
s = "float[]";
if(s.startsWith("[I"))
s = "int[]";
if(s.startsWith("[S"))
s = "short[]";
if(s.startsWith("[J"))
s = "long[]";
if(s.startsWith("[B"))
s = "byte[]";
if(s.startsWith("[L"))
{
s1 = "[]";
s = s.substring(2, s.length() - 1);
}
return s + s1;
}
private static String getStringValue(ObjectName objectname, MBeanAttributeInfo mbeanattributeinfo)
{
Object obj = null;
boolean flag = mbeanattributeinfo.isReadable();
boolean flag1 = mbeanattributeinfo.isWritable();
try {
if(flag)
obj = server.getAttribute(objectname, mbeanattributeinfo.getName());
} catch(Exception exception) {
}
if(obj == null)
return new String("");
else if(obj instanceof Date) {
DateFormat dateformat = DateFormat.getDateTimeInstance(1, 1);
dateformat.setTimeZone(TimeZone.getDefault());
return dateformat.format((Date)obj);
}
else
return obj.toString();
}
private void initComponents() {
pnlMain1 = new javax.swing.JPanel();
pnlTop1 = new javax.swing.JPanel();
pnlMainTree = new javax.swing.JPanel();
pnlTopTree = new javax.swing.JPanel();
pnlBottomLeft = new javax.swing.JPanel();
pnlBottomRight = new javax.swing.JPanel();
pnlMessage = new javax.swing.JPanel();
lblHeader = new javax.swing.JLabel();
lblFilter = new javax.swing.JLabel();
txtFilter = new javax.swing.JTextField("", 25);
btnSearch = new javax.swing.JButton();
btnCancel = new javax.swing.JButton();
lblMessage = new javax.swing.JLabel();
lblMBeanName = new javax.swing.JLabel();
txtMBeanName = new javax.swing.JTextField("", 30);
lblMBeanJavaClass = new javax.swing.JLabel();
txtMBeanJavaClass = new javax.swing.JTextField("", 30);
lblReload = new javax.swing.JLabel();
txtReload = new javax.swing.JTextField("0", 7);
btnReload = new javax.swing.JButton();
btnUnregister = new javax.swing.JButton();
lblMBeanTitle = new javax.swing.JLabel();
txtMbeanDescription = new javax.swing.JTextField("0", 30);
lblEmpty = new javax.swing.JLabel();
btnView = new javax.swing.JButton();
pnlTop1.setBackground(java.awt.Color.white);
pnlMessage.setBackground(java.awt.Color.white);
lblMessage.setText("This agent is registered on the domain DefaultDomain. ");
btnSearch.setForeground(java.awt.Color.blue);
btnCancel.setForeground(java.awt.Color.blue);
lblFilter.setText(" Filter by object name: ");
btnCancel.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnCancelActionPerformed(evt);
}
});
btnSearch.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnSearchActionPerformed(evt);
}
});
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent evt) {
exitForm(evt);
}
});
background = getToolkit().getImage( "C:/working/JMX/Directory/images/email_sign.gif" );
try {
MediaTracker tracker = new MediaTracker(this);
tracker.addImage(background, 0);
tracker.waitForID(0);
} catch( Exception e ){}
String text = LABEL_TEXT;
lblHeader.setText(text);
pnlMain1.add(lblHeader);
pnlTop1.add(lblFilter);
pnlTop1.add(txtFilter);
pnlMessage.add(lblMessage);
btnSearch.setText("Search");
pnlTop1.add(btnSearch);
btnCancel.setText("Cancel");
pnlTop1.add(btnCancel);
// Place the buttons in the tabbing order
txtFilter.setNextFocusableComponent(btnSearch);
btnSearch.setNextFocusableComponent(btnCancel);
btnCancel.setNextFocusableComponent(txtFilter);
getContentPane().setLayout(new GridBagLayout());
GridBagConstraints c=new GridBagConstraints();
c.fill = GridBagConstraints.BOTH;
c.gridwidth = GridBagConstraints.RELATIVE;
c.gridx=0; c.gridy=0;
getContentPane().add(pnlMain1, c);
c.gridwidth = GridBagConstraints.RELATIVE;
c.gridx=0; c.gridy=1;
getContentPane().add(pnlTop1, c);
c.gridx=0; c.gridy=2;
getContentPane().add(pnlMessage, c);
c.gridwidth = GridBagConstraints.RELATIVE;
JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, new JScrollPane(createTreePanel()), new JScrollPane(createTextPanel()));
splitPane.setDividerLocation(225);
splitPane.setOneTouchExpandable(true);
c.gridx=0; c.gridy=3;
getContentPane().add(splitPane, c);
pack();
}
private JPanel createTreePanel() {
JPanel treePanel = new JPanel();
treePanel.removeAll();
treePanel.setLayout(new BorderLayout());
pnlBottomLeft.setMinimumSize(new Dimension(0,50));
treePanel.add(new JScrollPane(pnlBottomLeft), BorderLayout.CENTER);
treePanel.setBorder(BorderFactory.createTitledBorder(
" List of registered MBeans by domain: ")
);
treePanel.setMinimumSize(new Dimension(0,250));
return treePanel;
}
private JPanel createTextPanel() {
JPanel textPanel = new JPanel();
lblMBeanName.setText("MBean Name: ");
lblMBeanJavaClass.setText("MBean Java Class:");
lblReload.setText("Reload Period in seconds: ");
lblMBeanTitle.setText("MBean description:");
txtMbeanDescription.setText("");
lblEmpty.setText(" ");
btnReload.setText("Reload");
btnReload.setForeground(Color.blue);
btnUnregister.setText("Unregister");
btnUnregister.setForeground(Color.blue);
btnView.setText("View");
btnView.setForeground(Color.blue);
JButton btnDisplay = new JButton();
btnDisplay.setText("Send");
btnDisplay.setForeground(Color.blue);
btnView.addActionListener(
new ActionListener() {
public void actionPerformed( ActionEvent ae ) {
//table.getCellEditor().stopCellEditing();
// contimue from here
Filter dd = new Filter();
dd.MBeanAttributes(txtMBeanName.getText());
if(arrayName.length == 1){
model = new AbstractTableModel() {
Object data[][] = {
{ arrayName[0], arrayType[0], arrayAccess[0],
arrayValue[0], arrayDescription[0]},
};
String columnNames[] = { "Name", "Type", "Access", "Value", "Description" };
public int getRowCount() {
return data.length;
}
public int getColumnCount() {
return data[0].length;
}
public Object getValueAt(int row, int col) {
return data[row][col];
}
public String getColumnName(int columnIndex) {
return columnNames[columnIndex];
}
public Class getColumnClass(int columnIndex) {
return data[0][columnIndex].getClass();
}
public boolean isCellEditable(int rowIndex, int columnIndex) {
return columnIndex == 3;
}
public void setValueAt(Object value, int rowIndex, int columnIndex) {
if (value instanceof Boolean && columnIndex == 1) {
data[rowIndex][columnIndex] = value;
fireTableCellUpdated(rowIndex, columnIndex);
}
}
};
} //end if
if(arrayName.length == 2){
model = new AbstractTableModel() {
Object data[][] = {
{ arrayName[0], arrayType[0], arrayAccess[0],
arrayValue[0], arrayDescription[0]},
{ arrayName[1], arrayType[1], arrayAccess[1],
arrayValue[1], arrayDescription[1]},
};
String columnNames[] = { "Name", "Type", "Access", "Value", "Description" };
public int getRowCount() {
return data.length;
}
public int getColumnCount() {
return data[0].length;
}
public Object getValueAt(int row, int col) {
return data[row][col];
}
public String getColumnName(int columnIndex) {
return columnNames[columnIndex];
}
public Class getColumnClass(int columnIndex) {
return data[0][columnIndex].getClass();
}
public boolean isCellEditable(int rowIndex, int columnIndex) {
return columnIndex == 3;
}
public void setValueAt(Object value, int rowIndex, int columnIndex) {
if (value instanceof Boolean && columnIndex == 1) {
data[rowIndex][columnIndex] = value;
fireTableCellUpdated(rowIndex, columnIndex);
}
}
};
} //end if
if(arrayName.length == 3){
model = new AbstractTableModel() {
Object data[][] = {
{ arrayName[0], arrayType[0], arrayAccess[0],
arrayValue[0], arrayDescription[0]},
{ arrayName[1], arrayType[1], arrayAccess[1],
arrayValue[1], arrayDescription[1]},
{ arrayName[2], arrayType[2], arrayAccess[2],
arrayValue[2], arrayDescription[2]},
};
String columnNames[] = { "Name", "Type", "Access", "Value", "Description" };
public int getRowCount() {
return data.length;
}
public int getColumnCount() {
return data[0].length;
}
public Object getValueAt(int row, int col) {
return data[row][col];
}
public String getColumnName(int columnIndex) {
return columnNames[columnIndex];
}
public Class getColumnClass(int columnIndex) {
return data[0][columnIndex].getClass();
}
public boolean isCellEditable(int rowIndex, int columnIndex) {
return columnIndex == 3;
}
public void setValueAt(Object value, int rowIndex, int columnIndex) {
if (value instanceof Boolean && columnIndex == 1) {
data[rowIndex][columnIndex] = value;
fireTableCellUpdated(rowIndex, columnIndex);
}
}
};
} //end if
if(arrayName.length == 4){
model = new AbstractTableModel() {
Object data[][] = {
{ arrayName[0], arrayType[0], arrayAccess[0],
arrayValue[0], arrayDescription[0]},
{ arrayName[1], arrayType[1], arrayAccess[1],
arrayValue[1], arrayDescription[1]},
{ arrayName[2], arrayType[2], arrayAccess[2],
arrayValue[2], arrayDescription[2]},
{ arrayName[3], arrayType[3], arrayAccess[3],
arrayValue[3], arrayDescription[3]},
};
String columnNames[] = { "Name", "Type", "Access", "Value", "Description" };
public int getRowCount() {
return data.length;
}
public int getColumnCount() {
return data[0].length;
}
public Object getValueAt(int row, int col) {
return data[row][col];
}
public String getColumnName(int columnIndex) {
return columnNames[columnIndex];
}
public Class getColumnClass(int columnIndex) {
return data[0][columnIndex].getClass();
}
public boolean isCellEditable(int rowIndex, int columnIndex) {
return columnIndex == 3;
}
public void setValueAt(Object value, int rowIndex, int columnIndex) {
if (value instanceof Boolean && columnIndex == 1) {
data[rowIndex][columnIndex] = value;
fireTableCellUpdated(rowIndex, columnIndex);
}
}
};
} //end if
if(arrayName.length == 5){
model = new AbstractTableModel() {
Object data[][] = {
{ arrayName[0], arrayType[0], arrayAccess[0],
arrayValue[0], arrayDescription[0]},
{ arrayName[1], arrayType[1], arrayAccess[1],
arrayValue[1], arrayDescription[1]},
{ arrayName[2], arrayType[2], arrayAccess[2],
arrayValue[2], arrayDescription[2]},
{ arrayName[3], arrayType[3], arrayAccess[3],
arrayValue[3], arrayDescription[3]},
{ arrayName[4], arrayType[4], arrayAccess[4],
arrayValue[4], arrayDescription[4]},
};
String columnNames[] = { "Name", "Type", "Access", "Value", "Description" };
public int getRowCount() {
return data.length;
}
public int getColumnCount() {
return data[0].length;
}
public Object getValueAt(int row, int col) {
return data[row][col];
}
public String getColumnName(int columnIndex) {
return columnNames[columnIndex];
}
public Class getColumnClass(int columnIndex) {
return data[0][columnIndex].getClass();
}
public boolean isCellEditable(int rowIndex, int columnIndex) {
return columnIndex == 3;
}
public void setValueAt(Object value, int rowIndex, int columnIndex) {
if (value instanceof Boolean && columnIndex == 1) {
data[rowIndex][columnIndex] = value;
fireTableCellUpdated(rowIndex, columnIndex);
}
}
};
} //end if
if(arrayName.length == 6){
model = new AbstractTableModel() {
Object data[][] = {
{ arrayName[0], arrayType[0], arrayAccess[0],
arrayValue[0], arrayDescription[0]},
{ arrayName[1], arrayType[1], arrayAccess[1],
arrayValue[1], arrayDescription[1]},
{ arrayName[2], arrayType[2], arrayAccess[2],
arrayValue[2], arrayDescription[2]},
{ arrayName[3], arrayType[3], arrayAccess[3],
arrayValue[3], arrayDescription[3]},
{ arrayName[4], arrayType[4], arrayAccess[4],
arrayValue[4], arrayDescription[4]},
{ arrayName[5], arrayType[5], arrayAccess[5],
arrayValue[5], arrayDescription[5]},
};
String columnNames[] = { "Name", "Type", "Access", "Value", "Description" };
public int getRowCount() {
return data.length;
}
public int getColumnCount() {
return data[0].length;
}
public Object getValueAt(int row, int col) {
return data[row][col];
}
public String getColumnName(int columnIndex) {
return columnNames[columnIndex];
}
public Class getColumnClass(int columnIndex) {
return data[0][columnIndex].getClass();
}
public boolean isCellEditable(int rowIndex, int columnIndex) {
return columnIndex == 3;
}
public void setValueAt(Object value, int rowIndex, int columnIndex) {
if (value instanceof Boolean && columnIndex == 1) {
data[rowIndex][columnIndex] = value;
fireTableCellUpdated(rowIndex, columnIndex);
}
}
};
} //end if
if(arrayName.length == 7){
model = new AbstractTableModel() {
Object data[][] = {
{ arrayName[0], arrayType[0], arrayAccess[0],
arrayValue[0], arrayDescription[0]},
{ arrayName[1], arrayType[1], arrayAccess[1],
arrayValue[1], arrayDescription[1]},
{ arrayName[2], arrayType[2], arrayAccess[2],
arrayValue[2], arrayDescription[2]},
{ arrayName[3], arrayType[3], arrayAccess[3],
arrayValue[3], arrayDescription[3]},
{ arrayName[4], arrayType[4], arrayAccess[4],
arrayValue[4], arrayDescription[4]},
{ arrayName[5], arrayType[5], arrayAccess[5],
arrayValue[5], arrayDescription[5]},
{ arrayName[6], arrayType[6], arrayAccess[6],
arrayValue[6], arrayDescription[6]},
};
String columnNames[] = { "Name", "Type", "Access", "Value", "Description" };
public int getRowCount() {
return data.length;
}
public int getColumnCount() {
return data[0].length;
}
public Object getValueAt(int row, int col) {
return data[row][col];
}
public String getColumnName(int columnIndex) {
return columnNames[columnIndex];
}
public Class getColumnClass(int columnIndex) {
return data[0][columnIndex].getClass();
}
public boolean isCellEditable(int rowIndex, int columnIndex) {
return columnIndex == 3;
}
public void setValueAt(Object value, int rowIndex, int columnIndex) {
if (value instanceof Boolean && columnIndex == 1) {
data[rowIndex][columnIndex] = value;
fireTableCellUpdated(rowIndex, columnIndex);
}
}
};
} //end if
if(arrayName.length == 8){
model = new AbstractTableModel() {
Object data[][] = {
{ arrayName[0], arrayType[0], arrayAccess[0],
arrayValue[0], arrayDescription[0]},
{ arrayName[1], arrayType[1], arrayAccess[1],
arrayValue[1], arrayDescription[1]},
{ arrayName[2], arrayType[2], arrayAccess[2],
arrayValue[2], arrayDescription[2]},
{ arrayName[3], arrayType[3], arrayAccess[3],
arrayValue[3], arrayDescription[3]},
{ arrayName[4], arrayType[4], arrayAccess[4],
arrayValue[4], arrayDescription[4]},
{ arrayName[5], arrayType[5], arrayAccess[5],
arrayValue[5], arrayDescription[5]},
{ arrayName[6], arrayType[6], arrayAccess[6],
arrayValue[6], arrayDescription[6]},
{ arrayName[7], arrayType[7], arrayAccess[7],
arrayValue[7], arrayDescription[7]},
};
String columnNames[] = { "Name", "Type", "Access", "Value", "Description" };
public int getRowCount() {
return data.length;
}
public int getColumnCount() {
return data[0].length;
}
public Object getValueAt(int row, int col) {
return data[row][col];
}
public String getColumnName(int columnIndex) {
return columnNames[columnIndex];
}
public Class getColumnClass(int columnIndex) {
return data[0][columnIndex].getClass();
}
public boolean isCellEditable(int rowIndex, int columnIndex) {
return columnIndex == 3;
}
public void setValueAt(Object value, int rowIndex, int columnIndex) {
if (value instanceof Boolean && columnIndex == 1) {
data[rowIndex][columnIndex] = value;
fireTableCellUpdated(rowIndex, columnIndex);
}
}
};
} //end if
if(arrayName.length == 9){
model = new AbstractTableModel() {
Object data[][] = {
{ arrayName[0], arrayType[0], arrayAccess[0],
arrayValue[0], arrayDescription[0]},
{ arrayName[1], arrayType[1], arrayAccess[1],
arrayValue[1], arrayDescription[1]},
{ arrayName[2], arrayType[2], arrayAccess[2],
arrayValue[2], arrayDescription[2]},
{ arrayName[3], arrayType[3], arrayAccess[3],
arrayValue[3], arrayDescription[3]},
{ arrayName[4], arrayType[4], arrayAccess[4],
arrayValue[4], arrayDescription[4]},
{ arrayName[5], arrayType[5], arrayAccess[5],
arrayValue[5], arrayDescription[5]},
{ arrayName[6], arrayType[6], arrayAccess[6],
arrayValue[6], arrayDescription[6]},
{ arrayName[7], arrayType[7], arrayAccess[7],
arrayValue[7], arrayDescription[7]},
{ arrayName[8], arrayType[8], arrayAccess[8],
arrayValue[8], arrayDescription[8]},
};
String columnNames[] = { "Name", "Type", "Access", "Value", "Description" };
public int getRowCount() {
return data.length;
}
public int getColumnCount() {
return data[0].length;
}
public Object getValueAt(int row, int col) {
return data[row][col];
}
public String getColumnName(int columnIndex) {
return columnNames[columnIndex];
}
public Class getColumnClass(int columnIndex) {
return data[0][columnIndex].getClass();
}
public boolean isCellEditable(int rowIndex, int columnIndex) {
return columnIndex == 3;
}
public void setValueAt(Object value, int rowIndex, int columnIndex) {
if (value instanceof Boolean && columnIndex == 1) {
data[rowIndex][columnIndex] = value;
fireTableCellUpdated(rowIndex, columnIndex);
}
}
};
} //end if
if(arrayName.length == 10){
model = new AbstractTableModel() {
Object data[][] = {
{ arrayName[0], arrayType[0], arrayAccess[0],
arrayValue[0], arrayDescription[0]},
{ arrayName[1], arrayType[1], arrayAccess[1],
arrayValue[1], arrayDescription[1]},
{ arrayName[2], arrayType[2], arrayAccess[2],
arrayValue[2], arrayDescription[2]},
{ arrayName[3], arrayType[3], arrayAccess[3],
arrayValue[3], arrayDescription[3]},
{ arrayName[4], arrayType[4], arrayAccess[4],
arrayValue[4], arrayDescription[4]},
{ arrayName[5], arrayType[5], arrayAccess[5],
arrayValue[5], arrayDescription[5]},
{ arrayName[6], arrayType[6], arrayAccess[6],
arrayValue[6], arrayDescription[6]},
{ arrayName[7], arrayType[7], arrayAccess[7],
arrayValue[7], arrayDescription[7]},
{ arrayName[8], arrayType[8], arrayAccess[8],
arrayValue[8], arrayDescription[8]},
{ arrayName[9], arrayType[9], arrayAccess[9],
arrayValue[9], arrayDescription[9]},
};
String columnNames[] = { "Name", "Type", "Access", "Value", "Description" };
public int getRowCount() {
return data.length;
}
public int getColumnCount() {
return data[0].length;
}
public Object getValueAt(int row, int col) {
return data[row][col];
}
public String getColumnName(int columnIndex) {
return columnNames[columnIndex];
}
public Class getColumnClass(int columnIndex) {
return data[0][columnIndex].getClass();
}
public boolean isCellEditable(int rowIndex, int columnIndex) {
return columnIndex == 3;
}
public void setValueAt(Object value, int rowIndex, int columnIndex) {
if (value instanceof Boolean && columnIndex == 1) {
data[rowIndex][columnIndex] = value;
fireTableCellUpdated(rowIndex, columnIndex);
}
}
};
} //end if

tbl1 = new JTable(model);
tablePanel.removeAll();
tablePanel.add(new JScrollPane(tbl1));
tablePanel.updateUI();
}
});

btnDisplay.addActionListener(
new ActionListener() {
public void actionPerformed( ActionEvent ae ) {
try {
Filter f = new Filter();
String MBeanAttributes = f.MBeanAttributes(txtMBeanName.getText());
// Update Attribute (testing only)
//f.UpdateAttributes("nbChanges", "0", "incremental");
// System.out.println("Object Update Name: "+ );
f.UpdateAttributes((""+txtMBeanName.getText()),"State", "Robert State" );
//System.out.println("txtMBeanName.getText().trim() >>" + txtMBeanName.getText());
} catch (Exception e){ e.printStackTrace();}
//Display Table information
for( int row = 0; row < tbl1.getRowCount(); ++row ) {
for( int col = 0; col < tbl1.getColumnCount(); ++col ) {
data = new HashMap();
data.put("1", tbl1.getValueAt( row, col ));
System.out.println( " "+ data.values());
}
System.out.println( " " );
}
}
});
txtMBeanName.setEditable(false);
txtMBeanJavaClass.setEditable(false);
txtMbeanDescription.setEditable(false);
textPanel.setLayout(new GridBagLayout());
GridBagConstraints c=new GridBagConstraints();
c.gridwidth = GridBagConstraints.RELATIVE;
JPanel pnlBeanName= new JPanel();
pnlBeanName.add(lblMBeanName);
pnlBeanName.add(txtMBeanName);
c.gridx=1; c.gridy=0;
textPanel.add(pnlBeanName, c);
JPanel pnlBeanJavaClass= new JPanel();
pnlBeanJavaClass.add(lblMBeanJavaClass);
pnlBeanJavaClass.add(txtMBeanJavaClass);
c.gridx=1; c.gridy=1;
textPanel.add(pnlBeanJavaClass, c);
JPanel pnlBeanReload= new JPanel();
pnlBeanReload.add(lblReload);
pnlBeanReload.add(txtReload);
pnlBeanReload.add(btnReload);
pnlBeanReload.add(btnUnregister);
c.gridx=1; c.gridy=2;
textPanel.add(pnlBeanReload, c);
JPanel pnlMBeanTitle= new JPanel();
pnlMBeanTitle.add(lblMBeanTitle);
pnlMBeanTitle.add(txtMbeanDescription);
c.gridx=1; c.gridy=3;
textPanel.add(pnlMBeanTitle, c);
tableView = new JPanel();
JLabel inv = new JLabel();
inv.setText("<html><FONT SIZE=+1 COLOR=blue>Attributes</FONT>");
c.gridx=1; c.gridy=5;
textPanel.add(inv, c);
tablePanel = new JPanel();
Object tabledata[][] = {
};
String columnheaders[] = { "Name", "Type", "Access", "Value", "Description" };
table = new JTable(tabledata, columnheaders){
public boolean isCellEditable(int row,int column) {
if ( column == 0 || column == 1 || column == 2 ){
return false;
} else {
return true;
}
}
};
// whenever the model changes, the columns get resized...
table.setAutoCreateColumnsFromModel(false);
table.setRowSelectionAllowed( true );
table.setSelectionForeground( Color.blue );
table.setSelectionBackground( Color.yellow );
table.setSelectionMode(0);
tablePanel.add( new JScrollPane( table ) );
tableView.add( tablePanel, BorderLayout.NORTH);
JPanel pnlViewButton = new JPanel();
pnlViewButton.setLayout(new GridBagLayout());
GridBagConstraints m = new GridBagConstraints();
m.gridx=0; m.gridy=0;
pnlViewButton.add(btnView, m);
m.fill = GridBagConstraints.BOTH;
m.gridwidth = GridBagConstraints.RELATIVE;
m.gridx=0; m.gridy=1;
pnlViewButton.add(btnDisplay, m);
// JButton btnMore = new JButton();
// btnMore.setText("More");
// m.gridx=0; m.gridy=2;
// pnlViewButton.add(btnMore, m);

tableView.add(pnlViewButton, BorderLayout.SOUTH);
c.gridx=1; c.gridy=6;
c.gridheight=8; c.gridwidth=15;
textPanel.add(tableView, c);
textPanel.setBorder(
BorderFactory.createTitledBorder(" MBean View: "));
textPanel.setMinimumSize(new Dimension(0,300));
return textPanel;
}
public void treeEvent(String tree) {
if(tree.charAt(0) == ' '){
txtMBeanName.setText("");
txtMBeanJavaClass.setText("");
txtMbeanDescription.setText("");
} else {
txtMBeanName.setText(tree);
String InfoClass = this.MBeanInfo(tree);
txtMBeanJavaClass.setText(InfoClass);
String MBeanDescription = this.MBeanDescription(tree);
txtMbeanDescription.setText(MBeanDescription);
// to continue from here
//String MBeanAttributes = this.MBeanAttributes(tree);
}
}
public void valueChanged (TreeSelectionEvent event) {
TreePath path = event.getPath();
Object elements[] = path.getPath();
Filter.this.treeEvent("" + path.getLastPathComponent());
}
private void btnSearchActionPerformed(java.awt.event.ActionEvent evt) {
// Parse system properties to check if LEVEL_TRACE and/or LEVEL_DEBUG are set
// and enable the TRACE level accordingly
try {
Trace.parseTraceProperties();
}
catch (IOException e) {
e.printStackTrace();
}
try {
Filter.initServer();
objName = new ObjectName(txtFilter.getText().trim() + ":*");
java.util.Set set = server.queryMBeans(objName, null);
java.util.Set setName = server.queryNames(objName, null);
count = set.size();
Iterator names = setName.iterator();
DefaultMutableTreeNode newtradeComponent = new DefaultMutableTreeNode(" Newtrade ");
DefaultMutableTreeNode[] theTreeNodes = new DefaultMutableTreeNode[count];
DefaultMutableTreeNode[] styles = new DefaultMutableTreeNode[count];

while (names.hasNext()){
ObjectName name = (ObjectName)names.next();
String values = name.toString();
StringTokenizer st = new StringTokenizer(values, ":");
if(st.hasMoreTokens()) {
int ss=(jj++);
String param1 = st.nextToken();
theTreeNodes[ss] = new DefaultMutableTreeNode(" " + param1);
styles[ss] = new DefaultMutableTreeNode(param1 + ":" + st.nextToken());
newtradeComponent.add(theTreeNodes[ss]);
theTreeNodes[ss].add(styles[ss]);
}
TreeSelectionListener listener = this;
TreePanel tp = new TreePanel(newtradeComponent, listener);

pnlBottomLeft.removeAll();
pnlBottomLeft.remove(tp);
pnlBottomLeft.add(tp);
pnlBottomLeft.updateUI();
}
}
catch(Exception e){ }
lblMessage.setText("This page contains " + count + " MBean(s).");
}
private void btnCancelActionPerformed(java.awt.event.ActionEvent evt) {
//create the yes/no dialog:
int n = JOptionPane.showConfirmDialog(this, "Are you sure you want to exit?", "Newtrade", JOptionPane.YES_NO_OPTION);
if (n == JOptionPane.YES_OPTION) {
System.exit(0);
} else if (n == JOptionPane.NO_OPTION) { }
}
private void exitForm(java.awt.event.WindowEvent evt) {
System.exit(0);
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
Filter mv = new Filter();
mv.initServer();
Dimension dd = Toolkit.getDefaultToolkit().getScreenSize ();
mv.show();
mv.setBounds(0, 0, dd.width, dd.height);
mv.setVisible (true);
mv.setBackground(java.awt.Color.white);
}
public void paint(Graphics g) {
super.paint(g);
// g.drawImage( background, 105, 7, null );
}
// Variables declaration
private javax.swing.JPanel pnlMain1;
private javax.swing.JPanel pnlTop1;
private javax.swing.JPanel pnlMainTree;
private javax.swing.JPanel pnlTopTree;
private javax.swing.JPanel pnlMessage;
private javax.swing.JLabel lblMessage;
private javax.swing.JPanel pnlBottomLeft;
private javax.swing.JPanel pnlBottomRight;
private javax.swing.JPanel tableView;
private javax.swing.JPanel tablePanel;
private javax.swing.JLabel lblHeader;
private javax.swing.JLabel lblFilter;
private javax.swing.JTextField txtFilter;
private javax.swing.JButton btnSearch;
private javax.swing.JButton btnCancel;
private javax.swing.JLabel lblMBeanName;
private javax.swing.JLabel lblMBeanJavaClass;
private javax.swing.JTextField txtMBeanName;
private javax.swing.JTextField txtMBeanJavaClass;
private javax.swing.JLabel lblReload;
private javax.swing.JTextField txtReload;
private javax.swing.JButton btnReload;
private javax.swing.JButton btnUnregister;
private javax.swing.JLabel lblMBeanTitle;
private javax.swing.JTextField txtMbeanDescription;
private javax.swing.JLabel lblEmpty;
private javax.swing.JButton btnView;
// Variables declaration
// Inner Class [store data]
class Attributes {
String Name;
String Type;
String Access;
String Value;
String Description;
}
// End Inner Class

}
</code>
Mandan Happy
Ranch Hand

Joined: Dec 17, 2001
Posts: 65
Dear Bobby,
I would definitely be interested . I havent gone thru your code yet. I would like to know the purpose of the Swing Application. Does it provides only a GUI or would act as a Manager embedding any Adaptors stubs?
Also FYI u can contribute to www.sourceforge.net/projects/openjmx
Thanks
Mandan
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JMX Example (Need to improve my application)
 
Similar Threads
Displaying ArrayList data in a JTable
JTable Dynamic - Urgent
jtable not displayed
AbstractTreeModel Cannot insert rows correctly
JTable problem