1 19 package org.netbeans.modules.websvc.core.jaxws.nodes; 20 21 import java.awt.Dialog ; 22 import java.io.IOException ; 23 import java.net.URL ; 24 import java.util.ArrayList ; 25 import java.util.Collection ; 26 import java.util.List ; 27 import javax.swing.Action ; 28 import org.apache.tools.ant.module.api.support.ActionUtils; 29 import org.netbeans.api.project.FileOwnerQuery; 30 import org.netbeans.api.project.Project; 31 import org.netbeans.modules.j2ee.deployment.devmodules.spi.J2eeModuleProvider; 32 import org.netbeans.modules.websvc.api.jaxws.client.JAXWSClientSupport; 33 import org.netbeans.modules.websvc.api.jaxws.project.GeneratedFilesHelper; 34 import org.netbeans.modules.websvc.api.jaxws.project.config.Binding; 35 import org.netbeans.modules.websvc.api.jaxws.wsdlmodel.WsdlModel; 36 import org.netbeans.modules.websvc.api.jaxws.wsdlmodel.WsdlModelListener; 37 import org.netbeans.modules.websvc.api.jaxws.wsdlmodel.WsdlModeler; 38 import org.netbeans.modules.websvc.api.jaxws.wsdlmodel.WsdlModelerFactory; 39 import org.netbeans.modules.websvc.core.jaxws.actions.JaxWsRefreshClientAction; 40 import org.netbeans.modules.websvc.core.jaxws.bindings.model.BindingsHandler; 41 import org.netbeans.modules.websvc.core.jaxws.bindings.model.BindingsHandlerChain; 42 import org.netbeans.modules.websvc.core.jaxws.bindings.model.BindingsHandlerChains; 43 import org.netbeans.modules.websvc.core.jaxws.bindings.model.BindingsHandlerClass; 44 import org.netbeans.modules.websvc.core.jaxws.bindings.model.BindingsModel; 45 import org.netbeans.modules.websvc.core.jaxws.bindings.model.BindingsModelFactory; 46 import org.netbeans.modules.websvc.core.jaxws.bindings.model.DefinitionsBindings; 47 import org.netbeans.modules.websvc.core.jaxws.bindings.model.GlobalBindings; 48 import org.netbeans.modules.websvc.core.webservices.action.ConfigureHandlerAction; 49 import org.netbeans.modules.websvc.core.webservices.action.ConfigureHandlerCookie; 50 import org.netbeans.modules.websvc.core.webservices.ui.panels.MessageHandlerPanel; 51 import org.netbeans.modules.websvc.core.wseditor.support.EditWSAttributesCookie; 52 import org.netbeans.modules.websvc.core.wseditor.support.WSEditAttributesAction; 53 import org.netbeans.modules.websvc.jaxws.api.JaxWsRefreshCookie; 54 import org.netbeans.modules.websvc.api.jaxws.project.config.JaxWsModel; 55 import org.netbeans.modules.websvc.api.jaxws.project.config.Client; 56 import org.netbeans.modules.websvc.core.wseditor.support.EditWSAttributesCookieImpl; 57 import org.netbeans.modules.xml.retriever.catalog.Utilities; 58 import org.netbeans.modules.xml.xam.ModelSource; 59 import org.openide.DialogDescriptor; 60 import org.openide.DialogDisplayer; 61 import org.openide.ErrorManager; 62 import org.openide.NotifyDescriptor; 63 import org.openide.actions.DeleteAction; 64 import org.openide.actions.OpenAction; 65 import org.openide.actions.OpenLocalExplorerAction; 66 import org.openide.actions.PropertiesAction; 67 import org.openide.cookies.EditCookie; 68 import org.openide.cookies.OpenCookie; 69 import org.openide.execution.ExecutorTask; 70 import org.openide.filesystems.FileLock; 71 import org.openide.filesystems.FileObject; 72 import org.openide.filesystems.FileStateInvalidException; 73 import org.openide.loaders.DataObject; 74 import org.openide.nodes.AbstractNode; 75 import org.openide.nodes.Node; 76 import org.openide.util.HelpCtx; 77 import org.openide.util.NbBundle; 78 import org.openide.util.actions.SystemAction; 79 import org.openide.util.lookup.AbstractLookup; 80 import org.openide.util.lookup.InstanceContent; 81 82 public class JaxWsClientNode extends AbstractNode implements OpenCookie, JaxWsRefreshCookie, 83 ConfigureHandlerCookie{ 84 Client client; 85 FileObject srcRoot; 86 JaxWsModel jaxWsModel; 87 InstanceContent content; 88 private FileObject wsdlFileObject; 89 boolean modelGenerationFinished; 90 91 public JaxWsClientNode(JaxWsModel jaxWsModel, Client client, FileObject srcRoot) { 92 this(jaxWsModel, client, srcRoot, new InstanceContent()); 93 } 94 95 private JaxWsClientNode(JaxWsModel jaxWsModel, Client client, FileObject srcRoot, InstanceContent content) { 96 super(new JaxWsClientChildren(client),new AbstractLookup(content)); 97 this.jaxWsModel=jaxWsModel; 98 this.client=client; 99 this.srcRoot=srcRoot; 100 this.content = content; 101 setName(client.getName()); 102 setDisplayName(client.getName()); 103 content.add(this); 104 content.add(client); 105 content.add(srcRoot); 106 WsdlModeler modeler = getWsdlModeler(); 107 if (modeler!=null) { 108 changeIcon(); 109 modeler.generateWsdlModel(new WsdlModelListener(){ 110 public void modelCreated(WsdlModel model) { 111 modelGenerationFinished=true; 112 changeIcon(); 113 } 114 }); 115 } 116 content.add(new EditWSAttributesCookieImpl(this, jaxWsModel)); 117 } 118 119 public String getShortDescription() { 120 return client.getWsdlUrl(); 121 } 122 123 private static final java.awt.Image WAITING_BADGE = 124 org.openide.util.Utilities.loadImage( "org/netbeans/modules/websvc/core/webservices/ui/resources/waiting.png"); private static final java.awt.Image ERROR_BADGE = 126 org.openide.util.Utilities.loadImage( "org/netbeans/modules/websvc/core/webservices/ui/resources/error-badge.gif" ); private static final java.awt.Image SERVICE_BADGE = 128 org.openide.util.Utilities.loadImage( "org/netbeans/modules/websvc/core/webservices/ui/resources/XMLServiceDataIcon.gif" ); 130 public java.awt.Image getIcon(int type) { 131 if (((JaxWsClientChildren)getChildren()).getWsdlModel()!=null) { 132 return SERVICE_BADGE; 133 } else { 134 WsdlModeler wsdlModeler = getWsdlModeler(); 135 if (wsdlModeler!=null && wsdlModeler.getCreationException()==null) { 136 if (modelGenerationFinished) 137 return SERVICE_BADGE; 138 else 139 return org.openide.util.Utilities.mergeImages(SERVICE_BADGE, WAITING_BADGE, 15, 8); 140 } else { 141 java.awt.Image dirtyNodeImage = org.openide.util.Utilities.mergeImages(SERVICE_BADGE, ERROR_BADGE, 6, 6); 142 if (modelGenerationFinished) 143 return dirtyNodeImage; 144 else 145 return org.openide.util.Utilities.mergeImages(dirtyNodeImage, WAITING_BADGE, 15, 8); 146 } 147 } 148 } 149 150 public java.awt.Image getOpenedIcon(int type){ 151 return getIcon( type); 152 } 153 154 public void open() { 155 EditCookie ec = getEditCookie(); 156 if (ec != null) { 157 ec.edit(); 158 } 159 } 160 161 void changeIcon() { 162 fireIconChange(); 163 } 164 173 private EditCookie getEditCookie() { 174 try { 175 FileObject wsdlFo = 176 JAXWSClientSupport.getJaxWsClientSupport(srcRoot).getLocalWsdlFolderForClient(client.getName(),false).getFileObject(client.getLocalWsdlFile()); 177 assert wsdlFo!=null: "Cannot find local WSDL file"; if (wsdlFo!=null) { 179 DataObject dObj = DataObject.find(wsdlFo); 180 return (EditCookie)dObj.getCookie(EditCookie.class); 181 } 182 } catch (java.io.IOException ex) { 183 ErrorManager.getDefault().log(ex.getLocalizedMessage()); 184 return null; 185 } 186 return null; 187 } 188 189 public Action getPreferredAction() { 190 return SystemAction.get(OpenAction.class); 191 } 192 193 public Action [] getActions(boolean context) { 195 return new SystemAction[] { 196 SystemAction.get(OpenAction.class), 197 SystemAction.get(JaxWsRefreshClientAction.class), 198 null, 199 SystemAction.get(WSEditAttributesAction.class), 200 null, 201 SystemAction.get(ConfigureHandlerAction.class), 202 null, 203 SystemAction.get(DeleteAction.class), 204 null, 205 SystemAction.get(OpenLocalExplorerAction.class), 206 null, 207 SystemAction.get(PropertiesAction.class), 208 }; 209 } 210 211 public HelpCtx getHelpCtx() { 212 return HelpCtx.DEFAULT_HELP; 213 } 214 215 public boolean canDestroy() { 217 return true; 218 } 219 220 public void destroy() throws java.io.IOException { 221 String clientName = client.getName(); 222 NotifyDescriptor.Confirmation notifyDesc = 223 new NotifyDescriptor.Confirmation(NbBundle.getMessage(JaxWsClientNode.class, "MSG_CONFIRM_DELETE", clientName)); 224 DialogDisplayer.getDefault().notify(notifyDesc); 225 if(notifyDesc.getValue() == NotifyDescriptor.YES_OPTION){ 226 227 JAXWSClientSupport support = JAXWSClientSupport.getJaxWsClientSupport(srcRoot); 228 FileObject localWsdlFolder = support.getLocalWsdlFolderForClient(clientName,false); 230 if (localWsdlFolder!=null) { 231 FileObject clientArtifactsFolder = localWsdlFolder.getParent(); 232 FileLock lock=null; 233 try { 234 lock = clientArtifactsFolder.lock(); 235 clientArtifactsFolder.delete(lock); 236 } finally { 237 if (lock!=null) lock.releaseLock(); 238 } 239 } 240 241 Project project = FileOwnerQuery.getOwner(srcRoot); 242 if (client.getWsdlUrl().startsWith("file:")) { if (project.getLookup().lookup(J2eeModuleProvider.class)!=null) { 245 FileObject webInfClientFolder = findWsdlFolderForClient(support, clientName); 246 if (webInfClientFolder!=null) { 247 FileObject webInfClientRootFolder = webInfClientFolder.getParent(); 248 FileLock lock=null; 249 try { 250 lock = webInfClientFolder.lock(); 251 webInfClientFolder.delete(lock); 252 } finally { 253 if (lock!=null) lock.releaseLock(); 254 } 255 if (webInfClientRootFolder.getChildren().length==0) { 256 try { 257 lock = webInfClientRootFolder.lock(); 258 webInfClientRootFolder.delete(lock); 259 } finally { 260 if (lock!=null) lock.releaseLock(); 261 } 262 } 263 } 264 } 265 } 266 FileObject buildImplFo = project.getProjectDirectory().getFileObject(GeneratedFilesHelper.BUILD_IMPL_XML_PATH); 268 try { 269 ExecutorTask wsimportTask = 270 ActionUtils.runTarget(buildImplFo, 271 new String []{"wsimport-client-clean-"+clientName},null); wsimportTask.waitFinished(); 273 } catch (java.io.IOException ex) { 274 ErrorManager.getDefault().log(ex.getLocalizedMessage()); 275 } catch (IllegalArgumentException ex) { 276 ErrorManager.getDefault().log(ex.getLocalizedMessage()); 277 } 278 support.removeServiceClient(clientName); 280 super.destroy(); 281 } 282 } 283 284 287 public void refreshService(boolean downloadWsdl) { 288 if (downloadWsdl) { 289 int result = RefreshClientDialog.open(client.getWsdlUrl()); 290 if (RefreshClientDialog.CLOSE==result) return; 291 if (RefreshClientDialog.DOWNLOAD_WSDL==result){ 292 removeWsdlFolderContents(); 293 ((JaxWsClientChildren)getChildren()).refreshKeys(true); 294 } else 295 ((JaxWsClientChildren)getChildren()).refreshKeys(false); 296 } else { 297 Object result = DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message( 298 NbBundle.getMessage(JaxWsClientNode.class, 299 "HINT_RefreshClient"))); ((JaxWsClientChildren)getChildren()).refreshKeys(false); 301 } 302 } 303 304 private void removeWsdlFolderContents(){ 305 FileObject wsdlFolder = getJAXWSClientSupport().getLocalWsdlFolderForClient(getName(), false); 306 if(wsdlFolder != null){ 307 FileLock lock = null; 308 309 FileObject[] files = wsdlFolder.getChildren(); 310 for(int i = 0; i < files.length; i++){ 311 try{ 312 FileObject file = files[i]; 313 lock = file.lock(); 314 file.delete(lock); 315 }catch(IOException e){ 316 ErrorManager.getDefault().notify(e); 317 } 318 finally{ 319 if(lock != null){ 320 lock.releaseLock(); 321 lock = null; 322 } 323 } 324 } 325 } 326 } 327 328 329 public void configureHandler() { 330 Project project = FileOwnerQuery.getOwner(srcRoot); 331 ArrayList <String > handlerClasses = new ArrayList <String >(); 332 BindingsModel bindingsModel = getBindingsModel(); 333 if(bindingsModel != null){ GlobalBindings gb = bindingsModel.getGlobalBindings(); 335 if(gb != null){ 336 DefinitionsBindings db = gb.getDefinitionsBindings(); 337 if(db != null){ 338 BindingsHandlerChains handlerChains = db.getHandlerChains(); 339 BindingsHandlerChain handlerChain = 341 handlerChains.getHandlerChains().iterator().next(); 342 Collection <BindingsHandler> handlers = handlerChain.getHandlers(); 343 for(BindingsHandler handler : handlers){ 344 BindingsHandlerClass handlerClass = handler.getHandlerClass(); 345 handlerClasses.add(handlerClass.getClassName()); 346 } 347 } 348 } 349 } 350 final MessageHandlerPanel panel = new MessageHandlerPanel(project, 351 (String [])handlerClasses.toArray(new String [handlerClasses.size()]), true, client.getName()); 352 String title = NbBundle.getMessage(JaxWsNode.class,"TTL_MessageHandlerPanel"); 353 DialogDescriptor dialogDesc = new DialogDescriptor(panel, title); 354 dialogDesc.setButtonListener(new ClientHandlerButtonListener(panel, 355 bindingsModel, client, this, jaxWsModel)); 356 Dialog dialog = DialogDisplayer.getDefault().createDialog(dialogDesc); 357 dialog.setVisible(true); 358 } 359 360 private BindingsModel getBindingsModel(){ 361 String handlerBindingFile = client.getHandlerBindingFile(); 362 BindingsModel bindingsModel = null; 363 364 try{ 366 if(handlerBindingFile != null){ 367 JAXWSClientSupport support = JAXWSClientSupport.getJaxWsClientSupport(srcRoot); 368 FileObject bindingsFolder = support.getBindingsFolderForClient(getName(), false); 369 if(bindingsFolder != null){ 370 FileObject handlerBindingFO = bindingsFolder.getFileObject(handlerBindingFile); 371 if(handlerBindingFO != null){ 372 ModelSource ms = Utilities.getModelSource(handlerBindingFO, true); 373 bindingsModel = BindingsModelFactory.getDefault().getModel(ms); 374 } 375 } 376 } 377 }catch(Exception e){ 378 ErrorManager.getDefault().notify(e); 379 return null; 380 } 381 return bindingsModel; 382 } 383 384 WsdlModeler getWsdlModeler() { 385 if (getLocalWsdl()!=null) { 386 try { 387 WsdlModeler modeler = WsdlModelerFactory.getDefault().getWsdlModeler(wsdlFileObject.getURL()); 388 if (modeler!=null) { 389 String packageName = client.getPackageName(); 390 if (packageName!=null && client.isPackageNameForceReplace()) { 391 modeler.setPackageName(packageName); 393 } else { 394 modeler.setPackageName(null); 395 } 396 modeler.setCatalog(getJAXWSClientSupport().getCatalog()); 397 setBindings(modeler); 398 return modeler; 399 } 400 } catch (FileStateInvalidException ex) { 401 ErrorManager.getDefault().log(ex.getLocalizedMessage()); 402 } 403 } else { 404 ErrorManager.getDefault().log(ErrorManager.ERROR, NbBundle.getMessage(JaxWsNode.class,"ERR_missingLocalWsdl")); 405 } 406 return null; 407 } 408 409 FileObject getLocalWsdl() { 410 if (wsdlFileObject==null) { 411 FileObject localWsdlocalFolder = getJAXWSClientSupport().getLocalWsdlFolderForClient(client.getName(),false); 412 if (localWsdlocalFolder!=null) 413 wsdlFileObject=localWsdlocalFolder.getFileObject(client.getLocalWsdlFile()); 414 } 415 return wsdlFileObject; 416 } 417 418 JAXWSClientSupport getJAXWSClientSupport() { 419 return JAXWSClientSupport.getJaxWsClientSupport(srcRoot); 420 } 421 422 private void setBindings(WsdlModeler wsdlModeler) { 423 Binding[] extbindings = client.getBindings(); 424 if (extbindings==null || extbindings.length==0) { 425 wsdlModeler.setJAXBBindings(null); 426 return; 427 } 428 String [] bindingFiles = new String [extbindings.length]; 429 for(int i = 0; i < extbindings.length; i++){ 430 bindingFiles[i] = extbindings[i].getFileName(); 431 } 432 433 FileObject bindingsFolder = getJAXWSClientSupport().getBindingsFolderForClient(getName(),true); 434 List <URL > list = new ArrayList <URL >(); 435 for (int i=0;i<bindingFiles.length;i++) { 436 FileObject fo = bindingsFolder.getFileObject(bindingFiles[i]); 437 try { 438 list.add(fo.getURL()); 439 } catch (FileStateInvalidException ex) { 440 } 442 } 443 URL [] bindings = new URL [list.size()]; 444 list.<URL >toArray(bindings); 445 wsdlModeler.setJAXBBindings(bindings); 446 } 447 448 void setModelGenerationFinished(boolean value) { 449 modelGenerationFinished=value; 450 } 451 452 JaxWsModel getJaxWsModel() { 453 return jaxWsModel; 454 } 455 456 private FileObject findWsdlFolderForClient(JAXWSClientSupport support, String name) throws IOException { 457 FileObject globalWsdlFolder = support.getWsdlFolder(false); 458 if (globalWsdlFolder!=null) { 459 return globalWsdlFolder.getFileObject("client/"+name); 460 } 461 return null; 462 } 463 } 464 | Popular Tags |