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.Collection ; 26 import java.util.Enumeration ; 27 import java.util.Iterator ; 28 import java.util.List ; 29 import javax.jmi.reflect.RefObject; 30 import org.netbeans.modules.j2ee.dd.api.web.WebApp; 31 import org.netbeans.jmi.javamodel.JavaClass; 32 import org.netbeans.jmi.javamodel.Resource; 33 import org.netbeans.modules.j2ee.refactoring.Utility; 34 import org.netbeans.modules.javacore.api.JavaModel; 35 import org.netbeans.modules.javacore.internalapi.ExternalChange; 36 import org.netbeans.modules.javacore.internalapi.JavaMetamodel; 37 import org.netbeans.modules.refactoring.api.MoveClassRefactoring; 38 import org.netbeans.modules.refactoring.api.Problem; 39 import org.netbeans.modules.refactoring.spi.RefactoringElementsBag; 40 import org.netbeans.modules.refactoring.spi.RefactoringElementImplementation; 41 import org.netbeans.modules.web.api.webmodule.WebModule; 42 import org.netbeans.modules.web.taglib.TLDDataObject; 43 import org.netbeans.modules.web.taglib.TLDLoader; 44 import org.netbeans.modules.web.taglib.model.FunctionType; 45 import org.netbeans.modules.web.taglib.model.ListenerType; 46 import org.netbeans.modules.web.taglib.model.TagType; 47 import org.netbeans.modules.web.taglib.model.Taglib; 48 import org.netbeans.modules.web.taglib.model.ValidatorType; 49 import org.openide.ErrorManager; 50 import org.openide.cookies.EditorCookie; 51 import org.openide.cookies.OpenCookie; 52 import org.openide.filesystems.FileObject; 53 import org.openide.filesystems.FileUtil; 54 import org.openide.loaders.DataObject; 55 import org.openide.loaders.DataObjectNotFoundException; 56 import org.openide.util.NbBundle; 57 58 62 public final class TldMoveClassRefactoring { 63 64 private static final ErrorManager err = ErrorManager.getDefault().getInstance("org.netbeans.modules.j2ee.refactoring.rename"); 66 public TldMoveClassRefactoring() { } 67 68 70 public Problem prepare(MoveClassRefactoring moveClassRefactor, Collection resources, RefactoringElementsBag refactoringElements) { 71 Problem problem = null; 72 73 for (Iterator i = resources.iterator(); i.hasNext();) { 74 Resource resource = (Resource) i.next(); 75 FileObject fo = JavaModel.getFileObject(resource); 76 77 err.log("resource package name: " + resource.getPackageName()); 78 err.log("resource: name " + resource.getName()); 79 80 WebModule wm = WebModule.getWebModule(fo); 81 82 FileObject target = moveClassRefactor.getTargetClassPathRoot(); 83 WebModule wmNew = null; 84 if (target != null) { 85 wmNew = WebModule.getWebModule(moveClassRefactor.getTargetClassPathRoot()); 86 } 87 88 if (wm != null) { boolean moveToAnotherProject = false; 90 91 if (wmNew != null) { 92 moveToAnotherProject = !wm.equals(wmNew); 93 } 94 95 FileObject webInf = wm.getWebInf(); 96 Enumeration e = null; 97 if (webInf != null) { 98 e = webInf.getChildren(true); 99 } 100 if (e != null) { 101 while (e.hasMoreElements()) { 102 FileObject tld = (FileObject)e.nextElement(); 103 FileObject tldNew = null; 104 105 if (isTld(tld)) { 106 107 DataObject tldData = null; 108 DataObject newTldData = null; 109 110 try { 111 tldData = DataObject.find(tld); 112 } catch (DataObjectNotFoundException dne) { 113 } 115 116 if (moveToAnotherProject) { 117 FileObject webInfNew = wmNew.getWebInf(); 118 Enumeration e2 = null; 119 if (webInfNew != null) { 120 e2 = webInfNew.getChildren(true); 121 } 122 while (e2.hasMoreElements()) { 123 tldNew = (FileObject)e2.nextElement(); 124 if (isTld(tldNew)) { 125 try { 126 newTldData = DataObject.find(tldNew); 127 break; 128 } catch (DataObjectNotFoundException dne) { 129 } 131 } 132 } 133 if (newTldData == null) { 134 Problem newProblem = new Problem(false, NbBundle.getMessage(TldMoveClassRefactoring.class, "TXT_TaglibNotExistMoveClassOtherProjectInvalidProblem")); 135 problem = Utility.addProblemsToEnd(problem, newProblem); 136 } 137 } 138 139 140 if ((tldData != null) && (tldData instanceof TLDDataObject)) { 141 Taglib taglib = null; 142 try { 143 taglib = ((TLDDataObject)tldData).getTaglib(); 144 } catch (IOException ioe) {} 145 if (taglib != null) { 146 List classes = resource.getClassifiers(); 147 err.log("Classes in resource: " + classes); 148 149 for (int j=0; j < classes.size(); j++ ) { 150 JavaClass jClass = (JavaClass)classes.get(j); 151 err.log("javaclass: "+ jClass); 152 153 String name = jClass.getName(); 154 err.log("name: " + name); 155 156 String targetPackage = moveClassRefactor.getTargetPackageName(resource); 157 err.log("targetPackage: " + targetPackage); 158 159 String newName = targetPackage + "." + jClass.getSimpleName(); 160 err.log("newname: " + newName); 161 162 TagType[] tagTypes = taglib.getTag(); 164 if ((tagTypes != null) && (tagTypes.length > 0)) { 165 for (int tt = 0; tt < tagTypes.length; tt++) { 166 TagType tagT = tagTypes[tt]; 167 String tagClass = tagT.getTagClass(); 168 String teiClass = tagT.getTeiClass(); 169 if (!moveToAnotherProject) { 170 if ((tagClass != null) && (tagClass.equals(name))) { 171 RefactoringElementImplementation elem = new TaglibTagClassMoveClassRefactoringElement(tldData, name, newName); 172 refactoringElements.add(moveClassRefactor, elem); 173 } 174 if ((teiClass != null) && (teiClass.equals(name))) { 175 RefactoringElementImplementation elem = new TaglibTeiClassMoveClassRefactoringElement(tldData, name, newName); 176 refactoringElements.add(moveClassRefactor, elem); 177 } 178 } else { 179 if (newTldData != null) { 180 if ((tagClass != null) && (tagClass.equals(name))) { 181 RefactoringElementImplementation elem = new TaglibTagClassReferenceMoveClassOtherProjectRefactoringElement(tldData, newTldData, name, newName); 182 refactoringElements.add(moveClassRefactor, elem); 183 } 184 if ((teiClass != null) && (teiClass.equals(name))) { 185 RefactoringElementImplementation elem = new TaglibTeiClassReferenceMoveClassOtherProjectRefactoringElement(tldData, newTldData, name, newName); 186 refactoringElements.add(moveClassRefactor, elem); 187 } 188 } 189 } 190 } 191 } 192 193 FunctionType[] functionTypes = taglib.getFunction(); 194 if ((functionTypes != null) && (functionTypes.length > 0)) { 195 for (int tt = 0; tt < functionTypes.length; tt++) { 196 FunctionType functionT = functionTypes[tt]; 197 String functionClass = functionT.getFunctionClass(); 198 if ((functionClass != null) && (functionClass.equals(name))) { 199 RefactoringElementImplementation elem = new TaglibFunctionClassMoveClassRefactoringElement(tldData, name, newName); 200 refactoringElements.add(moveClassRefactor, elem); 201 } 202 } 203 } 204 205 ValidatorType validatorType = taglib.getValidator(); 207 if (validatorType != null) { 208 String validatorClass = validatorType.getValidatorClass(); 209 if ((validatorClass != null) && (validatorClass.equals(name))) { 210 RefactoringElementImplementation elem = new TaglibValidatorClassMoveClassRefactoringElement(tldData, name, newName); 211 refactoringElements.add(moveClassRefactor, elem); 212 } 213 } 214 215 org.netbeans.modules.web.taglib.model.ListenerType[] listenerTypes = taglib.getListener(); 217 if ((listenerTypes != null) && (listenerTypes.length > 0)) { 218 for (int tt = 0; tt < listenerTypes.length; tt++) { 219 org.netbeans.modules.web.taglib.model.ListenerType listenerT = listenerTypes[tt]; 220 String listenerClass = listenerT.getListenerClass(); 221 if ((listenerClass != null) && (listenerClass.equals(name))) { 222 RefactoringElementImplementation elem = new TaglibListenerClassMoveClassRefactoringElement(tldData, name, newName); 223 refactoringElements.add(moveClassRefactor, elem); 224 } 225 } 226 } 227 228 229 } 230 231 } else { 232 Object [] args = new Object [] {tld.getNameExt()}; 233 String msg = MessageFormat.format(NbBundle.getMessage(TldMoveClassRefactoring.class, "TXT_TaglibMoveClassInvalidProblem"), args); 234 Problem newProblem = new Problem(false, msg); 235 problem = Utility.addProblemsToEnd(problem, newProblem); 236 } 237 } 238 } 239 } 240 } 241 } 242 } 243 return problem; 244 } 245 246 private boolean isTld(FileObject fo) { 247 boolean isTld = false; 248 if (fo != null) { 249 String ext = fo.getExt(); 250 if (TLDLoader.tldExt.equalsIgnoreCase(ext)) { 251 isTld = true; 252 } 253 } 254 return isTld; 255 } 256 257 public final class TaglibTagClassMoveClassRefactoringElement extends AbstractMoveClassRefactoringElement implements ExternalChange { 258 259 protected DataObject data = null; 260 261 262 public TaglibTagClassMoveClassRefactoringElement(DataObject data, String oldName, String newName) { 263 this.data = data; 264 this.oldName = oldName; 265 this.newName = newName; 266 } 267 268 271 public String getDisplayText() { 272 Object [] args = new Object [] {data.getPrimaryFile().getNameExt(), oldName, newName}; 273 return MessageFormat.format(NbBundle.getMessage(TldMoveClassRefactoring.class, "TXT_TaglibTagClassMoveClass"), args); 274 } 275 276 279 public FileObject getParentFile() { 280 if (data != null) { 281 return data.getPrimaryFile(); 282 } 283 return null; 284 } 285 286 288 public void performChange() { 289 JavaMetamodel.getManager().registerExtChange(this); 290 } 291 292 public void performExternalChange() { 293 if (data != null) { 294 FileObject tldFO = data.getPrimaryFile(); 295 TLDDataObject tdo = ((TLDDataObject)data); 296 Taglib taglib = null; 297 try { 298 taglib = tdo.getTaglib(); 299 } catch (IOException ioe) { 300 } 302 if (taglib != null) { 303 err.log("perform external change: TaglibTagClassMoveClassRefactoringElement"); 304 TagType tag = null; 305 TagType[] tags = taglib.getTag(); 306 for (int i=0; i < tags.length; i++) { 307 String tagClass = tags[i].getTagClass(); 308 if (oldName.equals(tagClass)) { 309 tag = tags[i]; 310 break; 311 } 312 } 313 if (tag!=null) { 314 tag.setTagClass(newName); 315 try { 316 if (tdo != null) { 317 tdo.write(taglib); 318 } 319 } catch (IOException ioe) { 320 ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL, ioe.getMessage()); 321 } 322 } 323 } 324 } 325 } 326 327 public void undoExternalChange() { 328 if (data != null) { 329 FileObject tldFO = data.getPrimaryFile(); 330 TLDDataObject tdo = ((TLDDataObject)data); 331 Taglib taglib = null; 332 try { 333 taglib = tdo.getTaglib(); 334 } catch (IOException ioe) { 335 } 337 if (taglib != null) { 338 err.log("undo external change: TaglibTagClassMoveClassRefactoringElement"); 339 TagType tag = null; 340 TagType[] tags = taglib.getTag(); 341 for (int i=0; i < tags.length; i++) { 342 String tagClass = tags[i].getTagClass(); 343 if (newName.equals(tagClass)) { 344 tag = tags[i]; 345 break; 346 } 347 } 348 if (tag!=null) { 349 tag.setTagClass(oldName); 350 try { 351 if (tdo != null) { 352 tdo.write(taglib); 353 } 354 } catch (IOException ioe) { 355 ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL, ioe.getMessage()); 356 } 357 } 358 } 359 } 360 } 361 } 362 363 364 public final class TaglibTagClassReferenceMoveClassOtherProjectRefactoringElement extends AbstractMoveClassRefactoringElement implements ExternalChange { 365 366 protected DataObject data = null; 367 protected DataObject newData = null; 368 369 370 public TaglibTagClassReferenceMoveClassOtherProjectRefactoringElement(DataObject data, DataObject newData, String oldName, String newName) { 371 this.data = data; 372 this.newData = newData; 373 this.oldName = oldName; 374 this.newName = newName; 375 } 376 377 380 public String getDisplayText() { 381 Object [] args = new Object [] {data.getPrimaryFile().getNameExt(), data.getPrimaryFile().getNameExt(), newData.getPrimaryFile().getNameExt()}; 382 return MessageFormat.format(NbBundle.getMessage(TldMoveClassRefactoring.class, "TXT_TaglibTagClassReferenceMoveClassOtherProject"), args); 383 } 384 385 388 public FileObject getParentFile() { 389 if (data != null) { 390 return data.getPrimaryFile(); 391 } 392 return null; 393 } 394 395 397 public void performChange() { 398 JavaMetamodel.getManager().registerExtChange(this); 399 } 400 401 public void performExternalChange() { 402 if (data != null) { 403 FileObject tldFO = data.getPrimaryFile(); 404 TLDDataObject tdo = ((TLDDataObject)data); 405 406 FileObject newTldFO = newData.getPrimaryFile(); 407 TLDDataObject newTdo = ((TLDDataObject)newData); 408 409 Taglib taglib = null; 410 Taglib newTaglib = null; 411 try { 412 taglib = tdo.getTaglib(); 413 newTaglib = newTdo.getTaglib(); 414 } catch (IOException ioe) { 415 } 417 if ((taglib != null) && (newTaglib != null)) { 418 err.log("perform external change: TaglibTagClassReferenceMoveClassOtherProject"); 419 TagType tag = null; 420 TagType[] tags = taglib.getTag(); 421 for (int i=0; i < tags.length; i++) { 422 String tagClass = tags[i].getTagClass(); 423 if (oldName.equals(tagClass)) { 424 tag = tags[i]; 425 break; 426 } 427 } 428 if (tag != null) { 429 taglib.removeTag(tag); 430 tag.setTagClass(newName); 431 newTaglib.addTag(tag); 432 try { 433 if (tdo != null) { 434 tdo.write(taglib); 435 } 436 if (newTdo != null) { 437 newTdo.write(newTaglib); 438 } 439 } catch (IOException ioe) { 440 ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL, ioe.getMessage()); 441 } 442 } 443 } 444 } 445 } 446 447 public void undoExternalChange() { 448 if (data != null) { 449 FileObject tldFO = data.getPrimaryFile(); 450 TLDDataObject tdo = ((TLDDataObject)data); 451 452 FileObject newTldFO = newData.getPrimaryFile(); 453 TLDDataObject newTdo = ((TLDDataObject)newData); 454 455 Taglib taglib = null; 456 Taglib newTaglib = null; 457 try { 458 taglib = tdo.getTaglib(); 459 newTaglib = newTdo.getTaglib(); 460 } catch (IOException ioe) { 461 } 463 if ((taglib != null) && (newTaglib != null)) { 464 err.log("perform external change: TaglibTagClassReferenceMoveClassOtherProject"); 465 TagType tag = null; 466 TagType[] tags = newTaglib.getTag(); 467 for (int i=0; i < tags.length; i++) { 468 String tagClass = tags[i].getTagClass(); 469 if (newName.equals(tagClass)) { 470 tag = tags[i]; 471 break; 472 } 473 } 474 if (tag != null) { 475 newTaglib.removeTag(tag); 476 tag.setTagClass(oldName); 477 taglib.addTag(tag); 478 try { 479 if (tdo != null) { 480 tdo.write(taglib); 481 } 482 if (newTdo != null) { 483 newTdo.write(newTaglib); 484 } 485 } catch (IOException ioe) { 486 ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL, ioe.getMessage()); 487 } 488 } 489 } 490 } 491 } 492 } 493 494 495 public final class TaglibTeiClassMoveClassRefactoringElement extends AbstractMoveClassRefactoringElement implements ExternalChange { 496 497 protected DataObject data = null; 498 499 500 public TaglibTeiClassMoveClassRefactoringElement(DataObject data, String oldName, String newName) { 501 this.data = data; 502 this.oldName = oldName; 503 this.newName = newName; 504 } 505 506 509 public String getDisplayText() { 510 Object [] args = new Object [] {data.getPrimaryFile().getNameExt(), oldName, newName}; 511 return MessageFormat.format(NbBundle.getMessage(TldMoveClassRefactoring.class, "TXT_TaglibTeiClassMoveClass"), args); 512 } 513 514 517 public FileObject getParentFile() { 518 if (data != null) { 519 return data.getPrimaryFile(); 520 } 521 return null; 522 } 523 524 526 public void performChange() { 527 JavaMetamodel.getManager().registerExtChange(this); 528 } 529 530 public void performExternalChange() { 531 if (data != null) { 532 FileObject tldFO = data.getPrimaryFile(); 533 TLDDataObject tdo = ((TLDDataObject)data); 534 Taglib taglib = null; 535 try { 536 taglib = tdo.getTaglib(); 537 } catch (IOException ioe) { 538 } 540 if (taglib != null) { 541 TagType tag = null; 542 TagType[] tags = taglib.getTag(); 543 for (int i=0; i < tags.length; i++) { 544 String teiClass = tags[i].getTagClass(); 545 if (oldName.equals(teiClass)) { 546 tag = tags[i]; 547 break; 548 } 549 } 550 if (tag!=null) { 551 tag.setTeiClass(newName); 552 try { 553 if (tdo != null) { 554 tdo.write(taglib); 555 } 556 } catch (IOException ioe) { 557 ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL, ioe.getMessage()); 558 } 559 } 560 } 561 } 562 } 563 564 public void undoExternalChange() { 565 if (data != null) { 566 FileObject tldFO = data.getPrimaryFile(); 567 TLDDataObject tdo = ((TLDDataObject)data); 568 Taglib taglib = null; 569 try { 570 taglib = tdo.getTaglib(); 571 } catch (IOException ioe) { 572 } 574 if (taglib != null) { 575 TagType tag = null; 576 TagType[] tags = taglib.getTag(); 577 for (int i=0; i < tags.length; i++) { 578 String teiClass = tags[i].getTagClass(); 579 if (newName.equals(teiClass)) { 580 tag = tags[i]; 581 break; 582 } 583 } 584 if (tag!=null) { 585 tag.setTeiClass(oldName); 586 try { 587 if (tdo != null) { 588 tdo.write(taglib); 589 } 590 } catch (IOException ioe) { 591 ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL, ioe.getMessage()); 592 } 593 } 594 } 595 } 596 } 597 } 598 599 600 public final class TaglibTeiClassReferenceMoveClassOtherProjectRefactoringElement extends AbstractMoveClassRefactoringElement implements ExternalChange { 601 602 protected DataObject data = null; 603 protected DataObject newData = null; 604 605 606 public TaglibTeiClassReferenceMoveClassOtherProjectRefactoringElement(DataObject data, DataObject newData, String oldName, String newName) { 607 this.data = data; 608 this.newData = newData; 609 this.oldName = oldName; 610 this.newName = newName; 611 } 612 613 616 public String getDisplayText() { 617 Object [] args = new Object [] {data.getPrimaryFile().getNameExt(), oldName, newName}; 618 return MessageFormat.format(NbBundle.getMessage(TldMoveClassRefactoring.class, "TXT_TaglibTeiClassReferenceMoveClassOtherProject"), args); 619 } 620 621 624 public FileObject getParentFile() { 625 if (data != null) { 626 return data.getPrimaryFile(); 627 } 628 return null; 629 } 630 631 633 public void performChange() { 634 JavaMetamodel.getManager().registerExtChange(this); 635 } 636 637 public void performExternalChange() { 638 if (data != null) { 639 FileObject tldFO = data.getPrimaryFile(); 640 TLDDataObject tdo = ((TLDDataObject)data); 641 642 FileObject newTldFO = newData.getPrimaryFile(); 643 TLDDataObject newTdo = ((TLDDataObject)newData); 644 645 Taglib taglib = null; 646 Taglib newTaglib = null; 647 try { 648 taglib = tdo.getTaglib(); 649 newTaglib = newTdo.getTaglib(); 650 } catch (IOException ioe) { 651 } 653 if ((taglib != null) && (newTaglib != null)) { 654 err.log("perform external change: TaglibTagClassReferenceMoveClassOtherProject"); 655 TagType tag = null; 656 TagType[] tags = taglib.getTag(); 657 for (int i=0; i < tags.length; i++) { 658 String teiClass = tags[i].getTeiClass(); 659 if (oldName.equals(teiClass)) { 660 tag = tags[i]; 661 break; 662 } 663 } 664 if (tag != null) { 665 taglib.removeTag(tag); 666 tag.setTeiClass(newName); 667 newTaglib.addTag(tag); 668 try { 669 if (tdo != null) { 670 tdo.write(taglib); 671 } 672 if (newTdo != null) { 673 newTdo.write(newTaglib); 674 } 675 } catch (IOException ioe) { 676 ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL, ioe.getMessage()); 677 } 678 } 679 } 680 } 681 } 682 683 public void undoExternalChange() { 684 if (data != null) { 685 FileObject tldFO = data.getPrimaryFile(); 686 TLDDataObject tdo = ((TLDDataObject)data); 687 688 FileObject newTldFO = newData.getPrimaryFile(); 689 TLDDataObject newTdo = ((TLDDataObject)newData); 690 691 Taglib taglib = null; 692 Taglib newTaglib = null; 693 try { 694 taglib = tdo.getTaglib(); 695 newTaglib = newTdo.getTaglib(); 696 } catch (IOException ioe) { 697 } 699 if ((taglib != null) && (newTaglib != null)) { 700 err.log("undo external change: TaglibTagClassReferenceMoveClassOtherProject"); 701 TagType tag = null; 702 TagType[] tags = newTaglib.getTag(); 703 for (int i=0; i < tags.length; i++) { 704 String teiClass = tags[i].getTeiClass(); 705 if (newName.equals(teiClass)) { 706 tag = tags[i]; 707 break; 708 } 709 } 710 if (tag != null) { 711 newTaglib.removeTag(tag); 712 tag.setTeiClass(oldName); 713 taglib.addTag(tag); 714 try { 715 if (tdo != null) { 716 tdo.write(taglib); 717 } 718 if (newTdo != null) { 719 newTdo.write(newTaglib); 720 } 721 } catch (IOException ioe) { 722 ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL, ioe.getMessage()); 723 } 724 } 725 } 726 } 727 } 728 } 729 730 731 public final class TaglibFunctionClassMoveClassRefactoringElement extends AbstractMoveClassRefactoringElement implements ExternalChange { 732 733 protected DataObject data; 734 735 736 public TaglibFunctionClassMoveClassRefactoringElement(DataObject data, String oldName, String newName) { 737 this.data = data; 738 this.oldName = oldName; 739 this.newName = newName; 740 } 741 742 745 public String getDisplayText() { 746 Object [] args = new Object [] {data.getPrimaryFile().getNameExt(), oldName, newName}; 747 return MessageFormat.format(NbBundle.getMessage(TldMoveClassRefactoring.class, "TXT_TaglibFunctionClassMoveClass"), args); 748 } 749 750 752 public void performChange() { 753 JavaMetamodel.getManager().registerExtChange(this); 754 } 755 756 759 public FileObject getParentFile() { 760 if (data != null) { 761 return data.getPrimaryFile(); 762 } 763 return null; 764 } 765 766 public void performExternalChange() { 767 if (data != null) { 768 FileObject tldFO = data.getPrimaryFile(); 769 TLDDataObject tdo = ((TLDDataObject)data); 770 Taglib taglib = null; 771 try { 772 taglib = tdo.getTaglib(); 773 } catch (IOException ioe) { 774 } 776 if (taglib != null) { 777 FunctionType function = null; 778 FunctionType[] functions = taglib.getFunction(); 779 for (int i=0; i < functions.length; i++) { 780 String functionClass = functions[i].getFunctionClass(); 781 if (oldName.equals(functionClass)) { 782 function = functions[i]; 783 break; 784 } 785 } 786 if (function!=null) { 787 function.setFunctionClass(newName); 788 try { 789 if (tdo != null) { 790 tdo.write(taglib); 791 } 792 } catch (IOException ioe) { 793 ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL, ioe.getMessage()); 794 } 795 } 796 } 797 } 798 } 799 800 public void undoExternalChange() { 801 if (data != null) { 802 FileObject tldFO = data.getPrimaryFile(); 803 TLDDataObject tdo = ((TLDDataObject)data); 804 Taglib taglib = null; 805 try { 806 taglib = tdo.getTaglib(); 807 } catch (IOException ioe) { 808 } 810 if (taglib != null) { 811 FunctionType function = null; 812 FunctionType[] functions = taglib.getFunction(); 813 for (int i=0; i < functions.length; i++) { 814 String functionClass = functions[i].getFunctionClass(); 815 if (newName.equals(functionClass)) { 816 function = functions[i]; 817 break; 818 } 819 } 820 if (function!=null) { 821 function.setFunctionClass(oldName); 822 try { 823 if (tdo != null) { 824 tdo.write(taglib); 825 } 826 } catch (IOException ioe) { 827 ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL, ioe.getMessage()); 828 } 829 } 830 } 831 } 832 } 833 } 834 835 836 public final class TaglibFunctionClassReferenceMoveClassOtherProjectRefactoringElement extends AbstractMoveClassRefactoringElement implements ExternalChange { 837 838 protected DataObject data = null; 839 protected DataObject newData = null; 840 841 842 public TaglibFunctionClassReferenceMoveClassOtherProjectRefactoringElement(DataObject data, DataObject newData, String oldName, String newName) { 843 this.data = data; 844 this.newData = newData; 845 this.oldName = oldName; 846 this.newName = newName; 847 } 848 849 852 public String getDisplayText() { 853 Object [] args = new Object [] {data.getPrimaryFile().getNameExt(), oldName, newName}; 854 return MessageFormat.format(NbBundle.getMessage(TldMoveClassRefactoring.class, "TXT_TaglibFunctionClassReferenceMoveClassOtherProject"), args); 855 } 856 857 860 public FileObject getParentFile() { 861 if (data != null) { 862 return data.getPrimaryFile(); 863 } 864 return null; 865 } 866 867 869 public void performChange() { 870 JavaMetamodel.getManager().registerExtChange(this); 871 } 872 873 public void performExternalChange() { 874 if (data != null) { 875 FileObject tldFO = data.getPrimaryFile(); 876 TLDDataObject tdo = ((TLDDataObject)data); 877 878 FileObject newTldFO = newData.getPrimaryFile(); 879 TLDDataObject newTdo = ((TLDDataObject)newData); 880 881 Taglib taglib = null; 882 Taglib newTaglib = null; 883 try { 884 taglib = tdo.getTaglib(); 885 newTaglib = newTdo.getTaglib(); 886 } catch (IOException ioe) { 887 } 889 if ((taglib != null) && (newTaglib != null)) { 890 err.log("perform external change: TaglibFunctionClassReferenceMoveClassOtherProjectRefactoringElement"); 891 FunctionType function = null; 892 FunctionType[] functions = taglib.getFunction(); 893 for (int i=0; i < functions.length; i++) { 894 String functionClass = functions[i].getFunctionClass(); 895 if (oldName.equals(functionClass)) { 896 function = functions[i]; 897 break; 898 } 899 } 900 if (function != null) { 901 taglib.removeFunction(function); 902 function.setFunctionClass(newName); 903 newTaglib.addFunction(function); 904 try { 905 if (tdo != null) { 906 tdo.write(taglib); 907 } 908 if (newTdo != null) { 909 newTdo.write(newTaglib); 910 } 911 } catch (IOException ioe) { 912 ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL, ioe.getMessage()); 913 } 914 } 915 } 916 } 917 } 918 919 public void undoExternalChange() { 920 if (data != null) { 921 FileObject tldFO = data.getPrimaryFile(); 922 TLDDataObject tdo = ((TLDDataObject)data); 923 924 FileObject newTldFO = newData.getPrimaryFile(); 925 TLDDataObject newTdo = ((TLDDataObject)newData); 926 927 Taglib taglib = null; 928 Taglib newTaglib = null; 929 try { 930 taglib = tdo.getTaglib(); 931 newTaglib = newTdo.getTaglib(); 932 } catch (IOException ioe) { 933 } 935 if ((taglib != null) && (newTaglib != null)) { 936 err.log("undo external change: TaglibFunctionClassReferenceMoveClassOtherProjectRefactoringElement"); 937 FunctionType function = null; 938 FunctionType[] functions = newTaglib.getFunction(); 939 for (int i=0; i < functions.length; i++) { 940 String functionClass = functions[i].getFunctionClass(); 941 if (newName.equals(functionClass)) { 942 function = functions[i]; 943 break; 944 } 945 } 946 if (function != null) { 947 newTaglib.removeFunction(function); 948 function.setFunctionClass(oldName); 949 taglib.addFunction(function); 950 try { 951 if (tdo != null) { 952 tdo.write(taglib); 953 } 954 if (newTdo != null) { 955 newTdo.write(newTaglib); 956 } 957 } catch (IOException ioe) { 958 ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL, ioe.getMessage()); 959 } 960 } 961 } 962 } 963 } 964 } 965 966 public final class TaglibValidatorClassMoveClassRefactoringElement extends AbstractMoveClassRefactoringElement implements ExternalChange { 967 968 protected DataObject data; 969 970 971 public TaglibValidatorClassMoveClassRefactoringElement(DataObject data, String oldName, String newName) { 972 this.data = data; 973 this.oldName = oldName; 974 this.newName = newName; 975 } 976 977 980 public String getDisplayText() { 981 Object [] args = new Object [] {data.getPrimaryFile().getNameExt(), oldName, newName}; 982 return MessageFormat.format(NbBundle.getMessage(TldMoveClassRefactoring.class, "TXT_TaglibValidatorClassMoveClass"), args); 983 } 984 985 988 public FileObject getParentFile() { 989 if (data != null) { 990 return data.getPrimaryFile(); 991 } 992 return null; 993 } 994 995 997 public void performChange() { 998 JavaMetamodel.getManager().registerExtChange(this); 999 } 1000 1001 public void performExternalChange() { 1002 if (data != null) { 1003 FileObject tldFO = data.getPrimaryFile(); 1004 TLDDataObject tdo = ((TLDDataObject)data); 1005 Taglib taglib = null; 1006 try { 1007 taglib = tdo.getTaglib(); 1008 } catch (IOException ioe) { 1009 } 1011 if (taglib != null) { 1012 ValidatorType validator = taglib.getValidator(); 1013 if (validator!=null) { 1014 validator.setValidatorClass(newName); 1015 try { 1016 if (tdo != null) { 1017 tdo.write(taglib); 1018 } 1019 } catch (IOException ioe) { 1020 ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL, ioe.getMessage()); 1021 } 1022 } 1023 } 1024 } 1025 } 1026 1027 public void undoExternalChange() { 1028 if (data != null) { 1029 FileObject tldFO = data.getPrimaryFile(); 1030 Taglib taglib = null; 1031 TLDDataObject tdo = ((TLDDataObject)data); 1032 try { 1033 taglib = tdo.getTaglib(); 1034 } catch (IOException ioe) { 1035 } 1037 if (taglib != null) { 1038 ValidatorType validator = taglib.getValidator(); 1039 if (validator!=null) { 1040 validator.setValidatorClass(oldName); 1041 try { 1042 if (tdo != null) { 1043 tdo.write(taglib); 1044 } 1045 } catch (IOException ioe) { 1046 ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL, ioe.getMessage()); 1047 } 1048 } 1049 } 1050 } 1051 } 1052 } 1053 1054 public final class TaglibValidatorClassReferenceMoveClassOtherProjectRefactoringElement extends AbstractMoveClassRefactoringElement implements ExternalChange { 1055 1056 protected DataObject data = null; 1057 protected DataObject newData = null; 1058 1059 1060 public TaglibValidatorClassReferenceMoveClassOtherProjectRefactoringElement(DataObject data, DataObject newData, String oldName, String newName) { 1061 this.data = data; 1062 this.newData = newData; 1063 this.oldName = oldName; 1064 this.newName = newName; 1065 } 1066 1067 1070 public String getDisplayText() { 1071 Object [] args = new Object [] {data.getPrimaryFile().getNameExt(), oldName, newName}; 1072 return MessageFormat.format(NbBundle.getMessage(TldMoveClassRefactoring.class, "TXT_TaglibValidatorClassReferenceMoveClassOtherProject"), args); 1073 } 1074 1075 1078 public FileObject getParentFile() { 1079 if (data != null) { 1080 return data.getPrimaryFile(); 1081 } 1082 return null; 1083 } 1084 1085 1087 public void performChange() { 1088 JavaMetamodel.getManager().registerExtChange(this); 1089 } 1090 1091 public void performExternalChange() { 1092 if (data != null) { 1093 FileObject tldFO = data.getPrimaryFile(); 1094 TLDDataObject tdo = ((TLDDataObject)data); 1095 1096 FileObject newTldFO = newData.getPrimaryFile(); 1097 TLDDataObject newTdo = ((TLDDataObject)newData); 1098 1099 Taglib taglib = null; 1100 Taglib newTaglib = null; 1101 try { 1102 taglib = tdo.getTaglib(); 1103 newTaglib = newTdo.getTaglib(); 1104 } catch (IOException ioe) { 1105 } 1107 if ((taglib != null) && (newTaglib != null)) { 1108 err.log("perform external change: TaglibValidatorClassReferenceMoveClassOtherProjectRefactoringElement"); 1109 ValidatorType validator = taglib.getValidator(); 1110 if (validator != null) { 1111 String validatorClass = validator.getValidatorClass(); 1112 if (oldName.equals(validatorClass)) { 1113 1114 try { 1119 if (tdo != null) { 1120 tdo.write(taglib); 1121 } 1122 if (newTdo != null) { 1123 newTdo.write(newTaglib); 1124 } 1125 } catch (IOException ioe) { 1126 ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL, ioe.getMessage()); 1127 } 1128 } 1129 } 1130 } 1131 } 1132 } 1133 1134 public void undoExternalChange() { 1135 if (data != null) { 1136 FileObject tldFO = data.getPrimaryFile(); 1137 TLDDataObject tdo = ((TLDDataObject)data); 1138 1139 FileObject newTldFO = newData.getPrimaryFile(); 1140 TLDDataObject newTdo = ((TLDDataObject)newData); 1141 1142 Taglib taglib = null; 1143 Taglib newTaglib = null; 1144 try { 1145 taglib = tdo.getTaglib(); 1146 newTaglib = newTdo.getTaglib(); 1147 } catch (IOException ioe) { 1148 } 1150 if ((taglib != null) && (newTaglib != null)) { 1151 err.log("undo external change: TaglibValidatorClassReferenceMoveClassOtherProjectRefactoringElement"); 1152 ValidatorType validator = newTaglib.getValidator(); 1153 if (validator != null) { 1154 String validatorClass = validator.getValidatorClass(); 1155 if (newName.equals(validatorClass)) { 1156 try { 1161 if (tdo != null) { 1162 tdo.write(taglib); 1163 } 1164 if (newTdo != null) { 1165 newTdo.write(newTaglib); 1166 } 1167 } catch (IOException ioe) { 1168 ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL, ioe.getMessage()); 1169 } 1170 } 1171 } 1172 } 1173 } 1174 } 1175 } 1176 1177 public final class TaglibListenerClassMoveClassRefactoringElement extends AbstractMoveClassRefactoringElement implements ExternalChange { 1178 1179 protected DataObject data; 1180 1181 1182 public TaglibListenerClassMoveClassRefactoringElement(DataObject data, String oldName, String newName) { 1183 this.data = data; 1184 this.oldName = oldName; 1185 this.newName = newName; 1186 } 1187 1188 1191 public String getDisplayText() { 1192 Object [] args = new Object [] {data.getPrimaryFile().getNameExt(), oldName, newName}; 1193 return MessageFormat.format(NbBundle.getMessage(TldMoveClassRefactoring.class, "TXT_TaglibListenerClassMoveClass"), args); 1194 } 1195 1196 1199 public FileObject getParentFile() { 1200 if (data != null) { 1201 return data.getPrimaryFile(); 1202 } 1203 return null; 1204 } 1205 1206 1208 public void performChange() { 1209 JavaMetamodel.getManager().registerExtChange(this); 1210 } 1211 1212 public void performExternalChange() { 1213 if (data != null) { 1214 FileObject tldFO = data.getPrimaryFile(); 1215 TLDDataObject tdo = ((TLDDataObject)data); 1216 Taglib taglib = null; 1217 try { 1218 taglib = tdo.getTaglib(); 1219 } catch (IOException ioe) { 1220 } 1222 if (taglib != null) { 1223 org.netbeans.modules.web.taglib.model.ListenerType listener = null; 1224 org.netbeans.modules.web.taglib.model.ListenerType[] listeners = taglib.getListener(); 1225 for (int i=0; i < listeners.length; i++) { 1226 String listenerClass = listeners[i].getListenerClass(); 1227 if (oldName.equals(listenerClass)) { 1228 listener = listeners[i]; 1229 break; 1230 } 1231 } 1232 if (listener!=null) { 1233 listener.setListenerClass(newName); 1234 try { 1235 if (tdo != null) { 1236 tdo.write(taglib); 1237 } 1238 } catch (IOException ioe) { 1239 ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL, ioe.getMessage()); 1240 } 1241 } 1242 } 1243 } 1244 } 1245 1246 public void undoExternalChange() { 1247 if (data != null) { 1248 FileObject tldFO = data.getPrimaryFile(); 1249 TLDDataObject tdo = ((TLDDataObject)data); 1250 Taglib taglib = null; 1251 try { 1252 taglib = tdo.getTaglib(); 1253 } catch (IOException ioe) { 1254 } 1256 if (taglib != null) { 1257 org.netbeans.modules.web.taglib.model.ListenerType listener = null; 1258 org.netbeans.modules.web.taglib.model.ListenerType[] listeners = taglib.getListener(); 1259 for (int i=0; i < listeners.length; i++) { 1260 String listenerClass = listeners[i].getListenerClass(); 1261 if (newName.equals(listenerClass)) { 1262 listener = listeners[i]; 1263 break; 1264 } 1265 } 1266 if (listener!=null) { 1267 listener.setListenerClass(oldName); 1268 try { 1269 if (tdo != null) { 1270 tdo.write(taglib); 1271 } 1272 } catch (IOException ioe) { 1273 ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL, ioe.getMessage()); 1274 } 1275 } 1276 } 1277 } 1278 } 1279 } 1280 1281 1282 public final class TaglibListenerClassReferenceMoveClassOtherProjectRefactoringElement extends AbstractMoveClassRefactoringElement implements ExternalChange { 1283 1284 protected DataObject data = null; 1285 protected DataObject newData = null; 1286 1287 1288 public TaglibListenerClassReferenceMoveClassOtherProjectRefactoringElement(DataObject data, DataObject newData, String oldName, String newName) { 1289 this.data = data; 1290 this.newData = newData; 1291 this.oldName = oldName; 1292 this.newName = newName; 1293 } 1294 1295 1298 public String getDisplayText() { 1299 Object [] args = new Object [] {data.getPrimaryFile().getNameExt(), oldName, newName}; 1300 return MessageFormat.format(NbBundle.getMessage(TldMoveClassRefactoring.class, "TXT_TaglibListenerClassReferenceMoveClassOtherProject"), args); 1301 } 1302 1303 1306 public FileObject getParentFile() { 1307 if (data != null) { 1308 return data.getPrimaryFile(); 1309 } 1310 return null; 1311 } 1312 1313 1315 public void performChange() { 1316 JavaMetamodel.getManager().registerExtChange(this); 1317 } 1318 1319 public void performExternalChange() { 1320 if (data != null) { 1321 FileObject tldFO = data.getPrimaryFile(); 1322 TLDDataObject tdo = ((TLDDataObject)data); 1323 1324 FileObject newTldFO = newData.getPrimaryFile(); 1325 TLDDataObject newTdo = ((TLDDataObject)newData); 1326 1327 Taglib taglib = null; 1328 Taglib newTaglib = null; 1329 try { 1330 taglib = tdo.getTaglib(); 1331 newTaglib = newTdo.getTaglib(); 1332 } catch (IOException ioe) { 1333 } 1335 if ((taglib != null) && (newTaglib != null)) { 1336 err.log("perform external change: TaglibListenerClassReferenceMoveClassOtherProjectRefactoringElement"); 1337 ListenerType listener = null; 1338 ListenerType[] listeners = taglib.getListener(); 1339 for (int i=0; i < listeners.length; i++) { 1340 String listenerClass = listeners[i].getListenerClass(); 1341 if (oldName.equals(listenerClass)) { 1342 listener = listeners[i]; 1343 break; 1344 } 1345 } 1346 if (listener != null) { 1347 taglib.removeListener(listener); 1348 listener.setListenerClass(newName); 1349 newTaglib.addListener(listener); 1350 try { 1351 if (tdo != null) { 1352 tdo.write(taglib); 1353 } 1354 if (newTdo != null) { 1355 newTdo.write(newTaglib); 1356 } 1357 } catch (IOException ioe) { 1358 ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL, ioe.getMessage()); 1359 } 1360 } 1361 } 1362 } 1363 } 1364 1365 public void undoExternalChange() { 1366 if (data != null) { 1367 FileObject tldFO = data.getPrimaryFile(); 1368 TLDDataObject tdo = ((TLDDataObject)data); 1369 1370 FileObject newTldFO = newData.getPrimaryFile(); 1371 TLDDataObject newTdo = ((TLDDataObject)newData); 1372 1373 Taglib taglib = null; 1374 Taglib newTaglib = null; 1375 try { 1376 taglib = tdo.getTaglib(); 1377 newTaglib = newTdo.getTaglib(); 1378 } catch (IOException ioe) { 1379 } 1381 if ((taglib != null) && (newTaglib != null)) { 1382 err.log("undo external change: TaglibListenerClassReferenceMoveClassOtherProjectRefactoringElement"); 1383 ListenerType listener = null; 1384 ListenerType[] listeners = newTaglib.getListener(); 1385 for (int i=0; i < listeners.length; i++) { 1386 String listenerClass = listeners[i].getListenerClass(); 1387 if (newName.equals(listenerClass)) { 1388 listener = listeners[i]; 1389 break; 1390 } 1391 } 1392 if (listener != null) { 1393 newTaglib.removeListener(listener); 1394 listener.setListenerClass(oldName); 1395 taglib.addListener(listener); 1396 try { 1397 if (tdo != null) { 1398 tdo.write(taglib); 1399 } 1400 if (newTdo != null) { 1401 newTdo.write(newTaglib); 1402 } 1403 } catch (IOException ioe) { 1404 ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL, ioe.getMessage()); 1405 } 1406 } 1407 } 1408 } 1409 } 1410 } 1411 1412} 1413 | Popular Tags |