9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package sun.tools.jconsole.inspector; 27 28 import javax.swing.*; 29 import javax.swing.event.*; 30 import javax.swing.table.*; 31 import javax.swing.tree.*; 32 import java.awt.BorderLayout; 33 import java.awt.GridLayout; 34 import java.awt.FlowLayout; 35 import java.awt.Component; 36 import java.awt.event.*; 37 import java.util.*; 38 import java.io.*; 39 40 import javax.management.*; 41 42 import sun.tools.jconsole.Resources; 43 import sun.tools.jconsole.MBeansTab; 44 import sun.tools.jconsole.JConsole; 45 46 public abstract class XOperations extends JPanel implements ActionListener { 47 48 public final static String OPERATION_INVOCATION_EVENT = 49 "jam.xoperations.invoke.result"; 50 private java.util.List<NotificationListener> notificationListenersList; 51 private Hashtable<JButton, OperationEntry> operationEntryTable; 52 private XMBean mbean; 53 private MBeanInfo mbeanInfo; 54 private MBeansTab mbeansTab; 55 56 public XOperations(MBeansTab mbeansTab) { 57 super(new GridLayout(1, 1)); 58 this.mbeansTab = mbeansTab; 59 operationEntryTable = new Hashtable<JButton, OperationEntry>(); 60 ArrayList<NotificationListener> l = 61 new ArrayList<NotificationListener>(1); 62 notificationListenersList = 63 Collections.synchronizedList(l); 64 } 65 168 final OperationEntry entryIf = operationEntryTable.get(button); 169 new SwingWorker<Object, Void>() { 170 @Override 171 public Object doInBackground() throws Exception { 172 return mbean.invoke(button.getText(), 173 entryIf.getParameters(), entryIf.getSignature()); 174 } 175 @Override 176 protected void done() { 177 try { 178 Object result = get(); 179 // sends result notification to upper level if 180 // there is a return value 181 if (entryIf.getReturnType() != null && 182 !entryIf.getReturnType().equals(Void.TYPE.getName()) && 183 !entryIf.getReturnType().equals(Void.class.getName())) { 184 fireChangedNotification(OPERATION_INVOCATION_EVENT, button, result); 185 } else { 186 new ThreadDialog( 187 button, 188 Resources.getText("Method successfully invoked"), 189 Resources.getText("Info"), 190 JOptionPane.INFORMATION_MESSAGE).run(); 191 } 192 } catch (Throwable t) { 193 t = Utils.getActualException(t); 194 if (JConsole.isDebug()) { 195 t.printStackTrace(); 196 } 197 new ThreadDialog( 198 button, 199 Resources.getText("Problem invoking") + " " + 200 button.getText() + " : " + t.toString(), 201 Resources.getText("Error"), 202 JOptionPane.ERROR_MESSAGE).run(); 203 } 204 } 205 }.execute(); 206 } 207 208 public void addOperationsListener(NotificationListener nl) { 209 notificationListenersList.add(nl); 210 } 211 212 public void removeOperationsListener(NotificationListener nl) { 213 notificationListenersList.remove(nl); 214 } 215 216 // Call on EDT 217 private void fireChangedNotification( 218 String type, Object source, Object handback) { 219 Notification n = new Notification(type, source, 0); 220 for (NotificationListener nl : notificationListenersList) { 221 nl.handleNotification(n, handback); | 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package sun.tools.jconsole.inspector; 27 28 import javax.swing.*; 29 import java.awt.BorderLayout; 30 import java.awt.GridLayout; 31 import java.awt.FlowLayout; 32 import java.awt.Component; 33 import java.awt.event.*; 34 import java.util.*; 35 36 import javax.management.*; 37 38 import sun.tools.jconsole.MBeansTab; 39 import sun.tools.jconsole.JConsole; 40 import sun.tools.jconsole.resources.Messages; 41 42 @SuppressWarnings("serial") 43 public abstract class XOperations extends JPanel implements ActionListener { 44 45 public final static String OPERATION_INVOCATION_EVENT = 46 "jam.xoperations.invoke.result"; 47 private java.util.List<NotificationListener> notificationListenersList; 48 private Hashtable<JButton, OperationEntry> operationEntryTable; 49 private XMBean mbean; 50 private MBeanInfo mbeanInfo; 51 private MBeansTab mbeansTab; 52 53 public XOperations(MBeansTab mbeansTab) { 54 super(new GridLayout(1, 1)); 55 this.mbeansTab = mbeansTab; 56 operationEntryTable = new Hashtable<JButton, OperationEntry>(); 57 ArrayList<NotificationListener> l = 58 new ArrayList<NotificationListener>(1); 59 notificationListenersList = 60 Collections.synchronizedList(l); 61 } 62 165 final OperationEntry entryIf = operationEntryTable.get(button); 166 new SwingWorker<Object, Void>() { 167 @Override 168 public Object doInBackground() throws Exception { 169 return mbean.invoke(button.getText(), 170 entryIf.getParameters(), entryIf.getSignature()); 171 } 172 @Override 173 protected void done() { 174 try { 175 Object result = get(); 176 // sends result notification to upper level if 177 // there is a return value 178 if (entryIf.getReturnType() != null && 179 !entryIf.getReturnType().equals(Void.TYPE.getName()) && 180 !entryIf.getReturnType().equals(Void.class.getName())) { 181 fireChangedNotification(OPERATION_INVOCATION_EVENT, button, result); 182 } else { 183 new ThreadDialog( 184 button, 185 Messages.METHOD_SUCCESSFULLY_INVOKED, 186 Messages.INFO, 187 JOptionPane.INFORMATION_MESSAGE).run(); 188 } 189 } catch (Throwable t) { 190 t = Utils.getActualException(t); 191 if (JConsole.isDebug()) { 192 t.printStackTrace(); 193 } 194 new ThreadDialog( 195 button, 196 Messages.PROBLEM_INVOKING + " " + 197 button.getText() + " : " + t.toString(), 198 Messages.ERROR, 199 JOptionPane.ERROR_MESSAGE).run(); 200 } 201 } 202 }.execute(); 203 } 204 205 public void addOperationsListener(NotificationListener nl) { 206 notificationListenersList.add(nl); 207 } 208 209 public void removeOperationsListener(NotificationListener nl) { 210 notificationListenersList.remove(nl); 211 } 212 213 // Call on EDT 214 private void fireChangedNotification( 215 String type, Object source, Object handback) { 216 Notification n = new Notification(type, source, 0); 217 for (NotificationListener nl : notificationListenersList) { 218 nl.handleNotification(n, handback); |