1 package org.sape.carbon.services.console; 2 3 import java.awt.Component ; 4 import java.util.Iterator ; 5 import java.util.TreeMap ; 6 7 import javax.management.MBeanAttributeInfo ; 8 import javax.management.MBeanInfo ; 9 import javax.management.MBeanNotificationInfo ; 10 import javax.management.MBeanOperationInfo ; 11 import javax.management.MBeanServer ; 12 import javax.management.ObjectName ; 13 import javax.swing.BoxLayout ; 14 import javax.swing.JInternalFrame ; 15 import javax.swing.JPanel ; 16 import javax.swing.JScrollPane ; 17 18 import org.sape.carbon.core.exception.ExceptionUtility; 19 20 21 30 public class MBeanFrame extends JInternalFrame { 31 32 MBeanServer server; 33 ObjectName objectName; 34 MBeanInfo info; 35 36 37 public MBeanFrame(MBeanServer server, ObjectName objectName) { 38 39 try { 40 this.server = server; 41 this.objectName = objectName; 42 this.info = server.getMBeanInfo(this.objectName); 43 } catch (Exception e) { 44 e.printStackTrace(); 45 } 46 47 this.setTitle(this.objectName.getCanonicalName()); 48 initComponents(); 49 this.serverLabelValue.setText("?"); this.nameLabelValue.setText(this.objectName.toString()); 51 this.descriptionValue.setText(this.info.getDescription()); 52 53 54 try { 55 56 Class componentClass; 57 try { 58 componentClass = (Class ) server.invoke(this.objectName,"getClass",new Object [] {}, new String [] {}); 61 } catch (Exception e) { 62 componentClass = Class.forName(this.info.getClassName(),true,this.getClass().getClassLoader()); 64 } 65 66 72 addProfileTab("Managed Bean"); 73 } catch (Exception e) { 74 SingletonExceptionViewer.getInstance().addException(e); 75 } 76 } 77 78 79 private void addProfileTab(String name) { 80 MBeanProfilePanel profilePane = new MBeanProfilePanel(); 81 82 83 Component attrPane = addProfileAttributes(); 84 profilePane.addTab(attrPane, "Attributes"); 85 86 87 JScrollPane operPane = addProfileOperations(); 88 profilePane.addTab(operPane, "Operations"); 89 90 JScrollPane notifPane = addNotifications(); 91 profilePane.addTab(notifPane, "Notification"); 92 93 94 this.profileTabPane.add(profilePane,name); } 96 97 98 private JScrollPane addNotifications() { 99 JScrollPane notifPanel = newPanel(); 100 MBeanNotificationInfo [] notifs = this.info.getNotifications(); 101 for (int i = 0; i < notifs.length; i++) { 102 try { 103 NotificationPanel notificationPanel = 104 new NotificationPanel( 105 this.objectName, 106 notifs[i], 107 this.server); 108 109 ((JPanel )notifPanel.getViewport().getView()).add(notificationPanel); 110 } catch (Exception e) { 111 System.out.println(ExceptionUtility.printStackTracesToString(e)); 112 } 113 } 114 return notifPanel; 115 } 116 117 118 private AttributesPanel addProfileAttributes() { 119 121 AttributesPanel attrPane = new AttributesPanel(this.objectName,this.server); 122 MBeanAttributeInfo [] attrs = this.info.getAttributes(); 123 TreeMap map = new TreeMap (); 124 for (int i = 0; i < attrs.length; i++) { 125 map.put(attrs[i].getName(), attrs[i]); 126 } 127 128 Iterator attributes = map.values().iterator(); 129 while (attributes.hasNext()) { 130 MBeanAttributeInfo attributeInfo = 131 (MBeanAttributeInfo ) attributes.next(); 132 try { 133 134 Object value = this.server.getAttribute(this.objectName, attributeInfo.getName()); 135 AttributePanel attrPanel = new AttributePanel( 136 this.objectName, attributeInfo, this.server); 137 138 139 attrPane.addRow(attrPanel); 140 } catch (Exception e) { 141 System.out.println(ExceptionUtility.printStackTracesToString(e)); 142 } 143 } 144 return attrPane; 145 } 146 147 private JScrollPane addProfileOperations() { 148 JScrollPane operPane = newPanel(); 149 MBeanOperationInfo [] opers = this.info.getOperations(); 150 for (int i = 0; i < opers.length; i++) { 151 try { 152 OperationPanel operationPanel = 154 new OperationPanel( 155 this.objectName, 156 opers[i], 157 this.server); 158 159 ((JPanel )operPane.getViewport().getView()).add(operationPanel); 160 } catch (Exception e) { 161 System.out.println(ExceptionUtility.printStackTracesToString(e)); 162 } 163 } 164 return operPane; 165 } 166 167 private static JScrollPane newPanel() { 168 JPanel panel = new JPanel (); 169 BoxLayout layout = new BoxLayout (panel,BoxLayout.Y_AXIS); 170 panel.setLayout(layout); 171 JScrollPane scrollPane = new JScrollPane (); 172 scrollPane.setViewportView(panel); 173 return scrollPane; 175 } 176 177 private static String shortClassName(Class theClass) { 178 String className = theClass.getName(); 179 return className.substring(className.lastIndexOf('.') + 1); 180 } 181 182 187 private void initComponents() { java.awt.GridBagConstraints gridBagConstraints; 189 190 headerPanel = new javax.swing.JPanel (); 191 nameLabel = new javax.swing.JLabel (); 192 nameLabelValue = new javax.swing.JLabel (); 193 descriptionLabel = new javax.swing.JLabel (); 194 descriptionValue = new javax.swing.JTextArea (); 195 serverLabel = new javax.swing.JLabel (); 196 serverLabelValue = new javax.swing.JLabel (); 197 statusBarPanel = new javax.swing.JPanel (); 198 jLabel1 = new javax.swing.JLabel (); 199 tabAndButtonPanel = new javax.swing.JPanel (); 200 profileTabPane = new javax.swing.JTabbedPane (); 201 202 setBackground(new java.awt.Color (255, 255, 255)); 203 setClosable(true); 204 setIconifiable(true); 205 setMaximizable(true); 206 setResizable(true); 207 setDoubleBuffered(true); 208 headerPanel.setLayout(new java.awt.GridBagLayout ()); 209 210 headerPanel.setBackground(new java.awt.Color (204, 204, 204)); 211 headerPanel.setBorder(new javax.swing.border.BevelBorder (javax.swing.border.BevelBorder.RAISED)); 212 nameLabel.setText("Name"); 213 gridBagConstraints = new java.awt.GridBagConstraints (); 214 gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST; 215 gridBagConstraints.insets = new java.awt.Insets (3, 3, 3, 3); 216 headerPanel.add(nameLabel, gridBagConstraints); 217 218 nameLabelValue.setFont(new java.awt.Font ("Dialog", 0, 12)); 219 nameLabelValue.setText("component name"); 220 gridBagConstraints = new java.awt.GridBagConstraints (); 221 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 222 gridBagConstraints.insets = new java.awt.Insets (3, 3, 3, 3); 223 headerPanel.add(nameLabelValue, gridBagConstraints); 224 225 descriptionLabel.setText("Description"); 226 gridBagConstraints = new java.awt.GridBagConstraints (); 227 gridBagConstraints.gridx = 0; 228 gridBagConstraints.gridy = 2; 229 gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST; 230 gridBagConstraints.insets = new java.awt.Insets (3, 3, 3, 3); 231 headerPanel.add(descriptionLabel, gridBagConstraints); 232 233 descriptionValue.setBackground(new java.awt.Color (204, 204, 204)); 234 descriptionValue.setEditable(false); 235 descriptionValue.setLineWrap(true); 236 descriptionValue.setText("The description value..."); 237 descriptionValue.setWrapStyleWord(true); 238 descriptionValue.setOpaque(false); 239 gridBagConstraints = new java.awt.GridBagConstraints (); 240 gridBagConstraints.gridx = 1; 241 gridBagConstraints.gridy = 2; 242 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 243 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 244 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 245 gridBagConstraints.weightx = 1.0; 246 gridBagConstraints.insets = new java.awt.Insets (3, 3, 3, 3); 247 headerPanel.add(descriptionValue, gridBagConstraints); 248 249 serverLabel.setText("Server"); 250 gridBagConstraints = new java.awt.GridBagConstraints (); 251 gridBagConstraints.gridx = 0; 252 gridBagConstraints.gridy = 1; 253 gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST; 254 gridBagConstraints.insets = new java.awt.Insets (3, 3, 3, 3); 255 headerPanel.add(serverLabel, gridBagConstraints); 256 257 serverLabelValue.setFont(new java.awt.Font ("Dialog", 0, 12)); 258 serverLabelValue.setText("server name"); 259 gridBagConstraints = new java.awt.GridBagConstraints (); 260 gridBagConstraints.gridx = 1; 261 gridBagConstraints.gridy = 1; 262 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 263 gridBagConstraints.insets = new java.awt.Insets (3, 3, 3, 3); 264 headerPanel.add(serverLabelValue, gridBagConstraints); 265 266 getContentPane().add(headerPanel, java.awt.BorderLayout.NORTH); 267 268 statusBarPanel.setLayout(new java.awt.BorderLayout ()); 269 270 statusBarPanel.setBorder(new javax.swing.border.CompoundBorder (new javax.swing.border.SoftBevelBorder (javax.swing.border.BevelBorder.RAISED), new javax.swing.border.SoftBevelBorder (javax.swing.border.BevelBorder.LOWERED))); 271 jLabel1.setFont(new java.awt.Font ("Dialog", 0, 12)); 272 jLabel1.setText("Status bar..."); 273 jLabel1.setToolTipText(""); 274 statusBarPanel.add(jLabel1, java.awt.BorderLayout.CENTER); 275 276 getContentPane().add(statusBarPanel, java.awt.BorderLayout.SOUTH); 277 278 tabAndButtonPanel.setLayout(new java.awt.BorderLayout ()); 279 280 profileTabPane.setBackground(new java.awt.Color (255, 255, 255)); 281 tabAndButtonPanel.add(profileTabPane, java.awt.BorderLayout.CENTER); 282 283 getContentPane().add(tabAndButtonPanel, java.awt.BorderLayout.CENTER); 284 285 setBounds(0, 0, 587, 427); 286 } 288 289 private javax.swing.JLabel jLabel1; 291 private javax.swing.JLabel serverLabel; 292 private javax.swing.JLabel nameLabel; 293 private javax.swing.JPanel headerPanel; 294 private javax.swing.JPanel tabAndButtonPanel; 295 private javax.swing.JLabel descriptionLabel; 296 private javax.swing.JLabel serverLabelValue; 297 private javax.swing.JLabel nameLabelValue; 298 private javax.swing.JTabbedPane profileTabPane; 299 private javax.swing.JTextArea descriptionValue; 300 private javax.swing.JPanel statusBarPanel; 301 303 } 304 | Popular Tags |