KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > share > configbean > customizers > webservice > MessageSecurityEntryPanel


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 /*
20  * MessageSecurityEntryPanel.java
21  *
22  * Created on Apr 19, 2006, 6:28 PM
23  */

24
25 package org.netbeans.modules.j2ee.sun.share.configbean.customizers.webservice;
26
27 import java.awt.Dimension JavaDoc;
28 import java.text.MessageFormat JavaDoc;
29 import java.util.ArrayList JavaDoc;
30 import java.util.Collection JavaDoc;
31 import java.util.List JavaDoc;
32 import java.util.ResourceBundle JavaDoc;
33 import javax.swing.DefaultComboBoxModel JavaDoc;
34 import javax.swing.JPanel JavaDoc;
35
36 import org.openide.util.NbBundle;
37
38 import org.netbeans.modules.j2ee.sun.share.Constants;
39 import org.netbeans.modules.j2ee.sun.share.configbean.ASDDVersion;
40 import org.netbeans.modules.j2ee.sun.share.configbean.Utils;
41 import org.netbeans.modules.j2ee.sun.share.configbean.customizers.common.ValidationSupport;
42 import org.netbeans.modules.j2ee.sun.share.configbean.customizers.common.GenericTableDialogPanelAccessor;
43 import org.netbeans.modules.j2ee.sun.share.configbean.customizers.common.TextMapping;
44
45
46 /**
47  *
48  * @author Peter Williams
49  */

