1 19 24 25 package org.netbeans.modules.j2ee.sun.share.configbean.customizers.webservice; 26 27 import java.awt.Dimension ; 28 import java.text.MessageFormat ; 29 import java.util.ArrayList ; 30 import java.util.Collection ; 31 import java.util.List ; 32 import java.util.ResourceBundle ; 33 import javax.swing.DefaultComboBoxModel ; 34 import javax.swing.JPanel ; 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 50 public class MessageSecurityEntryPanel extends JPanel implements GenericTableDialogPanelAccessor { 51 52 private static final ResourceBundle webserviceBundle = ResourceBundle.getBundle( 53 "org.netbeans.modules.j2ee.sun.share.configbean.customizers.webservice.Bundle"); 55 private static final ResourceBundle commonBundle = ResourceBundle.getBundle( 56 "org.netbeans.modules.j2ee.sun.share.configbean.customizers.common.Bundle"); 58 59 private static final TextMapping [] sourceTypes = { 60 new TextMapping("", ""), new TextMapping("sender", webserviceBundle.getString("AUTH_SOURCE_SENDER")), new TextMapping("content", webserviceBundle.getString("AUTH_SOURCE_CONTENT")), }; 64 65 private static final TextMapping [] recipientTypes = { 66 new TextMapping("", ""), new TextMapping("before-content", webserviceBundle.getString("AUTH_RECIPIENT_BEFORE_CONTENT")), new TextMapping("after-content", webserviceBundle.getString("AUTH_RECIPIENT_AFTER_CONTENT")), }; 70 71 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; 79 private DefaultComboBoxModel authReqSourceModel; 80 private DefaultComboBoxModel authReqRecipientModel; 81 private DefaultComboBoxModel authRespSourceModel; 82 private DefaultComboBoxModel authRespRecipientModel; 83 84 private boolean methodAsOperation; 86 87 private String methodName; 89 private String reqSource; 90 private String reqRecipient; 91 private String respSource; 92 private String respRecipient; 93 94 private boolean initializingFields; 95 96 99 public MessageSecurityEntryPanel() { 100 initComponents(); 101 initUserComponents(); 102 } 103 104 109 private void initComponents() { 111 java.awt.GridBagConstraints gridBagConstraints; 112 113 jLblMethodNameReqFlag = new javax.swing.JLabel (); 114 jLblMethodName = new javax.swing.JLabel (); 115 jTxtMethodName = new javax.swing.JTextField (); 116 jLblReqAuthSource = new javax.swing.JLabel (); 117 jCbxReqAuthSource = new javax.swing.JComboBox (); 118 jLblReqAuthRecip = new javax.swing.JLabel (); 119 jCbxReqAuthRecip = new javax.swing.JComboBox (); 120 jLblRespAuthSource = new javax.swing.JLabel (); 121 jCbxRespAuthSource = new javax.swing.JComboBox (); 122 jLblRespAuthRecip = new javax.swing.JLabel (); 123 jCbxRespAuthRecip = new javax.swing.JComboBox (); 124 125 setLayout(new java.awt.GridBagLayout ()); 126 127 jLblMethodNameReqFlag.setText(commonBundle.getString("LBL_RequiredMark")); 128 gridBagConstraints = new java.awt.GridBagConstraints (); 129 gridBagConstraints.insets = new java.awt.Insets (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 (); 137 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 138 gridBagConstraints.insets = new java.awt.Insets (6, 6, 0, 0); 139 add(jLblMethodName, gridBagConstraints); 140 141 jTxtMethodName.addKeyListener(new java.awt.event.KeyAdapter () { 142 public void keyReleased(java.awt.event.KeyEvent evt) { 143 jTxtMethodNameKeyReleased(evt); 144 } 145 }); 146 147 gridBagConstraints = new java.awt.GridBagConstraints (); 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 (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 (); 157 gridBagConstraints.gridx = 1; 158 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 159 gridBagConstraints.insets = new java.awt.Insets (6, 6, 0, 0); 160 add(jLblReqAuthSource, gridBagConstraints); 161 162 jCbxReqAuthSource.addActionListener(new java.awt.event.ActionListener () { 163 public void actionPerformed(java.awt.event.ActionEvent evt) { 164 jCbxReqAuthSourceActionPerformed(evt); 165 } 166 }); 167 168 gridBagConstraints = new java.awt.GridBagConstraints (); 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 (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 (); 178 gridBagConstraints.gridx = 1; 179 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 180 gridBagConstraints.insets = new java.awt.Insets (6, 6, 0, 0); 181 add(jLblReqAuthRecip, gridBagConstraints); 182 183 jCbxReqAuthRecip.addActionListener(new java.awt.event.ActionListener () { 184 public void actionPerformed(java.awt.event.ActionEvent evt) { 185 jCbxReqAuthRecipActionPerformed(evt); 186 } 187 }); 188 189 gridBagConstraints = new java.awt.GridBagConstraints (); 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 (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 (); 199 gridBagConstraints.gridx = 1; 200 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 201 gridBagConstraints.insets = new java.awt.Insets (6, 6, 0, 0); 202 add(jLblRespAuthSource, gridBagConstraints); 203 204 jCbxRespAuthSource.addActionListener(new java.awt.event.ActionListener () { 205 public void actionPerformed(java.awt.event.ActionEvent evt) { 206 jCbxRespAuthSourceActionPerformed(evt); 207 } 208 }); 209 210 gridBagConstraints = new java.awt.GridBagConstraints (); 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 (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 (); 220 gridBagConstraints.gridx = 1; 221 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 222 gridBagConstraints.insets = new java.awt.Insets (6, 6, 5, 0); 223 add(jLblRespAuthRecip, gridBagConstraints); 224 225 jCbxRespAuthRecip.addActionListener(new java.awt.event.ActionListener () { 226 public void actionPerformed(java.awt.event.ActionEvent evt) { 227 jCbxRespAuthRecipActionPerformed(evt); 228 } 229 }); 230 231 gridBagConstraints = new java.awt.GridBagConstraints (); 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 (6, 6, 5, 5); 236 add(jCbxRespAuthRecip, gridBagConstraints); 237 238 } 240 private void jTxtMethodNameKeyReleased(java.awt.event.KeyEvent evt) { if(!initializingFields) { 242 String oldMethodName = methodName; 243 methodName = jTxtMethodName.getText().trim(); 244 if(!methodName.equals(oldMethodName)) { 245 firePropertyChange(Constants.USER_DATA_CHANGED, null, null); 246 } 247 } 248 } 250 private void jCbxRespAuthRecipActionPerformed(java.awt.event.ActionEvent evt) { if(!initializingFields) { 252 TextMapping authMapping = (TextMapping) authRespRecipientModel.getSelectedItem(); 253 respRecipient = normalizeBlank(authMapping.getXMLString()); 254 firePropertyChange(Constants.USER_DATA_CHANGED, null, null); 255 } 256 } 258 private void jCbxRespAuthSourceActionPerformed(java.awt.event.ActionEvent evt) { if(!initializingFields) { 260 TextMapping authMapping = (TextMapping) authRespSourceModel.getSelectedItem(); 261 respSource = normalizeBlank(authMapping.getXMLString()); 262 firePropertyChange(Constants.USER_DATA_CHANGED, null, null); 263 } 264 } 266 private void jCbxReqAuthRecipActionPerformed(java.awt.event.ActionEvent evt) { if(!initializingFields) { 268 TextMapping authMapping = (TextMapping) authReqRecipientModel.getSelectedItem(); 269 reqRecipient = normalizeBlank(authMapping.getXMLString()); 270 firePropertyChange(Constants.USER_DATA_CHANGED, null, null); 271 } 272 } 274 private void jCbxReqAuthSourceActionPerformed(java.awt.event.ActionEvent evt) { if(!initializingFields) { 276 TextMapping authMapping = (TextMapping) authReqSourceModel.getSelectedItem(); 277 reqSource = normalizeBlank(authMapping.getXMLString()); 278 firePropertyChange(Constants.USER_DATA_CHANGED, null, null); 279 } 280 } 282 private javax.swing.JComboBox jCbxReqAuthRecip; 284 private javax.swing.JComboBox jCbxReqAuthSource; 285 private javax.swing.JComboBox jCbxRespAuthRecip; 286 private javax.swing.JComboBox jCbxRespAuthSource; 287 private javax.swing.JLabel jLblMethodName; 288 private javax.swing.JLabel jLblMethodNameReqFlag; 289 private javax.swing.JLabel jLblReqAuthRecip; 290 private javax.swing.JLabel jLblReqAuthSource; 291 private javax.swing.JLabel jLblRespAuthRecip; 292 private javax.swing.JLabel jLblRespAuthSource; 293 private javax.swing.JTextField jTxtMethodName; 294 296 protected void initUserComponents() { 297 authReqSourceModel = new DefaultComboBoxModel (); 299 authRespSourceModel = new DefaultComboBoxModel (); 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 authReqRecipientModel = new DefaultComboBoxModel (); 309 authRespRecipientModel = new DefaultComboBoxModel (); 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 normalizeBlank(String value) { 319 return (value != "") ? value : null; 320 } 321 322 private TextMapping getAuthMapping(String xmlKey, final TextMapping [] authMap) { 323 TextMapping result = null; 324 if(xmlKey == null) { 325 xmlKey = ""; } 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 getErrors(ValidationSupport validationSupport) { 337 ArrayList errorList = new ArrayList (); 338 339 if(!Utils.notEmpty(methodName)) { 340 String msgPattern = webserviceBundle.getString("ERR_MethodNameRequired"); errorList.add(MessageFormat.format(msgPattern, new Object [] { new Integer (methodAsOperation ? 1 : 0) } )); 342 } else if(!"*".equals(methodName)) { 343 if(methodAsOperation) { 344 if(!Utils.isJavaIdentifier(methodName)) { 346 errorList.add(NbBundle.getMessage(MessageSecurityEntryPanel.class, 347 "ERR_OperationNameInvalid", methodName)); } 349 } else { 350 String [] 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])); } 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])); break; 363 } 364 } 365 } 366 } 367 } 368 } 369 370 return errorList; 371 } 372 373 public Object [] getValues() { 374 Object [] result = new Object [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 entries, Object data) { 386 if(data instanceof Boolean ) { 387 methodAsOperation = ((Boolean ) data).booleanValue(); 388 } 389 390 setPreferredSize(new Dimension (preferredWidth, getPreferredSize().height)); 391 } 392 393 public void setValues(Object [] values) { 394 if(values != null && values.length == NUM_FIELDS) { 395 methodName = (String ) values[METHOD_FIELD]; 396 reqSource = (String ) values[REQ_SOURCE_FIELD]; 397 reqRecipient = (String ) values[REQ_RECIPIENT_FIELD]; 398 respSource = (String ) values[RESP_SOURCE_FIELD]; 399 respRecipient = (String ) values[RESP_RECIPIENT_FIELD]; 400 } else { 401 if(values != null) { 402 assert (values.length == NUM_FIELDS); } 404 405 methodName = "*"; 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 |