|
1
|
|
|
|
2
|
|
|
|
3
|
|
|
|
4
|
|
|
|
5
|
|
|
|
6
|
|
|
|
7
|
|
package org.ejtools.adwt.jmx;
|
|
8
|
|
|
|
9
|
|
import java.awt.Component;
|
|
10
|
|
import java.awt.Dimension;
|
|
11
|
|
import java.awt.Frame;
|
|
12
|
|
import java.awt.GridBagConstraints;
|
|
13
|
|
import java.awt.GridBagLayout;
|
|
14
|
|
import java.awt.Insets;
|
|
15
|
|
import java.awt.event.ActionEvent;
|
|
16
|
|
import java.awt.event.ActionListener;
|
|
17
|
|
import java.beans.PropertyEditor;
|
|
18
|
|
import java.util.Arrays;
|
|
19
|
|
import java.util.Iterator;
|
|
20
|
|
import java.util.ResourceBundle;
|
|
21
|
|
import java.util.Vector;
|
|
22
|
|
|
|
23
|
|
import javax.management.MBeanOperationInfo;
|
|
24
|
|
import javax.management.MBeanParameterInfo;
|
|
25
|
|
import javax.swing.JButton;
|
|
26
|
|
import javax.swing.JDialog;
|
|
27
|
|
import javax.swing.JLabel;
|
|
28
|
|
import javax.swing.JOptionPane;
|
|
29
|
|
import javax.swing.JPanel;
|
|
30
|
|
import javax.swing.SwingConstants;
|
|
31
|
|
|
|
32
|
|
import org.ejtools.beans.CustomPropertyEditorManager;
|
|
33
|
|
import org.ejtools.jmx.MBeanInvokeAccessor;
|
|
34
|
|
import org.ejtools.util.ClassTools;
|
|
35
|
|
|
|
36
|
|
import com.dreambean.awt.GenericPropertyCustomizer;
|
|
37
|
|
|
|
38
|
|
|
|
39
|
|
|
|
40
|
|
|
|
41
|
|
|
|
42
|
|
|
|
43
|
|
|
|
44
|
|
public class MBeanMethodDialog extends JDialog implements ActionListener
|
|
45
|
|
{
|
|
46
|
|
|
|
47
|
|
private Vector editors = new Vector();
|
|
48
|
|
|
|
49
|
|
private MBeanOperationInfo operationInfo = null;
|
|
50
|
|
|
|
51
|
|
private MBeanInvokeAccessor resource = null;
|
|
52
|
|
|
|
53
|
|
private static ResourceBundle resources = ResourceBundle.getBundle("org.ejtools.adwt.jmx.Resources");
|
|
54
|
|
|
|
55
|
|
|
|
56
|
|
|
|
57
|
|
|
|
58
|
|
|
|
59
|
|
|
|
60
|
|
|
|
61
|
|
|
|
62
|
|
|
|
63
|
0
|
public MBeanMethodDialog(MBeanInvokeAccessor resource, MBeanOperationInfo operationInfo, Frame parent)
|
|
64
|
|
{
|
|
65
|
0
|
super(parent, true);
|
|
66
|
0
|
this.setTitle(resources.getString("invoke.dialog.title"));
|
|
67
|
|
|
|
68
|
|
|
|
69
|
0
|
if (resource == null)
|
|
70
|
|
{
|
|
71
|
0
|
throw new IllegalArgumentException("MBeanAccessor must be defined");
|
|
72
|
|
}
|
|
73
|
0
|
if (operationInfo == null)
|
|
74
|
|
{
|
|
75
|
0
|
throw new IllegalArgumentException("Operation must be defined");
|
|
76
|
|
}
|
|
77
|
0
|
this.resource = resource;
|
|
78
|
0
|
this.operationInfo = operationInfo;
|
|
79
|
|
|
|
80
|
0
|
JPanel panel = (JPanel) this.getContentPane();
|
|
81
|
0
|
panel.setLayout(new GridBagLayout());
|
|
82
|
|
|
|
83
|
0
|
try
|
|
84
|
|
{
|
|
85
|
0
|
GridBagConstraints constraints = new GridBagConstraints();
|
|
86
|
0
|
constraints.insets = new Insets(2, 2, 2, 2);
|
|
87
|
0
|
constraints.anchor = GridBagConstraints.NORTH;
|
|
88
|
0
|
constraints.weighty = 1.0d;
|
|
89
|
|
|
|
90
|
|
|
|
91
|
0
|
StringBuffer display = new StringBuffer();
|
|
92
|
0
|
display.append(resources.getString("invoke.dialog.text.operation") + " : ");
|
|
93
|
0
|
display.append(this.operationInfo.getName());
|
|
94
|
0
|
JLabel nameLabel = new JLabel(display.toString());
|
|
95
|
0
|
constraints.gridwidth = GridBagConstraints.REMAINDER;
|
|
96
|
0
|
panel.add(nameLabel, constraints);
|
|
97
|
|
|
|
98
|
|
|
|
99
|
0
|
Iterator i = Arrays.asList(this.operationInfo.getSignature()).iterator();
|
|
100
|
0
|
while (i.hasNext())
|
|
101
|
|
{
|
|
102
|
0
|
MBeanParameterInfo parameter = (MBeanParameterInfo) i.next();
|
|
103
|
0
|
Class clazz = ClassTools.getClass(parameter.getType());
|
|
104
|
|
|
|
105
|
0
|
nameLabel = new JLabel(parameter.getName() + ":", SwingConstants.RIGHT);
|
|
106
|
0
|
constraints.gridwidth = GridBagConstraints.RELATIVE;
|
|
107
|
0
|
constraints.fill = GridBagConstraints.NONE;
|
|
108
|
0
|
constraints.weightx = 0.0d;
|
|
109
|
0
|
panel.add(nameLabel, constraints);
|
|
110
|
|
|
|
111
|
0
|
PropertyEditor editor = null;
|
|
112
|
0
|
if (clazz != null)
|
|
113
|
|
{
|
|
114
|
0
|
editor = CustomPropertyEditorManager.findEditor(clazz);
|
|
115
|
0
|
if (editor != null)
|
|
116
|
|
{
|
|
117
|
|
|
|
118
|
0
|
if (editor.getTags() != null)
|
|
119
|
|
{
|
|
120
|
|
|
|
121
|
0
|
editor.setAsText(editor.getTags()[0]);
|
|
122
|
|
}
|
|
123
|
|
|
|
124
|
0
|
Component component;
|
|
125
|
0
|
if (editor.supportsCustomEditor())
|
|
126
|
|
{
|
|
127
|
0
|
component = editor.getCustomEditor();
|
|
128
|
|
}
|
|
129
|
|
else
|
|
130
|
|
{
|
|
131
|
0
|
String[] lTags = editor.getTags();
|
|
132
|
0
|
if (lTags != null)
|
|
133
|
|
{
|
|
134
|
0
|
component = new GenericPropertyCustomizer(editor, lTags);
|
|
135
|
|
}
|
|
136
|
|
else
|
|
137
|
|
{
|
|
138
|
0
|
component = new GenericPropertyCustomizer(editor);
|
|
139
|
|
}
|
|
140
|
|
}
|
|
141
|
|
|
|
142
|
0
|
constraints.gridwidth = GridBagConstraints.REMAINDER;
|
|
143
|
0
|
constraints.fill = GridBagConstraints.HORIZONTAL;
|
|
144
|
0
|
constraints.weightx = 1.0d;
|
|
145
|
0
|
panel.add(component, constraints);
|
|
146
|
|
|
|
147
|
0
|
this.editors.addElement(new Editor(editor, parameter.getType()));
|
|
148
|
|
}
|
|
149
|
|
}
|
|
150
|
0
|
if (editor == null)
|
|
151
|
|
{
|
|
152
|
0
|
Component component;
|
|
153
|
0
|
component = new JLabel(resources.getString("invoke.dialog.text.unloadable.class") + " " + parameter.getType());
|
|
154
|
|
|
|
155
|
0
|
constraints.gridwidth = GridBagConstraints.REMAINDER;
|
|
156
|
0
|
constraints.fill = GridBagConstraints.HORIZONTAL;
|
|
157
|
0
|
constraints.weightx = 1.0d;
|
|
158
|
0
|
panel.add(component, constraints);
|
|
159
|
|
}
|
|
160
|
0
|
constraints.weighty = 1.0d;
|
|
161
|
|
}
|
|
162
|
|
|
|
163
|
|
|
|
164
|
0
|
constraints.gridwidth = GridBagConstraints.REMAINDER;
|
|
165
|
0
|
JPanel buttons = new JPanel();
|
|
166
|
0
|
JButton invokeButton = new JButton(resources.getString("invoke.dialog.button.invoke"));
|
|
167
|
0
|
invokeButton.setActionCommand("INVOKE");
|
|
168
|
0
|
buttons.add(invokeButton);
|
|
169
|
0
|
invokeButton.addActionListener(this);
|
|
170
|
0
|
JButton cancelButton = new JButton(resources.getString("invoke.dialog.button.cancel"));
|
|
171
|
0
|
buttons.add(cancelButton);
|
|
172
|
0
|
cancelButton.addActionListener(this);
|
|
173
|
0
|
panel.add(buttons, constraints);
|
|
174
|
|
|
|
175
|
0
|
if (this.editors.size() != this.operationInfo.getSignature().length)
|
|
176
|
|
{
|
|
177
|
0
|
invokeButton.setEnabled(false);
|
|
178
|
|
}
|
|
179
|
|
|
|
180
|
0
|
this.pack();
|
|
181
|
0
|
if (this.getWidth() < 300)
|
|
182
|
|
{
|
|
183
|
0
|
this.setSize(new Dimension(300, getHeight()));
|
|
184
|
|
}
|
|
185
|
0
|
this.setLocationRelativeTo(parent);
|
|
186
|
|
}
|
|
187
|
|
catch (Exception e)
|
|
188
|
|
{
|
|
189
|
0
|
e.printStackTrace();
|
|
190
|
|
}
|
|
191
|
|
}
|
|
192
|
|
|
|
193
|
|
|
|
194
|
|
|
|
195
|
|
|
|
196
|
|
|
|
197
|
|
|
|
198
|
|
|
|
199
|
0
|
public void actionPerformed(ActionEvent e)
|
|
200
|
|
{
|
|
201
|
0
|
if (e.getActionCommand().equals("INVOKE"))
|
|
202
|
|
{
|
|
203
|
0
|
Object[] parameters = new Object[this.editors.size()];
|
|
204
|
0
|
String[] types = new String[this.editors.size()];
|
|
205
|
0
|
int j = 0;
|
|
206
|
0
|
for (Iterator i = this.editors.iterator(); i.hasNext(); j++)
|
|
207
|
|
{
|
|
208
|
0
|
Editor editor = (Editor) i.next();
|
|
209
|
0
|
parameters[j] = editor.getEditor().getValue();
|
|
210
|
0
|
types[j] = editor.getType();
|
|
211
|
|
}
|
|
212
|
|
|
|
213
|
0
|
try
|
|
214
|
|
{
|
|
215
|
0
|
Object result = resource.invoke(this.operationInfo.getName(), parameters, types);
|
|
216
|
|
}
|
|
217
|
|
catch (Exception ex)
|
|
218
|
|
{
|
|
219
|
0
|
JOptionPane.showMessageDialog(this, resources.getString("invoke.dialog.text.error"), resources.getString("invoke.dialog.title.error"), JOptionPane.ERROR_MESSAGE);
|
|
220
|
|
}
|
|
221
|
|
}
|
|
222
|
0
|
this.setVisible(false);
|
|
223
|
|
}
|
|
224
|
|
|
|
225
|
|
|
|
226
|
|
|
|
227
|
|
|
|
228
|
|
|
|
229
|
|
|
|
230
|
|
|
|
231
|
|
|
|
232
|
|
private class Editor
|
|
233
|
|
{
|
|
234
|
|
|
|
235
|
|
private PropertyEditor editor;
|
|
236
|
|
|
|
237
|
|
private String type;
|
|
238
|
|
|
|
239
|
|
|
|
240
|
|
|
|
241
|
|
|
|
242
|
|
|
|
243
|
|
|
|
244
|
|
|
|
245
|
|
|
|
246
|
0
|
public Editor(PropertyEditor editor, String type)
|
|
247
|
|
{
|
|
248
|
0
|
this.editor = editor;
|
|
249
|
0
|
this.type = type;
|
|
250
|
|
}
|
|
251
|
|
|
|
252
|
|
|
|
253
|
|
|
|
254
|
|
|
|
255
|
|
|
|
256
|
|
|
|
257
|
|
|
|
258
|
0
|
public PropertyEditor getEditor()
|
|
259
|
|
{
|
|
260
|
0
|
return this.editor;
|
|
261
|
|
}
|
|
262
|
|
|
|
263
|
|
|
|
264
|
|
|
|
265
|
|
|
|
266
|
|
|
|
267
|
|
|
|
268
|
|
|
|
269
|
0
|
public String getType()
|
|
270
|
|
{
|
|
271
|
0
|
return this.type;
|
|
272
|
|
}
|
|
273
|
|
}
|
|
274
|
|
|
|
275
|
|
}
|
|
276
|
|
|
|
277
|
|
|