50 public class MessageSecurityEntryPanel extends JPanel JavaDoc implements GenericTableDialogPanelAccessor {
51
52     private static final ResourceBundle JavaDoc webserviceBundle = ResourceBundle.getBundle(
53         "org.netbeans.modules.j2ee.sun.share.configbean.customizers.webservice.Bundle"); // NOI18N
54

55     private static final ResourceBundle JavaDoc commonBundle = ResourceBundle.getBundle(
56         "org.netbeans.modules.j2ee.sun.share.configbean.customizers.common.Bundle"); // NOI18N
57

58     /** xml <--> ui mapping for request/response authorization settings */
59     private static final TextMapping [] sourceTypes = {
60         new TextMapping("", ""), // NOI18N
61
new TextMapping("sender", webserviceBundle.getString("AUTH_SOURCE_SENDER")), // NOI18N
62
new TextMapping("content", webserviceBundle.getString("AUTH_SOURCE_CONTENT")), // NOI18N
63
};
64     
65     private static final TextMapping [] recipientTypes = {
66         new TextMapping("", ""), // NOI18N
67
new TextMapping("before-content", webserviceBundle.getString("AUTH_RECIPIENT_BEFORE_CONTENT")), // NOI18N
68
new TextMapping("after-content", webserviceBundle.getString("AUTH_RECIPIENT_AFTER_CONTENT")), // NOI18N
69
};
70     
71     // Field indices (maps to values[] handled by get/setValues()
72
private static final int METHOD_FIELD = 0;
73     private static final int REQ_SOURCE_FIELD = 1;
74     private static final int REQ_RECIPIENT_FIELD = 2;
75     private static final int RESP_SOURCE_FIELD = 3;
76     private static final int RESP_RECIPIENT_FIELD = 4;
77     private static final int NUM_FIELDS = 5; // Number of objects expected in get/setValue methods.
78

79     private DefaultComboBoxModel JavaDoc authReqSourceModel;
80     private DefaultComboBoxModel JavaDoc authReqRecipientModel;
81     private DefaultComboBoxModel JavaDoc authRespSourceModel;
82     private DefaultComboBoxModel JavaDoc authRespRecipientModel;
83
84     // Do we validate method name as an operation or as a java method?
85
private boolean methodAsOperation;
86     
87     // Local storage for data entered by user
88
private String JavaDoc methodName;
89     private String JavaDoc reqSource;
90     private String JavaDoc reqRecipient;
91     private String JavaDoc respSource;
92     private String JavaDoc respRecipient;
93
94     private boolean initializingFields;
95
96     /**
97      * Creates new form MessageSecurityEntryPanel
98      */

99     public MessageSecurityEntryPanel() {
100         initComponents();
101         initUserComponents();
102     }
103     
104     /** This method is called from within the constructor to
105      * initialize the form.
106      * WARNING: Do NOT modify this code. The content of this method is
107      * always regenerated by the Form Editor.
108      */

109     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
110
private void initComponents() {
111         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
112
113         jLblMethodNameReqFlag = new javax.swing.JLabel JavaDoc();
114         jLblMethodName = new javax.swing.JLabel JavaDoc();
115         jTxtMethodName = new javax.swing.JTextField JavaDoc();
116         jLblReqAuthSource = new javax.swing.JLabel JavaDoc();
117         jCbxReqAuthSource = new javax.swing.JComboBox JavaDoc();
118         jLblReqAuthRecip = new javax.swing.JLabel JavaDoc();
119         jCbxReqAuthRecip = new javax.swing.JComboBox JavaDoc();
120         jLblRespAuthSource = new javax.swing.JLabel JavaDoc();
121         jCbxRespAuthSource = new javax.swing.JComboBox JavaDoc();
122         jLblRespAuthRecip = new javax.swing.JLabel JavaDoc();
123         jCbxRespAuthRecip = new javax.swing.JComboBox JavaDoc();
124
125         setLayout(new java.awt.GridBagLayout JavaDoc());
126
127         jLblMethodNameReqFlag.setText(commonBundle.getString("LBL_RequiredMark"));
128         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
129         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 6, 0, 0);
130         add(jLblMethodNameReqFlag, gridBagConstraints);
131         jLblMethodNameReqFlag.getAccessibleContext().setAccessibleName(commonBundle.getString("ACSN_RequiredMark"));
132         jLblMethodNameReqFlag.getAccessibleContext().setAccessibleDescription(commonBundle.getString("ACSD_RequiredMark"));
133
134         jLblMethodName.setDisplayedMnemonic(webserviceBundle.getString("MNE_MethodName").charAt(0));
135         jLblMethodName.setText(webserviceBundle.getString("LBL_MethodName_1"));
136         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
137         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
138         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 6, 0, 0);
139         add(jLblMethodName, gridBagConstraints);
140
141         jTxtMethodName.addKeyListener(new java.awt.event.KeyAdapter JavaDoc() {
142             public void keyReleased(java.awt.event.KeyEvent JavaDoc evt) {
143                 jTxtMethodNameKeyReleased(evt);
144             }
145         });
146
147         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
148         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
149         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
150         gridBagConstraints.weightx = 1.0;
151         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 6, 0, 5);
152         add(jTxtMethodName, gridBagConstraints);
153
154         jLblReqAuthSource.setDisplayedMnemonic(webserviceBundle.getString("MNE_ReqAuthSource").charAt(0));
155         jLblReqAuthSource.setText(webserviceBundle.getString("LBL_ReqAuthSource_1"));
156         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
157         gridBagConstraints.gridx = 1;
158         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
159         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 6, 0, 0);
160         add(jLblReqAuthSource, gridBagConstraints);
161
162         jCbxReqAuthSource.addActionListener(new java.awt.event.ActionListener JavaDoc() {
163             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
164                 jCbxReqAuthSourceActionPerformed(evt);
165             }
166         });
167
168         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
169         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
170         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
171         gridBagConstraints.weightx = 1.0;
172         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 6, 0, 5);
173         add(jCbxReqAuthSource, gridBagConstraints);
174
175         jLblReqAuthRecip.setDisplayedMnemonic(webserviceBundle.getString("MNE_ReqAuthRecipient").charAt(0));
176         jLblReqAuthRecip.setText(webserviceBundle.getString("LBL_ReqAuthRecipient_1"));
177         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
178         gridBagConstraints.gridx = 1;
179         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
180         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 6, 0, 0);
181         add(jLblReqAuthRecip, gridBagConstraints);
182
183         jCbxReqAuthRecip.addActionListener(new java.awt.event.ActionListener JavaDoc() {
184             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
185                 jCbxReqAuthRecipActionPerformed(evt);
186             }
187         });
188
189         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
190         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
191         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
192         gridBagConstraints.weightx = 1.0;
193         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 6, 0, 5);
194         add(jCbxReqAuthRecip, gridBagConstraints);
195
196         jLblRespAuthSource.setDisplayedMnemonic(webserviceBundle.getString("MNE_RespAuthSource").charAt(0));
197         jLblRespAuthSource.setText(webserviceBundle.getString("LBL_RespAuthSource_1"));
198         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
199         gridBagConstraints.gridx = 1;
200         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
201         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 6, 0, 0);
202         add(jLblRespAuthSource, gridBagConstraints);
203
204         jCbxRespAuthSource.addActionListener(new java.awt.event.ActionListener JavaDoc() {
205             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
206                 jCbxRespAuthSourceActionPerformed(evt);
207             }
208         });
209
210         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
211         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
212         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
213         gridBagConstraints.weightx = 1.0;
214         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 6, 0, 5);
215         add(jCbxRespAuthSource, gridBagConstraints);
216
217         jLblRespAuthRecip.setDisplayedMnemonic(webserviceBundle.getString("MNE_RespAuthRecipient").charAt(0));
218         jLblRespAuthRecip.setText(webserviceBundle.getString("LBL_RespAuthRecipient_1"));
219         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
220         gridBagConstraints.gridx = 1;
221         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
222         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 6, 5, 0);
223         add(jLblRespAuthRecip, gridBagConstraints);
224
225         jCbxRespAuthRecip.addActionListener(new java.awt.event.ActionListener JavaDoc() {
226             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
227                 jCbxRespAuthRecipActionPerformed(evt);
228             }
229         });
230
231         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
232         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
233         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
234         gridBagConstraints.weightx = 1.0;
235         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 6, 5, 5);
236         add(jCbxRespAuthRecip, gridBagConstraints);
237
238     }// </editor-fold>//GEN-END:initComponents
239

