1 19 20 package org.netbeans.modules.j2ee.refactoring.moveclass; 21 22 import java.io.File ; 23 import java.io.IOException ; 24 import java.text.MessageFormat ; 25 import java.util.ArrayList ; 26 import java.util.Collection ; 27 import java.util.Iterator ; 28 import java.util.List ; 29 import java.util.Map ; 30 import javax.jmi.reflect.RefObject; 31 import org.netbeans.api.java.project.JavaProjectConstants; 32 import org.netbeans.api.project.FileOwnerQuery; 33 import org.netbeans.api.project.Project; 34 import org.netbeans.api.project.ProjectManager; 35 import org.netbeans.api.project.ProjectUtils; 36 import org.netbeans.api.project.SourceGroup; 37 import org.netbeans.api.project.Sources; 38 import org.netbeans.modules.j2ee.dd.api.web.Filter; 39 import org.netbeans.modules.j2ee.dd.api.web.Listener; 40 import org.netbeans.modules.j2ee.dd.api.web.Servlet; 41 import org.netbeans.modules.j2ee.dd.api.web.WebApp; 42 import org.netbeans.jmi.javamodel.JavaClass; 43 import org.netbeans.jmi.javamodel.Resource; 44 import org.netbeans.modules.j2ee.dd.api.webservices.PortComponent; 45 import org.netbeans.modules.j2ee.dd.api.webservices.PortComponentHandler; 46 import org.netbeans.modules.j2ee.dd.api.webservices.WebserviceDescription; 47 import org.netbeans.modules.j2ee.dd.api.webservices.Webservices; 48 import org.netbeans.modules.j2ee.refactoring.Utility; 49 import org.netbeans.modules.javacore.api.JavaModel; 50 import org.netbeans.modules.javacore.internalapi.ExternalChange; 51 import org.netbeans.modules.javacore.internalapi.JavaMetamodel; 52 import org.netbeans.modules.refactoring.api.MoveClassRefactoring; 53 import org.netbeans.modules.refactoring.api.Problem; 54 import org.netbeans.modules.refactoring.api.RefactoringElement; 55 import org.netbeans.modules.refactoring.spi.RefactoringElementsBag; 56 import org.netbeans.modules.refactoring.spi.RefactoringElementImplementation; 57 import org.netbeans.modules.web.api.webmodule.WebModule; 58 import org.netbeans.modules.websvc.api.webservices.WebServicesSupport; 59 import org.netbeans.modules.websvc.spi.webservices.WebServicesConstants; 60 import org.netbeans.modules.websvc.wsdl.WsCompileConfigDataObject; 61 import org.netbeans.modules.websvc.wsdl.config.api.Configuration; 62 import org.netbeans.modules.websvc.wsdl.xmlutils.XMLJ2eeDataObject; 63 import org.netbeans.spi.project.support.ant.AntProjectHelper; 64 import org.netbeans.spi.project.support.ant.EditableProperties; 65 import org.openide.ErrorManager; 66 import org.openide.filesystems.FileObject; 67 import org.openide.filesystems.FileUtil; 68 import org.openide.loaders.DataFolder; 69 import org.openide.loaders.DataObject; 70 import org.openide.loaders.DataObjectNotFoundException; 71 import org.openide.util.NbBundle; 72 73 77 public final class WebservicesXmlMoveClassRefactoring { 78 79 private static final ErrorManager err = ErrorManager.getDefault().getInstance("org.netbeans.modules.j2ee.refactoring.rename"); 81 public WebservicesXmlMoveClassRefactoring() { } 82 83 85 public Problem prepare(MoveClassRefactoring moveClassRefactor, Collection resources, RefactoringElementsBag refactoringElements) { 86 87 Problem problem = null; 88 89 for (Iterator i = resources.iterator(); i.hasNext();) { 90 91 boolean isSEIMove = false; 92 93 Resource resource = (Resource) i.next(); 94 FileObject fo = JavaModel.getFileObject(resource); 95 96 err.log("resource package name: " + resource.getPackageName()); 97 err.log("resource: name " + resource.getName()); 98 WebServicesSupport wsm = WebServicesSupport.getWebServicesSupport(fo); 99 if (wsm != null) { 101 FileObject webservicesXmlFO = wsm.getWebservicesDD(); 102 Webservices webservicesXmlDD = null; 103 try { 104 webservicesXmlDD = org.netbeans.modules.j2ee.dd.api.webservices.DDProvider.getDefault().getDDRoot(webservicesXmlFO); 105 } catch (IOException ioe) { 106 } 108 109 if ((webservicesXmlDD != null) && (webservicesXmlDD.getStatus()!=Webservices.STATE_INVALID_UNPARSABLE)) { 110 List classes = resource.getClassifiers(); 111 err.log("Classes in resource: " + classes); 112 113 for (int j=0; j < classes.size(); j++ ) { 114 JavaClass jClass = (JavaClass)classes.get(j); 115 err.log("javaclass: "+ jClass); 116 117 String name = jClass.getName(); 118 err.log("name: " + name); 119 120 String oldPackage = name.substring(0, name.lastIndexOf('.')); 121 err.log("oldPackage: " + oldPackage); 122 123 String targetPackage = moveClassRefactor.getTargetPackageName(resource); 124 err.log("targetPackage: " + targetPackage); 125 126 String newName = targetPackage + "." + jClass.getSimpleName(); 127 err.log("newname: " + newName); 128 129 WebserviceDescription[] wservices = webservicesXmlDD.getWebserviceDescription(); 130 err.log("Web Services: " + wservices); 131 if ((wservices != null) && (wservices.length > 0)) { 132 for (int w=0; w < wservices.length; w++) { 133 WebserviceDescription webService = (WebserviceDescription)wservices[w]; 134 err.log("Web Service: " + webService); 135 136 137 PortComponent[] ports = webService.getPortComponent(); 138 err.log("Ports: " + ports); 139 if ((ports != null) && (ports.length > 0)) { 140 for (int p=0; p < ports.length; p++) { 141 142 143 PortComponent portComponent = (PortComponent)ports[p]; 144 err.log("Port Component: " + portComponent); 145 String serviceEndpointInterface = portComponent.getServiceEndpointInterface(); 146 err.log("serviceEndpointInterface: " + serviceEndpointInterface); 147 148 PortComponentHandler[] handlers = portComponent.getHandler(); 149 for (int k = 0; k < handlers.length; k++) { 150 if (name.equals(handlers[k].getHandlerClass())){ 151 RefactoringElementImplementation elem = new WebservicesHandlerMoveClassRefactoringElement(webservicesXmlDD, name, newName, handlers[k], webservicesXmlFO); 152 refactoringElements.add(moveClassRefactor, elem); 153 } 154 } 155 156 if ((serviceEndpointInterface != null) && (serviceEndpointInterface.equals(name))) { 157 isSEIMove = true; 158 RefactoringElementImplementation elem = new WebservicesSEIMoveClassRefactoringElement(webservicesXmlDD, name, newName, portComponent, webservicesXmlFO); 159 refactoringElements.add(moveClassRefactor, elem); 160 } 161 162 167 String portName = portComponent.getPortComponentName(); 168 Project project = FileOwnerQuery.getOwner(webservicesXmlFO); 169 err.log("Project: " + project); 170 Map properties = wsm.getAntProjectHelper().getStandardPropertyEvaluator().getProperties(); 171 if (err.isLoggable(ErrorManager.INFORMATIONAL)) { 172 err.log("Properties: " + properties); 173 } 174 String propertyName = portName + WebServicesConstants.CONFIG_PROP_SUFFIX; 175 err.log("Property name: " + propertyName); 176 String propertyValue = (String )properties.get(propertyName); 177 err.log("Property value: " + propertyValue); 178 if (propertyValue != null) { FileObject wsConfigXmlFO = null; 180 181 File f = new File (propertyValue); 182 if (f.isAbsolute()) { 183 wsConfigXmlFO = FileUtil.toFileObject(f); 184 } else { 185 wsConfigXmlFO = project.getProjectDirectory().getFileObject(propertyValue); 186 } 187 if (wsConfigXmlFO != null) { 188 Configuration wsConfigXmlDD = null; 189 try { 190 wsConfigXmlDD = org.netbeans.modules.websvc.wsdl.config.api.DDProvider.getDefault().getDDRoot(wsConfigXmlFO); 191 } catch (IOException ioe) { 192 } 194 DataObject data = null; 195 try { 196 data = DataObject.find(wsConfigXmlFO); 197 } catch (DataObjectNotFoundException notfoundexc) { 198 } 200 err.log("DataObject: " + data); 201 if ((data != null) && (wsConfigXmlDD != null)) { 202 org.netbeans.modules.websvc.wsdl.config.api.Service service = wsConfigXmlDD.getService(); 203 if (service != null) { 204 String packageName = service.getPackageName(); 205 err.log("Package name: " + packageName); 206 if ((packageName != null) && (packageName.equals(oldPackage))) { 207 if (isSEIMove) { 208 if (!isConfigXmlAlreadyMoved(refactoringElements, wsConfigXmlFO)) { 209 RefactoringElementImplementation elemFile = new WebservicesConfigXmlMoveClassRefactoringElement(data, moveClassRefactor.getTargetClassPathRoot(), moveClassRefactor.getTargetPackageName(fo)); 210 refactoringElements.add(moveClassRefactor, elemFile); 211 } 212 RefactoringElementImplementation elemPkg = new WebservicesConfigXmlPackageMoveClassRefactoringElement(data, jClass.getResource().getPackageName(), targetPackage); 213 refactoringElements.add(moveClassRefactor, elemPkg); 214 targetPackage = targetPackage.replace('.', '/'); 215 216 Sources srcs = ProjectUtils.getSources(project); 217 if (srcs != null) { 218 SourceGroup[] sourceGroups = srcs.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA); 219 SourceGroup srcGroup = null; 220 boolean found = false; 221 for (int k=0; k < sourceGroups.length; k++) { 222 srcGroup = sourceGroups[k]; 223 if (FileUtil.isParentOf(srcGroup.getRootFolder(), wsConfigXmlFO)) { 224 found = true; 225 break; 226 } 227 } 228 if (found) { 229 String relativePath = FileUtil.getRelativePath(srcGroup.getRootFolder(), wsConfigXmlFO); 230 int index = propertyValue.indexOf(relativePath); 231 String newValue = propertyValue.substring(0, 9) + 232 propertyValue.substring(index, propertyValue.length()).replaceFirst(packageName, targetPackage); 233 234 err.log("newvalue: " + newValue); 235 err.log("moving SEI, so move the config xml file with it, too"); 236 RefactoringElementImplementation elem2 = new WebservicesProjectMoveClassRefactoringElement(data, wsm.getAntProjectHelper(), propertyName, propertyValue, newValue, targetPackage); 237 refactoringElements.add(moveClassRefactor, elem2); 238 } 239 } 240 } 241 } 242 org.netbeans.modules.websvc.wsdl.config.api.Interface[] interfaces = service.getInterface(); 243 if ((interfaces != null) && (interfaces.length > 0)) { 244 for (int ii=0; ii < interfaces.length; ii++) { 245 org.netbeans.modules.websvc.wsdl.config.api.Interface iface = interfaces[ii]; 246 String servant = iface.getServantName(); 247 String iname = iface.getName(); 248 err.log("Servant: " + servant); 249 err.log("Interface: " + iname); 250 if ((servant != null) && (servant.equals(name))) { 251 RefactoringElementImplementation elem = new WebservicesConfigXmlServantMoveClassRefactoringElement(data, name, newName); 252 refactoringElements.add(moveClassRefactor, elem); 253 } 254 if ((iname != null) && (iname.equals(name))) { 255 RefactoringElementImplementation elem = new WebservicesConfigXmlInterfaceMoveClassRefactoringElement(data, name, newName); 256 refactoringElements.add(moveClassRefactor, elem); 257 } 258 } 259 } 260 } 261 } else { 262 Object [] args = new Object [] {wsConfigXmlFO.getPath()}; 263 String msg = MessageFormat.format(NbBundle.getMessage(WebservicesXmlMoveClassRefactoring.class, "TXT_WebservicesConfigXmlMoveClassInvalidProblem"), args); 264 Problem newProblem = new Problem(false, msg); 265 problem = Utility.addProblemsToEnd(problem, newProblem); 266 } 267 } 268 } 269 } 270 } 271 } 272 } 273 } 274 } else if (webservicesXmlDD != null) { 275 Problem newProblem = new Problem(false, NbBundle.getMessage(WebservicesXmlMoveClassRefactoring.class, "TXT_WebservicesXmlMoveClassInvalidProblem")); 276 if (problem == null) { 277 problem = newProblem; 278 } else { 279 if (newProblem != null) problem.setNext(newProblem); 280 } 281 } 282 } 283 } return problem; 285 } 286 287 private boolean isConfigXmlAlreadyMoved(RefactoringElementsBag refactoringElements, FileObject file) { 288 Collection c = refactoringElements.getSession().getRefactoringElements(); 289 Iterator refElems = c.iterator(); 290 while (refElems.hasNext()) { 291 RefactoringElement refElem = (RefactoringElement)refElems.next(); 292 FileObject f = refElem.getParentFile(); 293 if (f != null) { 294 DataObject d=null; 295 try { 296 d = DataObject.find(f); 297 } catch (Exception e) { 298 299 } 300 if ( (d!=null) && (d instanceof WsCompileConfigDataObject)) { 301 return file.equals(((WsCompileConfigDataObject)d).getPrimaryFile()); 302 } 303 } 304 } 305 return false; 306 } 307 308 public final class WebservicesSEIMoveClassRefactoringElement extends AbstractMoveClassRefactoringElement implements ExternalChange { 309 310 protected Webservices webservicesXmlDD; 311 private PortComponent pc; 312 313 314 public WebservicesSEIMoveClassRefactoringElement(Webservices webservicesXmlDD, String oldName, String newName, PortComponent pc, FileObject parentFile) { 315 this.webservicesXmlDD = webservicesXmlDD; 316 this.pc = pc; 317 this.oldName = oldName; 318 this.newName = newName; 319 this.parentFile = parentFile; 320 } 321 322 325 public String getDisplayText() { 326 Object [] args = new Object [] {parentFile.getNameExt(), oldName, newName}; 327 return MessageFormat.format(NbBundle.getMessage(WebservicesXmlMoveClassRefactoring.class, "TXT_WebservicesXmlSEIMoveClass"), args); 328 } 329 330 332 public void performChange() { 333 JavaMetamodel.getManager().registerExtChange(this); 334 } 335 336 public void performExternalChange() { 337 if (pc != null) { 338 pc.setServiceEndpointInterface(newName); 339 try { 340 webservicesXmlDD.write(parentFile); 341 } catch (IOException ioe) { 342 } 344 } 345 } 346 347 public void undoExternalChange() { 348 if (pc != null) { 349 pc.setServiceEndpointInterface(oldName); 350 try { 351 webservicesXmlDD.write(parentFile); 352 } catch (IOException ioe) { 353 } 355 } 356 } 357 } 358 359 362 public final class WebservicesHandlerMoveClassRefactoringElement extends AbstractMoveClassRefactoringElement implements ExternalChange { 363 364 protected Webservices webservicesXmlDD; 365 private PortComponentHandler handler; 366 367 public WebservicesHandlerMoveClassRefactoringElement(Webservices webservicesXmlDD, String oldName, String newName, PortComponentHandler handler, FileObject parentFile) { 368 this.webservicesXmlDD = webservicesXmlDD; 369 this.handler = handler; 370 this.oldName = oldName; 371 this.newName = newName; 372 this.parentFile = parentFile; 373 } 374 375 public String getDisplayText() { 376 Object [] args = new Object [] {parentFile.getNameExt(), oldName, newName}; 377 return MessageFormat.format(NbBundle.getMessage(WebservicesXmlMoveClassRefactoring.class, "TXT_WebservicesXmlHandlerMoveClass"), args); 378 } 379 380 public void performChange() { 381 JavaMetamodel.getManager().registerExtChange(this); 382 } 383 384 public void performExternalChange() { 385 handler.setHandlerClass(newName); 386 write(); 387 } 388 389 public void undoExternalChange() { 390 handler.setHandlerClass(oldName); 391 write(); 392 } 393 394 private void write(){ 395 try { 396 webservicesXmlDD.write(parentFile); 397 } catch (IOException ioe) { 398 ErrorManager.getDefault().notify(ioe); 399 } 400 } 401 } 402 403 public final class WebservicesConfigXmlPackageMoveClassRefactoringElement extends AbstractMoveClassRefactoringElement implements ExternalChange { 404 405 private DataObject data = null; 406 407 408 public WebservicesConfigXmlPackageMoveClassRefactoringElement(DataObject data, String oldName, String newName) { 409 this.data = data; 410 this.oldName = oldName; 411 this.newName = newName; 412 } 413 414 417 public String getDisplayText() { 418 Object [] args = new Object [] {data.getPrimaryFile(), oldName, newName}; 419 return MessageFormat.format(NbBundle.getMessage(WebservicesXmlMoveClassRefactoring.class, "TXT_WebservicesConfigXmlPackageMoveClass"), args); 420 } 421 422 425 public FileObject getParentFile() { 426 if (data != null) { 427 return data.getPrimaryFile(); 428 } 429 return null; 430 } 431 432 434 public void performChange() { 435 JavaMetamodel.getManager().registerExtChange(this); 436 } 437 438 public void performExternalChange() { 439 if (data != null) { 440 FileObject wsConfigXmlFO = data.getPrimaryFile(); 441 Configuration wsConfigXmlDD = null; 442 try { 443 wsConfigXmlDD = org.netbeans.modules.websvc.wsdl.config.api.DDProvider.getDefault().getDDRoot(wsConfigXmlFO); 444 } catch (IOException ioe) { 445 } 447 if (wsConfigXmlDD != null) { 448 org.netbeans.modules.websvc.wsdl.config.api.Service service = wsConfigXmlDD.getService(); 449 if (service != null) { 450 service.setPackageName(newName); 451 try { 452 wsConfigXmlDD.write(wsConfigXmlFO); 453 } catch (IOException ioe) { 454 } 456 } 457 } 458 } 459 } 460 461 public void undoExternalChange() { 462 if (data != null) { 463 FileObject wsConfigXmlFO = data.getPrimaryFile(); 464 Configuration wsConfigXmlDD = null; 465 try { 466 wsConfigXmlDD = org.netbeans.modules.websvc.wsdl.config.api.DDProvider.getDefault().getDDRoot(wsConfigXmlFO); 467 } catch (IOException ioe) { 468 } 470 if (wsConfigXmlDD != null) { 471 org.netbeans.modules.websvc.wsdl.config.api.Service service = wsConfigXmlDD.getService(); 472 if (service != null) { 473 service.setPackageName(oldName); 474 try { 475 wsConfigXmlDD.write(wsConfigXmlFO); 476 } catch (IOException ioe) { 477 } 479 } 480 } 481 } 482 } 483 } 484 485 public final class WebservicesConfigXmlMoveClassRefactoringElement extends AbstractMoveClassRefactoringElement implements ExternalChange { 486 487 private DataObject data = null; 488 private FileObject target = null; 489 private FileObject originalFolder = null; 490 private String targetPackageName; 491 492 493 public WebservicesConfigXmlMoveClassRefactoringElement(DataObject data, FileObject targetClassPathRoot, String targetPackageName) { 494 this.data = data; 495 this.target = targetClassPathRoot; 496 this.originalFolder = data.getPrimaryFile().getParent(); 497 this.targetPackageName = targetPackageName; 498 } 499 500 503 public String getDisplayText() { 504 Object [] args = new Object [] {data.getPrimaryFile().getNameExt(), target.getPath() + "/" + targetPackageName.replace('.','/')}; return MessageFormat.format(NbBundle.getMessage(WebservicesXmlMoveClassRefactoring.class, "TXT_WebservicesConfigXmlMoveClass"), args); 506 } 507 508 511 public FileObject getParentFile() { 512 if (data != null) { 513 return data.getPrimaryFile(); 514 } 515 return null; 516 } 517 518 520 public void performChange() { 521 JavaMetamodel.getManager().registerExtChange(this); 522 } 523 524 public void performExternalChange() { 525 if (data != null) { 526 try { 527 DataFolder folder = DataFolder.findFolder(FileUtil.createFolder(target, targetPackageName.replace('.','/'))); 528 data.move(folder); 529 } catch (IOException ioe) { 530 ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL, "Could not move file: " + ioe); 531 } 532 } 533 } 534 535 public void undoExternalChange() { 536 if (data != null) { 537 DataFolder folder = DataFolder.findFolder(originalFolder); 538 try { 539 data.move(folder); 540 } catch (IOException ioe) { 541 ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL, "Could not undo move file: " + ioe); 542 } 543 } 544 } 545 } 546 547 public final class WebservicesConfigXmlServantMoveClassRefactoringElement extends AbstractMoveClassRefactoringElement implements ExternalChange { 548 549 private DataObject data = null; 550 551 552 public WebservicesConfigXmlServantMoveClassRefactoringElement(DataObject data, String oldName, String newName) { 553 this.oldName = oldName; 554 this.newName = newName; 555 this.data = data; 556 } 557 558 561 public String getDisplayText() { 562 Object [] args = new Object [] {data.getPrimaryFile(), oldName, newName}; 563 return MessageFormat.format(NbBundle.getMessage(WebservicesXmlMoveClassRefactoring.class, "TXT_WebservicesConfigXmlServantMoveClass"), args); 564 } 565 566 568 public void performChange() { 569 JavaMetamodel.getManager().registerExtChange(this); 570 } 571 572 575 public FileObject getParentFile() { 576 if (data != null) { 577 return data.getPrimaryFile(); 578 } 579 return null; 580 } 581 582 public void performExternalChange() { 583 if (data != null) { 584 FileObject wsConfigXmlFO = data.getPrimaryFile(); 585 Configuration wsConfigXmlDD = null; 586 try { 587 wsConfigXmlDD = org.netbeans.modules.websvc.wsdl.config.api.DDProvider.getDefault().getDDRoot(wsConfigXmlFO); 588 } catch (IOException ioe) { 589 } 591 if (wsConfigXmlDD != null) { 592 err.log("perform external change: WebservicesConfigXmlServantMoveClassRefactoringElement"); 593 org.netbeans.modules.websvc.wsdl.config.api.Service service = wsConfigXmlDD.getService(); 594 org.netbeans.modules.websvc.wsdl.config.api.Interface[] interfaces = service.getInterface(); 595 err.log("Interfaces: " + interfaces); 596 if ((interfaces != null) && (interfaces.length > 0)) { 597 for (int ii=0; ii < interfaces.length; ii++) { 598 org.netbeans.modules.websvc.wsdl.config.api.Interface iface = interfaces[ii]; 599 String servant = iface.getServantName(); 600 err.log("Servant: " + servant); 601 if ((servant != null) && (servant.equals(oldName))) { 602 iface.setServantName(newName); 603 } 604 } 605 try { 606 wsConfigXmlDD.write(wsConfigXmlFO); 607 } catch (IOException ioe) { 608 } 610 } 611 } 612 } 613 } 614 615 public void undoExternalChange() { 616 if (data != null) { 617 FileObject wsConfigXmlFO = data.getPrimaryFile(); 618 Configuration wsConfigXmlDD = null; 619 try { 620 wsConfigXmlDD = org.netbeans.modules.websvc.wsdl.config.api.DDProvider.getDefault().getDDRoot(wsConfigXmlFO); 621 } catch (IOException ioe) { 622 } 624 if (wsConfigXmlDD != null) { 625 err.log("undo external change: WebservicesConfigXmlServantMoveClassRefactoringElement"); 626 org.netbeans.modules.websvc.wsdl.config.api.Service service = wsConfigXmlDD.getService(); 627 org.netbeans.modules.websvc.wsdl.config.api.Interface[] interfaces = service.getInterface(); 628 err.log("Interfaces: " + interfaces); 629 if ((interfaces != null) && (interfaces.length > 0)) { 630 for (int ii=0; ii < interfaces.length; ii++) { 631 org.netbeans.modules.websvc.wsdl.config.api.Interface iface = interfaces[ii]; 632 String servant = iface.getServantName(); 633 err.log("Servant: " + servant); 634 if ((servant != null) && (servant.equals(newName))) { 635 iface.setServantName(oldName); 636 } 637 } 638 try { 639 wsConfigXmlDD.write(wsConfigXmlFO); 640 } catch (IOException ioe) { 641 } 643 } 644 } 645 } 646 } 647 } 648 649 public final class WebservicesConfigXmlInterfaceMoveClassRefactoringElement extends AbstractMoveClassRefactoringElement implements ExternalChange { 650 651 private DataObject data = null; 652 653 654 public WebservicesConfigXmlInterfaceMoveClassRefactoringElement(DataObject data, String oldName, String newName) { 655 this.oldName = oldName; 656 this.newName = newName; 657 this.data = data; 658 } 659 660 663 public String getDisplayText() { 664 Object [] args = new Object [] {data.getPrimaryFile(), oldName, newName}; 665 return MessageFormat.format(NbBundle.getMessage(WebservicesXmlMoveClassRefactoring.class, "TXT_WebservicesConfigXmlInterfaceMoveClass"), args); 666 } 667 668 671 public FileObject getParentFile() { 672 if (data != null) { 673 return data.getPrimaryFile(); 674 } 675 return null; 676 } 677 678 680 public void performChange() { 681 JavaMetamodel.getManager().registerExtChange(this); 682 } 683 684 public void performExternalChange() { 685 if (data != null) { 686 FileObject wsConfigXmlFO = data.getPrimaryFile(); 687 Configuration wsConfigXmlDD = null; 688 try { 689 wsConfigXmlDD = org.netbeans.modules.websvc.wsdl.config.api.DDProvider.getDefault().getDDRoot(wsConfigXmlFO); 690 } catch (IOException ioe) { 691 } 693 if (wsConfigXmlDD != null) { 694 err.log("perform external change: WebservicesConfigXmlInterfaceMoveClassRefactoringElement"); 695 org.netbeans.modules.websvc.wsdl.config.api.Service service = wsConfigXmlDD.getService(); 696 org.netbeans.modules.websvc.wsdl.config.api.Interface[] interfaces = service.getInterface(); 697 err.log("Interfaces: " + interfaces); 698 if ((interfaces != null) && (interfaces.length > 0)) { 699 for (int ii=0; ii < interfaces.length; ii++) { 700 org.netbeans.modules.websvc.wsdl.config.api.Interface iface = interfaces[ii]; 701 String interf = iface.getName(); 702 err.log("Interface: " + interf); 703 if ((interf != null) && (interf.equals(oldName))) { 704 iface.setName(newName); 705 } 706 } 707 try { 708 wsConfigXmlDD.write(wsConfigXmlFO); 709 } catch (IOException ioe) { 710 } 712 } 713 } 714 } 715 } 716 717 public void undoExternalChange() { 718 if (data != null) { 719 FileObject wsConfigXmlFO = data.getPrimaryFile(); 720 Configuration wsConfigXmlDD = null; 721 try { 722 wsConfigXmlDD = org.netbeans.modules.websvc.wsdl.config.api.DDProvider.getDefault().getDDRoot(wsConfigXmlFO); 723 } catch (IOException ioe) { 724 } 726 if (wsConfigXmlDD != null) { 727 err.log("undo external change: WebservicesConfigXmlInterfaceMoveClassRefactoringElement"); 728 org.netbeans.modules.websvc.wsdl.config.api.Service service = wsConfigXmlDD.getService(); 729 org.netbeans.modules.websvc.wsdl.config.api.Interface[] interfaces = service.getInterface(); 730 err.log("Interfaces: " + interfaces); 731 if ((interfaces != null) && (interfaces.length > 0)) { 732 for (int ii=0; ii < interfaces.length; ii++) { 733 org.netbeans.modules.websvc.wsdl.config.api.Interface iface = interfaces[ii]; 734 String interf = iface.getName(); 735 err.log("Interface: " + interf); 736 if ((interf != null) && (interf.equals(newName))) { 737 iface.setName(oldName); 738 } 739 } 740 try { 741 wsConfigXmlDD.write(wsConfigXmlFO); 742 } catch (IOException ioe) { 743 } 745 } 746 } 747 } 748 } 749 } 750 751 public final class WebservicesProjectMoveClassRefactoringElement extends AbstractMoveClassRefactoringElement implements ExternalChange { 752 753 private DataObject data = null; 754 private AntProjectHelper helper; 755 private String propertyName; 756 private String propertyValue; 757 private String targetPackage; 758 private String newValue; 759 760 761 public WebservicesProjectMoveClassRefactoringElement(DataObject data, AntProjectHelper helper, String propertyName, String propertyValue, String newValue, String targetPackage) { 762 this.propertyName = propertyName; 763 this.propertyValue = propertyValue; 764 this.targetPackage = targetPackage; 765 this.data = data; 766 this.newValue = newValue; 767 this.helper = helper; 768 } 769 770 773 public FileObject getParentFile() { 774 if (data != null) { 775 return data.getPrimaryFile(); 776 } 777 return null; 778 } 779 780 783 public String getDisplayText() { 784 Object [] args = new Object [] {propertyName, propertyValue, newValue}; 785 return MessageFormat.format(NbBundle.getMessage(WebservicesXmlMoveClassRefactoring.class, "TXT_WebservicesProjectMoveClass"), args); 786 } 787 788 790 public void performChange() { 791 JavaMetamodel.getManager().registerExtChange(this); 792 } 793 794 public void performExternalChange() { 795 EditableProperties ep = helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); 796 if (data != null) { 797 ep.setProperty(propertyName, newValue); 798 } 799 helper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, ep); 800 Project project = null; 801 try { 802 project = ProjectManager.getDefault().findProject(helper.getProjectDirectory()); 803 ProjectManager.getDefault().saveProject(project); 804 } catch (IOException ioe) { } 806 } 807 808 public void undoExternalChange() { 809 if (data != null) { 810 } 811 } 812 } 813 814 } 815 | Popular Tags |