1 19 20 28 29 package org.netbeans.modules.xml.wsdl.ui.wizard; 30 31 import java.awt.Component ; 32 import java.awt.Dimension ; 33 import java.beans.PropertyChangeEvent ; 34 import java.beans.PropertyChangeListener ; 35 import java.io.File ; 36 import java.io.IOException ; 37 import java.util.ArrayList ; 38 import java.util.HashMap ; 39 import java.util.Iterator ; 40 import java.util.List ; 41 import java.util.Map ; 42 import javax.swing.event.ChangeEvent ; 43 import javax.swing.event.ChangeListener ; 44 import javax.swing.event.DocumentEvent ; 45 import javax.swing.event.DocumentListener ; 46 import javax.swing.text.Document ; 47 import org.netbeans.modules.xml.wsdl.model.Binding; 48 import org.netbeans.modules.xml.wsdl.model.Port; 49 import org.netbeans.modules.xml.wsdl.model.PortType; 50 import org.netbeans.modules.xml.wsdl.model.Service; 51 import org.netbeans.modules.xml.wsdl.model.WSDLModel; 52 import org.netbeans.modules.xml.wsdl.model.WSDLModelFactory; 53 import org.netbeans.modules.xml.wsdl.ui.spi.ExtensibilityElementTemplateProvider; 54 import org.netbeans.modules.xml.wsdl.ui.spi.ValidationInfo; 55 import org.netbeans.modules.xml.wsdl.ui.view.BindingConfigurationPanel; 56 import org.netbeans.modules.xml.wsdl.ui.view.wizard.localized.LocalizedTemplate; 57 import org.netbeans.modules.xml.wsdl.ui.view.wizard.localized.LocalizedTemplateGroup; 58 import org.netbeans.modules.xml.xam.ModelSource; 59 import org.openide.WizardDescriptor; 60 import org.openide.filesystems.FileObject; 61 import org.openide.filesystems.FileUtil; 62 import org.openide.loaders.TemplateWizard; 63 import org.openide.util.HelpCtx; 64 import org.openide.util.NbBundle; 65 import org.openide.windows.IOProvider; 66 67 71 public class WizardBindingConfigurationStep implements WizardDescriptor.FinishablePanel { 72 73 public static final String BINDING_NAME = "BINDING_NAME"; 74 75 public static final String BINDING_TYPE = "BINDING_TYPE"; 76 77 public static final String BINDING_SUBTYPE = "BINDING_SUBTYPE"; 78 79 public static final String SERVICE_NAME = "SERVICE_NAME"; 80 81 public static final String SERVICEPORT_NAME = "SERVICEPORT_NAME"; 82 83 public static final String BINDING = "BINDING"; 84 85 public static final String SERVICE = "SERVICE"; 86 87 public static final String PORT = "PORT"; 88 89 90 91 private BindingConfigurationPanel mPanel; 92 93 private String mErrorMessage; 94 95 private String mBindingSubTypeError; 96 97 private final List <ChangeListener > listeners = new ArrayList (); 98 99 private WizardDescriptor wiz = null; 100 101 private WSDLModel mTempModel; 102 103 private PortType mPortType; 104 105 private Binding mBinding; 106 107 private Service mService; 108 109 private Port mPort; 110 111 112 public WizardBindingConfigurationStep() { 113 } 114 115 public void addChangeListener(ChangeListener l) { 116 listeners.add(l); 117 } 118 119 public void removeChangeListener(ChangeListener l) { 120 listeners.remove(l); 121 } 122 123 public Component getComponent() { 124 if (mPanel == null) { 125 this.mPanel = new BindingConfigurationPanel(); 126 this.mPanel.setName(NbBundle.getMessage(WizardBindingConfigurationStep.class, "LBL_WizardBindingConfigurationStep")); 128 TextChangeListener listener = new TextChangeListener(); 129 this.mPanel.getBindingNameTextField().getDocument().addDocumentListener(listener); 130 this.mPanel.getServiceNameTextField().getDocument().addDocumentListener(listener); 131 this.mPanel.getServicePortTextField().getDocument().addDocumentListener(listener); 132 BindingConfigurationListener propListener = new BindingConfigurationListener(); 133 this.mPanel.addPropertyChangeListener(propListener); 134 135 } 136 return this.mPanel; 137 } 138 139 140 141 public HelpCtx getHelp() { 142 return new HelpCtx(WizardBindingConfigurationStep.class); 143 } 144 145 public boolean isValid() { 146 wiz.putProperty ("WizardPanel_errorMessage", this.mErrorMessage); return this.mErrorMessage == null; 148 149 } 150 151 public void readSettings(Object settings) { 152 TemplateWizard templateWizard = (TemplateWizard)settings; 153 wiz = templateWizard; 154 String fileName = (String ) templateWizard.getProperty(WsdlPanel.FILE_NAME); 155 if(this.mPanel.getBindingName() == null || this.mPanel.getBindingName().trim().equals("")) { 156 this.mPanel.setBindingName(fileName + "Binding"); } 158 if(this.mPanel.getServiceName() == null || this.mPanel.getServiceName().trim().equals("")) { 159 this.mPanel.setServiceName(fileName + "Service"); } 161 if(this.mPanel.getServicePortName() == null || this.mPanel.getServicePortName().trim().equals("")) { 162 this.mPanel.setServicePortName(fileName + "Port"); } 164 165 this.mPortType = (PortType) templateWizard.getProperty(WizardPortTypeConfigurationStep.PORTTYPE); 166 this.mTempModel = (WSDLModel) templateWizard.getProperty(WizardPortTypeConfigurationStep.TEMP_WSDLMODEL); 167 168 170 } 171 172 public void storeSettings(Object settings) { 173 TemplateWizard templateWizard = (TemplateWizard)settings; 174 if(templateWizard.getValue() == TemplateWizard.CANCEL_OPTION) { 175 return; 176 } 177 178 if (templateWizard.getValue() == TemplateWizard.PREVIOUS_OPTION) { 179 mTempModel.startTransaction(); 180 cleanUpBindings(); 181 mTempModel.endTransaction(); 182 templateWizard.putProperty(BINDING_NAME, null); 183 templateWizard.putProperty(BINDING_TYPE, null); 184 templateWizard.putProperty(BINDING_SUBTYPE, null); 185 templateWizard.putProperty(SERVICE_NAME, null); 186 templateWizard.putProperty(SERVICEPORT_NAME, null); 187 return; 188 } 189 190 String bindingName = this.mPanel.getBindingName(); 191 LocalizedTemplateGroup bindingType = this.mPanel.getBindingType(); 192 LocalizedTemplate bindingSubType = this.mPanel.getBindingSubType(); 193 String serviceName = this.mPanel.getServiceName(); 194 String servicePortName = this.mPanel.getServicePortName(); 195 196 templateWizard.putProperty(BINDING_NAME, bindingName); 197 templateWizard.putProperty(BINDING_TYPE, bindingType); 198 templateWizard.putProperty(BINDING_SUBTYPE, bindingSubType); 199 templateWizard.putProperty(SERVICE_NAME, serviceName); 200 templateWizard.putProperty(SERVICEPORT_NAME, servicePortName); 201 202 processBindingSubType(bindingSubType); 203 } 204 205 private void cleanUpBindings() { 206 if(this.mBinding != null) { 207 this.mTempModel.getDefinitions().removeBinding(this.mBinding); 208 } 209 210 if(this.mService != null) { 211 this.mTempModel.getDefinitions().removeService(this.mService); 212 } 213 214 mBinding = null; 215 mService = null; 216 } 217 218 private boolean isValidName(Document doc) { 219 try { 220 String text = doc.getText(0, doc.getLength()); 221 boolean isValid = org.netbeans.modules.xml.xam.dom.Utils.isValidNCName(text); 222 if(!isValid) { 223 mErrorMessage = "Name \"" + text + "\" is not a valid NCName"; 224 } else { 225 mErrorMessage = null; 226 } 227 228 fireChangeEvent(); 229 } catch(Exception ex) { 230 ex.printStackTrace(); 231 } 232 233 return mErrorMessage == null; 234 } 235 236 private void validate() { 237 boolean isValidBinding = isValidName(this.mPanel.getBindingNameTextField().getDocument()); 238 if(!isValidBinding) { 239 fireChangeEvent(); 240 return; 241 } 242 243 boolean isValidService = isValidName(this.mPanel.getServiceNameTextField().getDocument()); 244 if(!isValidService) { 245 fireChangeEvent(); 246 return; 247 } 248 249 boolean isValidPort = isValidName(this.mPanel.getServicePortTextField().getDocument()); 250 if(!isValidPort) { 251 fireChangeEvent(); 252 return; 253 } 254 255 if(this.mBindingSubTypeError != null) { 256 this.mErrorMessage = this.mBindingSubTypeError; 257 fireChangeEvent(); 258 return; 259 } 260 261 fireChangeEvent(); 262 } 263 264 private void fireChangeEvent() { 265 Iterator <ChangeListener > it = this.listeners.iterator(); 266 ChangeEvent e = new ChangeEvent (this); 267 while(it.hasNext()) { 268 ChangeListener l = it.next(); 269 l.stateChanged(e); 270 } 271 } 272 273 public boolean isFinishPanel() { 274 return true; 275 } 276 277 private void processBindingSubType(LocalizedTemplate bindingSubType) { 278 if(bindingSubType != null) { 279 String bindingName = this.mPanel.getBindingName(); 280 LocalizedTemplateGroup bindingType = this.mPanel.getBindingType(); 281 282 283 String serviceName = this.mPanel.getServiceName(); 285 String servicePortName = this.mPanel.getServicePortName(); 286 287 Map configurationMap = new HashMap (); 288 configurationMap.put(WizardBindingConfigurationStep.BINDING_NAME, bindingName); 289 configurationMap.put(WizardBindingConfigurationStep.BINDING_TYPE, bindingType); 290 291 configurationMap.put(WizardBindingConfigurationStep.BINDING_SUBTYPE, bindingSubType); 293 294 configurationMap.put(WizardBindingConfigurationStep.SERVICE_NAME, serviceName); 296 configurationMap.put(WizardBindingConfigurationStep.SERVICEPORT_NAME, servicePortName); 297 298 this.mTempModel.startTransaction(); 299 cleanUpBindings(); 300 301 BindingGenerator bGen = new BindingGenerator(this.mTempModel, this.mPortType, configurationMap); 302 bGen.execute(); 303 304 this.mBinding = bGen.getBinding(); 305 this.mService = bGen.getService(); 306 this.mPort = bGen.getPort(); 307 308 if(this.mBinding != null) { 309 String targetNamespace = (String ) wiz.getProperty(WsdlPanel.WSDL_TARGETNAMESPACE); 310 List <ValidationInfo> vAllInfos =new ArrayList <ValidationInfo>(); 311 312 List <ValidationInfo> vBindingInfos = bindingSubType.getMProvider().validate(this.mBinding); 313 if(vBindingInfos != null) { 314 vAllInfos.addAll(vBindingInfos); 315 } 316 317 if(this.mPort != null) { 318 List <ValidationInfo> vPortInfos = bindingSubType.getMProvider().validate(this.mPort); 319 if(vPortInfos != null) { 320 vAllInfos.addAll(vPortInfos); 321 } 322 } 323 if(vAllInfos != null && vAllInfos.size() > 0) { 324 ValidationInfo vInfo = vAllInfos.get(0); 325 this.mBindingSubTypeError = vInfo.getDescription(); 326 IOProvider.getDefault().getStdOut().print(this.mBindingSubTypeError); 327 validate(); 328 } else { 329 this.mBindingSubTypeError = null; 331 validate(); 332 if(this.mBinding != null) { 333 bindingSubType.getMProvider().postProcess(targetNamespace, this.mBinding); 334 } 335 if(this.mPort != null) { 336 bindingSubType.getMProvider().postProcess(targetNamespace, this.mPort); 337 } 338 this.wiz.putProperty(BINDING, this.mBinding); 339 this.wiz.putProperty(SERVICE, this.mService); 340 this.wiz.putProperty(PORT, this.mPort); 341 } 342 } 343 344 this.mTempModel.endTransaction(); 345 } 346 } 347 348 class TextChangeListener implements DocumentListener { 349 350 public void changedUpdate(DocumentEvent e) { 351 validate(); 352 } 353 354 public void insertUpdate(DocumentEvent e) { 355 validate(); 356 } 357 358 public void removeUpdate(DocumentEvent e) { 359 validate(); 360 } 361 362 } 363 364 class BindingConfigurationListener implements PropertyChangeListener { 365 public void propertyChange(PropertyChangeEvent evt) { 366 String propertyName = evt.getPropertyName(); 367 if(BindingConfigurationPanel.PROP_BINDING_SUBTYPE.equals(propertyName)) { 368 LocalizedTemplate bindingSubType = (LocalizedTemplate) evt.getNewValue(); 369 processBindingSubType(bindingSubType); 370 } else if(BindingConfigurationPanel.PROP_BINDING_TYPE.equals(propertyName)) { 371 processBindingSubType(mPanel.getBindingSubType()); 372 } 373 } 374 } 375 } 376 377 | Popular Tags |