240     private void jTxtMethodNameKeyReleased(java.awt.event.KeyEvent JavaDoc evt) {//GEN-FIRST:event_jTxtMethodNameKeyReleased
241
if(!initializingFields) {
242             String JavaDoc oldMethodName = methodName;
243             methodName = jTxtMethodName.getText().trim();
244             if(!methodName.equals(oldMethodName)) {
245                 firePropertyChange(Constants.USER_DATA_CHANGED, null, null);
246             }
247         }
248     }//GEN-LAST:event_jTxtMethodNameKeyReleased
249

250     private void jCbxRespAuthRecipActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jCbxRespAuthRecipActionPerformed
251
if(!initializingFields) {
252             TextMapping authMapping = (TextMapping) authRespRecipientModel.getSelectedItem();
253             respRecipient = normalizeBlank(authMapping.getXMLString());
254             firePropertyChange(Constants.USER_DATA_CHANGED, null, null);
255         }
256     }//GEN-LAST:event_jCbxRespAuthRecipActionPerformed
257

258     private void jCbxRespAuthSourceActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jCbxRespAuthSourceActionPerformed
259
if(!initializingFields) {
260             TextMapping authMapping = (TextMapping) authRespSourceModel.getSelectedItem();
261             respSource = normalizeBlank(authMapping.getXMLString());
262             firePropertyChange(Constants.USER_DATA_CHANGED, null, null);
263         }
264     }//GEN-LAST:event_jCbxRespAuthSourceActionPerformed
265

266     private void jCbxReqAuthRecipActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jCbxReqAuthRecipActionPerformed
267
if(!initializingFields) {
268             TextMapping authMapping = (TextMapping) authReqRecipientModel.getSelectedItem();
269             reqRecipient = normalizeBlank(authMapping.getXMLString());
270             firePropertyChange(Constants.USER_DATA_CHANGED, null, null);
271         }
272     }//GEN-LAST:event_jCbxReqAuthRecipActionPerformed
273

274     private void jCbxReqAuthSourceActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jCbxReqAuthSourceActionPerformed
275
if(!initializingFields) {
276             TextMapping authMapping = (TextMapping) authReqSourceModel.getSelectedItem();
277             reqSource = normalizeBlank(authMapping.getXMLString());
278             firePropertyChange(Constants.USER_DATA_CHANGED, null, null);
279         }
280     }//GEN-LAST:event_jCbxReqAuthSourceActionPerformed
281

282     // Variables declaration - do not modify//GEN-BEGIN:variables
283
private javax.swing.JComboBox JavaDoc jCbxReqAuthRecip;
284     private javax.swing.JComboBox JavaDoc jCbxReqAuthSource;
285     private javax.swing.JComboBox JavaDoc jCbxRespAuthRecip;
286     private javax.swing.JComboBox JavaDoc jCbxRespAuthSource;
287     private javax.swing.JLabel JavaDoc jLblMethodName;
288     private javax.swing.JLabel JavaDoc jLblMethodNameReqFlag;
289     private javax.swing.JLabel JavaDoc jLblReqAuthRecip;
290     private javax.swing.JLabel JavaDoc jLblReqAuthSource;
291     private javax.swing.JLabel JavaDoc jLblRespAuthRecip;
292     private javax.swing.JLabel JavaDoc jLblRespAuthSource;
293     private javax.swing.JTextField JavaDoc jTxtMethodName;
294     // End of variables declaration//GEN-END:variables
295

296     protected void initUserComponents() {
297         // Setup authorization source comboboxes
298
authReqSourceModel = new DefaultComboBoxModel JavaDoc();
299         authRespSourceModel = new DefaultComboBoxModel JavaDoc();
300         for(int i = 0; i < sourceTypes.length; i++) {
301             authReqSourceModel.addElement(sourceTypes[i]);
302             authRespSourceModel.addElement(sourceTypes[i]);
303         }
304         jCbxReqAuthSource.setModel(authReqSourceModel);
305         jCbxRespAuthSource.setModel(authRespSourceModel);
306         
307         // Setup authorization recipient comboboxes
308
authReqRecipientModel = new DefaultComboBoxModel JavaDoc();
309         authRespRecipientModel = new DefaultComboBoxModel JavaDoc();
310         for(int i = 0; i < recipientTypes.length; i++) {
311             authReqRecipientModel.addElement(recipientTypes[i]);
312             authRespRecipientModel.addElement(recipientTypes[i]);
313         }
314         jCbxReqAuthRecip.setModel(authReqRecipientModel);
315         jCbxRespAuthRecip.setModel(authRespRecipientModel);
316     }
317     
318     private String JavaDoc normalizeBlank(String JavaDoc value) {
319         return (value != "") ? value : null;
320     }
321     
322     private TextMapping getAuthMapping(String JavaDoc xmlKey, final TextMapping [] authMap) {
323         TextMapping result = null;
324         if(xmlKey == null) {
325             xmlKey = ""; // NOI18N
326
}
327         for(int i = 0; i < authMap.length; i++) {
328             if(authMap[i].getXMLString().compareTo(xmlKey) == 0) {
329                 result = authMap[i];
330                 break;
331             }
332         }
333         return result;
334     }
335     
336     public Collection JavaDoc getErrors(ValidationSupport validationSupport) {
337         ArrayList JavaDoc errorList = new ArrayList JavaDoc();
338
339         if(!Utils.notEmpty(methodName)) {
340             String JavaDoc msgPattern = webserviceBundle.getString("ERR_MethodNameRequired"); // NOI18N
341
errorList.add(MessageFormat.format(msgPattern, new Object JavaDoc [] { new Integer JavaDoc(methodAsOperation ? 1 : 0) } ));
342         } else if(!"*".equals(methodName)) {
343             if(methodAsOperation) {
344                 // validate methodName as just an operation name.
345
if(!Utils.isJavaIdentifier(methodName)) {
346                     errorList.add(NbBundle.getMessage(MessageSecurityEntryPanel.class,
347                             "ERR_OperationNameInvalid", methodName)); // NOI18N
348
}
349             } else {
350                 // validate methodName as a java method signature.
351
String JavaDoc [] parts = MessageEntry.methodSplitter.split(methodName);
352                 if(parts.length > 0) {
353                     if(!Utils.isJavaIdentifier(parts[0])) {
354                         errorList.add(NbBundle.getMessage(MessageSecurityEntryPanel.class,
355                                 "ERR_JavaMethodInvalid", parts[0])); // NOI18N
356
} else {
357                         for(int i = 1; i < parts.length; i++) {
358                             if(!Utils.isJavaClass(parts[i])) {
359                                 errorList.add(NbBundle.getMessage(MessageSecurityEntryPanel.class,
360                                         "ERR_MethodParamInvalid", parts[i])); // NOI18N
361
// Only show one parameter error at a time.
362
break;
363                             }
364                         }
365                     }
366                 }
367             }
368         }
369         
370         return errorList;
371     }
372     
373     public Object JavaDoc[] getValues() {
374         Object JavaDoc [] result = new Object JavaDoc[NUM_FIELDS];
375         
376         result[METHOD_FIELD] = methodName;
377         result[REQ_SOURCE_FIELD] = reqSource;
378         result[REQ_RECIPIENT_FIELD] = reqRecipient;
379         result[RESP_SOURCE_FIELD] = respSource;
380         result[RESP_RECIPIENT_FIELD] = respRecipient;
381         
382         return result;
383     }
384     
385     public void init(ASDDVersion asVersion, int preferredWidth, List JavaDoc entries, Object JavaDoc data) {
386         if(data instanceof Boolean JavaDoc) {
387             methodAsOperation = ((Boolean JavaDoc) data).booleanValue();
388         }
389         
390         setPreferredSize(new Dimension JavaDoc(preferredWidth, getPreferredSize().height));
391     }
392     
393     public void setValues(Object JavaDoc[] values) {
394         if(values != null && values.length == NUM_FIELDS) {
395             methodName = (String JavaDoc) values[METHOD_FIELD];
396             reqSource = (String JavaDoc) values[REQ_SOURCE_FIELD];
397             reqRecipient = (String JavaDoc) values[REQ_RECIPIENT_FIELD];
398             respSource = (String JavaDoc) values[RESP_SOURCE_FIELD];
399             respRecipient = (String JavaDoc) values[RESP_RECIPIENT_FIELD];
400         } else {
401             if(values != null) {
402                 assert (values.length == NUM_FIELDS); // Should fail
403
}
404             
405             // default values
406
methodName = "*"; // NOI18N
407
reqSource = null;
408             reqRecipient = null;
409             respSource = null;
410             respRecipient = null;
411         }
412         
413         setComponentValues();
414     }
415     
416     private void setComponentValues() {
417         try {
418             initializingFields = true;
419             
420             jTxtMethodName.setText(methodName);
421             jCbxReqAuthSource.setSelectedItem(getAuthMapping(reqSource, sourceTypes));
422             jCbxReqAuthRecip.setSelectedItem(getAuthMapping(reqRecipient, recipientTypes));
423             jCbxRespAuthSource.setSelectedItem(getAuthMapping(respSource, sourceTypes));
424             jCbxRespAuthRecip.setSelectedItem(getAuthMapping(respRecipient, recipientTypes));
425         } finally {
426             initializingFields = false;
427         }
428     }
429     
430     public boolean requiredFieldsFilled() {
431         return Utils.notEmpty(methodName);
432     }
433 }
434
Popular Tags