1 19 20 package org.netbeans.modules.j2ee.clientproject; 21 22 import java.beans.PropertyChangeEvent ; 23 import java.beans.PropertyChangeListener ; 24 import java.beans.PropertyChangeSupport ; 25 import java.io.File ; 26 import java.io.IOException ; 27 import java.net.URI ; 28 import java.util.LinkedList ; 29 import java.util.List ; 30 import javax.swing.Icon ; 31 import javax.swing.ImageIcon ; 32 import javax.swing.JButton ; 33 import org.netbeans.api.java.classpath.ClassPath; 34 import org.netbeans.api.java.classpath.GlobalPathRegistry; 35 import org.netbeans.api.java.project.JavaProjectConstants; 36 import org.netbeans.api.project.FileOwnerQuery; 37 import org.netbeans.api.project.Project; 38 import org.netbeans.api.project.ProjectInformation; 39 import org.netbeans.api.project.ProjectManager; 40 import org.netbeans.api.project.ant.AntArtifact; 41 import org.netbeans.modules.j2ee.api.ejbjar.Car; 42 import org.netbeans.modules.j2ee.clientproject.classpath.AppClientProjectClassPathExtender; 43 import org.netbeans.modules.j2ee.clientproject.classpath.ClassPathProviderImpl; 44 import org.netbeans.modules.j2ee.clientproject.classpath.ClassPathSupport; 45 import org.netbeans.modules.j2ee.clientproject.queries.CompiledSourceForBinaryQuery; 46 import org.netbeans.modules.j2ee.clientproject.queries.JavadocForBinaryQueryImpl; 47 import org.netbeans.modules.j2ee.clientproject.queries.SourceLevelQueryImpl; 48 import org.netbeans.modules.j2ee.clientproject.queries.UnitTestForSourceQueryImpl; 49 import org.netbeans.modules.j2ee.clientproject.ui.AppClientLogicalViewProvider; 50 import org.netbeans.modules.j2ee.clientproject.ui.customizer.AppClientProjectProperties; 51 import org.netbeans.modules.j2ee.clientproject.ui.customizer.CustomizerProviderImpl; 52 import org.netbeans.modules.j2ee.clientproject.wsclient.AppClientProjectJAXWSClientSupport; 53 import org.netbeans.modules.j2ee.clientproject.wsclient.AppClientProjectWebServicesClientSupport; 54 import org.netbeans.modules.j2ee.clientproject.wsclient.AppClientProjectWebServicesSupportProvider; 55 import org.netbeans.modules.j2ee.common.ui.BrokenServerSupport; 56 import org.netbeans.modules.j2ee.deployment.devmodules.api.Deployment; 57 import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eePlatform; 58 import org.netbeans.modules.j2ee.spi.ejbjar.CarFactory; 59 import org.netbeans.modules.websvc.api.client.WebServicesClientSupport; 60 import org.netbeans.modules.websvc.api.jaxws.client.JAXWSClientSupport; 61 import org.netbeans.modules.websvc.api.jaxws.project.GeneratedFilesHelper; 62 import org.netbeans.modules.websvc.api.jaxws.project.WSUtils; 63 import org.netbeans.modules.websvc.api.jaxws.project.config.JaxWsModel; 64 import org.netbeans.modules.websvc.api.jaxws.project.config.JaxWsModelProvider; 65 import org.netbeans.modules.websvc.spi.client.WebServicesClientSupportFactory; 66 import org.netbeans.modules.websvc.spi.jaxws.client.JAXWSClientSupportFactory; 67 import org.netbeans.spi.java.project.support.ui.BrokenReferencesSupport; 68 import org.netbeans.spi.project.AuxiliaryConfiguration; 69 import org.netbeans.spi.project.SubprojectProvider; 70 import org.netbeans.spi.project.ant.AntArtifactProvider; 71 import org.netbeans.spi.project.support.LookupProviderSupport; 72 import org.netbeans.spi.project.support.ant.AntProjectEvent; 73 import org.netbeans.spi.project.support.ant.AntProjectHelper; 74 import org.netbeans.spi.project.support.ant.AntProjectListener; 75 import org.netbeans.spi.project.support.ant.EditableProperties; 76 import org.netbeans.spi.project.support.ant.ProjectXmlSavedHook; 77 import org.netbeans.spi.project.support.ant.PropertyEvaluator; 78 import org.netbeans.spi.project.support.ant.PropertyUtils; 79 import org.netbeans.spi.project.support.ant.ReferenceHelper; 80 import org.netbeans.spi.project.support.ant.SourcesHelper; 81 import org.netbeans.spi.project.ui.PrivilegedTemplates; 82 import org.netbeans.spi.project.ui.ProjectOpenedHook; 83 import org.netbeans.spi.project.ui.RecommendedTemplates; 84 import org.netbeans.spi.project.ui.support.UILookupMergerSupport; 85 import org.openide.DialogDisplayer; 86 import org.openide.ErrorManager; 87 import org.openide.NotifyDescriptor; 88 import org.openide.filesystems.FileAttributeEvent; 89 import org.openide.filesystems.FileChangeAdapter; 90 import org.openide.filesystems.FileChangeListener; 91 import org.openide.filesystems.FileEvent; 92 import org.openide.filesystems.FileObject; 93 import org.openide.filesystems.FileRenameEvent; 94 import org.openide.filesystems.FileUtil; 95 import org.openide.loaders.DataObject; 96 import org.openide.loaders.DataObjectNotFoundException; 97 import org.openide.util.Lookup; 98 import org.openide.util.Mutex; 99 import org.openide.util.NbBundle; 100 import org.openide.util.RequestProcessor; 101 import org.openide.util.Utilities; 102 import org.openide.util.lookup.Lookups; 103 import org.w3c.dom.Element ; 104 import org.w3c.dom.Node ; 105 import org.w3c.dom.NodeList ; 106 import org.w3c.dom.Text ; 107 108 112 public final class AppClientProject implements Project, AntProjectListener, FileChangeListener { 113 114 private static final Icon CAR_PROJECT_ICON = new ImageIcon (Utilities.loadImage("org/netbeans/modules/j2ee/clientproject/ui/resources/appclient.gif")); 116 private final AuxiliaryConfiguration aux; 117 private final AntProjectHelper helper; 118 private final PropertyEvaluator eval; 119 private final ReferenceHelper refHelper; 120 private final GeneratedFilesHelper genFilesHelper; 121 private final Lookup lookup; 122 private final UpdateHelper updateHelper; 123 private MainClassUpdater mainClassUpdater; 124 private SourceRoots sourceRoots; 125 private SourceRoots testRoots; 126 127 private AppClientProjectWebServicesClientSupport carProjectWebServicesClientSupport; 129 private AppClientProjectJAXWSClientSupport jaxWsClientSupport; 130 private WebServicesClientSupport apiWebServicesClientSupport; 131 private JAXWSClientSupport apiJAXWSClientSupport; 132 private JaxWsModel jaxWsModel; 133 private JaxWsListener jaxWsListener; 134 private FileObject jaxWsFo; 135 136 private PropertyChangeListener j2eePlatformListener; 137 private final AppClientProvider appClient; 138 private final Car apiJar; 139 private JarContainerImpl enterpriseResourceSupport; 140 private FileObject libFolder; 141 private final AppClientProjectClassPathExtender classpathExtender; 142 143 144 AppClientProject(AntProjectHelper helper) throws IOException { 145 this.helper = helper; 146 eval = createEvaluator(); 147 aux = helper.createAuxiliaryConfiguration(); 148 refHelper = new ReferenceHelper(helper, aux, eval); 149 genFilesHelper = new GeneratedFilesHelper(helper); 150 this.updateHelper = new UpdateHelper(this, this.helper, this.aux, this.genFilesHelper, 151 UpdateHelper.createDefaultNotifier()); 152 carProjectWebServicesClientSupport = new AppClientProjectWebServicesClientSupport(this, helper, refHelper); 153 jaxWsClientSupport = new AppClientProjectJAXWSClientSupport(this, helper); 154 apiWebServicesClientSupport = WebServicesClientSupportFactory.createWebServicesClientSupport(carProjectWebServicesClientSupport); 155 apiJAXWSClientSupport = JAXWSClientSupportFactory.createJAXWSClientSupport(jaxWsClientSupport); 156 appClient = new AppClientProvider(this, helper); 157 apiJar = CarFactory.createCar(appClient); 158 enterpriseResourceSupport = new JarContainerImpl(this, refHelper, helper); 159 classpathExtender = new AppClientProjectClassPathExtender(this, updateHelper, evaluator(), refHelper); 160 lookup = createLookup(aux); 161 helper.addAntProjectListener(this); 162 } 163 164 168 public FileObject getProjectDirectory() { 169 return helper.getProjectDirectory(); 170 } 171 172 public String toString() { 173 return "CarProject[" + getProjectDirectory() + "]"; } 175 176 private PropertyEvaluator createEvaluator() { 177 return helper.getStandardPropertyEvaluator(); 180 } 181 182 PropertyEvaluator evaluator() { 183 return eval; 184 } 185 186 public ReferenceHelper getReferenceHelper() { 187 return this.refHelper; 188 } 189 190 public UpdateHelper getUpdateHelper() { 191 return this.updateHelper; 192 } 193 194 public Lookup getLookup() { 195 return lookup; 196 } 197 198 public AntProjectHelper getAntProjectHelper() { 199 return helper; 200 } 201 202 private Lookup createLookup(AuxiliaryConfiguration aux) { 203 SubprojectProvider spp = refHelper.createSubprojectProvider(); 204 205 final SourcesHelper sourcesHelper = new SourcesHelper(helper, evaluator()); 206 String configFilesLabel = NbBundle.getMessage(AppClientLogicalViewProvider.class, "LBL_Node_ConfFiles"); 208 sourcesHelper.addPrincipalSourceRoot("${"+AppClientProjectProperties.META_INF+"}", configFilesLabel, null, null); 211 ProjectManager.mutex().postWriteRequest(new Runnable () { 212 public void run() { 213 sourcesHelper.registerExternalRoots(FileOwnerQuery.EXTERNAL_ALGORITHM_TRANSIENT); 214 } 215 }); 216 Lookup base = Lookups.fixed(new Object [] { 217 new Info(), 218 aux, 219 helper.createCacheDirectoryProvider(), 220 spp, 221 new AppClientActionProvider( this, helper, this.updateHelper ), 222 new AppClientLogicalViewProvider(this, this.updateHelper, evaluator(), refHelper), 223 new CustomizerProviderImpl(this, this.updateHelper, evaluator(), refHelper, this.genFilesHelper), 225 new ClassPathProviderImpl(this.helper, evaluator(), getSourceRoots(),getTestSourceRoots()), new CompiledSourceForBinaryQuery(this.helper, evaluator(),getSourceRoots(),getTestSourceRoots()), new JavadocForBinaryQueryImpl(this.helper, evaluator()), new AntArtifactProviderImpl(), 229 new ProjectXmlSavedHookImpl(), 230 new ProjectOpenedHookImpl(), 231 new UnitTestForSourceQueryImpl(getSourceRoots(),getTestSourceRoots()), 232 new SourceLevelQueryImpl(evaluator()), 233 new AppClientSources(this.helper, evaluator(), getSourceRoots(), getTestSourceRoots()), 234 new AppClientSharabilityQuery(this.helper, evaluator(), getSourceRoots(), getTestSourceRoots()), new AppClientFileBuiltQuery(this.helper, evaluator(),getSourceRoots(),getTestSourceRoots()), new RecommendedTemplatesImpl(this.updateHelper), 237 classpathExtender, 238 this, new AppClientProjectOperations(this), 240 new AppClientProjectWebServicesSupportProvider(), 241 242 new ProjectAppClientProvider(this), 243 appClient, 244 new AppClientPersistenceProvider(this, evaluator()), 245 enterpriseResourceSupport, 246 getJaxWsModel(), 247 UILookupMergerSupport.createPrivilegedTemplatesMerger(), 248 UILookupMergerSupport.createRecommendedTemplatesMerger(), 249 LookupProviderSupport.createSourcesMerger() 250 }); 251 return LookupProviderSupport.createCompositeLookup(base, "Projects/org-netbeans-modules-j2ee-clientproject/Lookup"); } 253 254 public void configurationXmlChanged(AntProjectEvent ev) { 255 if (ev.getPath().equals(AntProjectHelper.PROJECT_XML_PATH)) { 256 Info info = (Info)getLookup().lookup(ProjectInformation.class); 258 info.firePropertyChange(ProjectInformation.PROP_NAME); 259 info.firePropertyChange(ProjectInformation.PROP_DISPLAY_NAME); 260 } 261 } 262 263 public void propertiesChanged(AntProjectEvent ev) { 264 } 266 267 269 273 public synchronized SourceRoots getSourceRoots() { 274 if (this.sourceRoots == null) { this.sourceRoots = new SourceRoots(this.updateHelper, evaluator(), getReferenceHelper(), "source-roots", false, "src.{0}{1}.dir"); } 277 return this.sourceRoots; 278 } 279 280 public synchronized SourceRoots getTestSourceRoots() { 281 if (this.testRoots == null) { this.testRoots = new SourceRoots(this.updateHelper, evaluator(), getReferenceHelper(), "test-roots", true, "test.{0}{1}.dir"); } 284 return this.testRoots; 285 } 286 287 File getTestClassesDirectory() { 288 String testClassesDir = evaluator().getProperty(AppClientProjectProperties.BUILD_TEST_CLASSES_DIR); 289 if (testClassesDir == null) { 290 return null; 291 } 292 return helper.resolveFile(testClassesDir); 293 } 294 295 297 public void setName(final String name) { 298 ProjectManager.mutex().writeAccess(new Mutex.Action() { 299 public Object run() { 300 Element data = helper.getPrimaryConfigurationData(true); 301 NodeList nl = data.getElementsByTagNameNS(AppClientProjectType.PROJECT_CONFIGURATION_NAMESPACE, "name"); Element nameEl; 304 if (nl.getLength() == 1) { 305 nameEl = (Element ) nl.item(0); 306 NodeList deadKids = nameEl.getChildNodes(); 307 while (deadKids.getLength() > 0) { 308 nameEl.removeChild(deadKids.item(0)); 309 } 310 } else { 311 nameEl = data.getOwnerDocument().createElementNS(AppClientProjectType.PROJECT_CONFIGURATION_NAMESPACE, "name"); data.insertBefore(nameEl, data.getChildNodes().item(0)); 313 } 314 nameEl.appendChild(data.getOwnerDocument().createTextNode(name)); 315 helper.putPrimaryConfigurationData(data, true); 316 return null; 317 } 318 }); 319 } 320 321 322 public String getName() { 323 return (String ) ProjectManager.mutex().readAccess(new Mutex.Action() { 324 public Object run() { 325 Element data = updateHelper.getPrimaryConfigurationData(true); 326 NodeList nl = data.getElementsByTagNameNS(AppClientProjectType.PROJECT_CONFIGURATION_NAMESPACE, "name"); if (nl.getLength() == 1) { 329 nl = nl.item(0).getChildNodes(); 330 if (nl.getLength() == 1 && nl.item(0).getNodeType() == Node.TEXT_NODE) { 331 return ((Text ) nl.item(0)).getNodeValue(); 332 } 333 } 334 return "CAR???"; } 336 }); 337 } 338 339 public void fileAttributeChanged (FileAttributeEvent fe) { 340 } 341 342 public void fileChanged (FileEvent fe) { 343 } 344 345 public void fileDataCreated (FileEvent fe) { 346 FileObject fo = fe.getFile (); 347 checkLibraryFolder (fo); 348 } 349 350 public void fileDeleted (FileEvent fe) { 351 } 352 353 public void fileFolderCreated (FileEvent fe) { 354 } 355 356 public void fileRenamed (FileRenameEvent fe) { 357 FileObject fo = fe.getFile (); 358 checkLibraryFolder (fo); 359 } 360 361 private void checkLibraryFolder (FileObject fo) { 362 if (!FileUtil.isArchiveFile(fo)) { 363 return; 364 } 365 366 if (fo.getParent ().equals (libFolder)) { 367 try { 368 classpathExtender.addArchiveFile(fo); 369 } 370 catch (IOException e) { 371 ErrorManager.getDefault().notify(e); 372 } 373 } 374 } 375 376 public void registerJ2eePlatformListener(final J2eePlatform platform) { 377 j2eePlatformListener = new PropertyChangeListener () { 379 public void propertyChange(PropertyChangeEvent evt) { 380 if (evt.getPropertyName().equals(J2eePlatform.PROP_CLASSPATH)) { 381 ProjectManager.mutex().writeAccess(new Mutex.Action() { 382 public Object run() { 383 EditableProperties ep = helper.getProperties(AntProjectHelper.PRIVATE_PROPERTIES_PATH); 384 String classpath = Utils.toClasspathString(platform.getClasspathEntries()); 385 ep.setProperty(AppClientProjectProperties.J2EE_PLATFORM_CLASSPATH, classpath); 386 helper.putProperties(AntProjectHelper.PRIVATE_PROPERTIES_PATH, ep); 387 try { 388 ProjectManager.getDefault().saveProject(AppClientProject.this); 389 } catch (IOException e) { 390 ErrorManager.getDefault().notify(e); 391 } 392 return null; 393 } 394 }); 395 } 396 } 397 }; 398 platform.addPropertyChangeListener(j2eePlatformListener); 399 } 400 401 public void unregisterJ2eePlatformListener(J2eePlatform platform) { 402 if (j2eePlatformListener != null) { 403 platform.removePropertyChangeListener(j2eePlatformListener); 404 } 405 } 406 407 public Car getAPICar() { 408 return apiJar; 409 } 410 411 public AppClientProvider getCarModule() { 412 return appClient; 413 } 414 415 416 private String getProperty(String path, String name) { 417 return helper.getProperties(path).getProperty(name); 418 } 419 420 String getBuildXmlName() { 421 String storedName = helper.getStandardPropertyEvaluator().getProperty(AppClientProjectProperties.BUILD_FILE); 422 return storedName == null ? GeneratedFilesHelper.BUILD_XML_PATH : storedName; 423 } 424 425 434 private void refreshBuildImplXml(int askUserIfFlags, boolean askInCurrentThread) { 435 askUserIfFlags |= GeneratedFilesHelper.FLAG_MODIFIED; 436 int flags = genFilesHelper.getBuildScriptState( 437 GeneratedFilesHelper.BUILD_IMPL_XML_PATH, 438 AppClientProject.class.getResource("resources/build-impl.xsl"), jaxWsFo); if ((flags & askUserIfFlags) == askUserIfFlags) { 440 Runnable run = new Runnable () { 441 public void run () { 442 JButton updateOption = new JButton (NbBundle.getMessage(AppClientProject.class, "CTL_Regenerate")); 443 if (DialogDisplayer.getDefault().notify( 444 new NotifyDescriptor (NbBundle.getMessage(AppClientProject.class,"TXT_BuildImplRegenerate"), 445 NbBundle.getMessage(AppClientProject.class,"TXT_BuildImplRegenerateTitle"), 446 NotifyDescriptor.DEFAULT_OPTION, 447 NotifyDescriptor.WARNING_MESSAGE, 448 new Object [] { 449 updateOption, 450 NotifyDescriptor.CANCEL_OPTION 451 }, 452 updateOption)) == updateOption) { 453 try { 454 genFilesHelper.generateBuildScriptFromStylesheet( 455 GeneratedFilesHelper.BUILD_IMPL_XML_PATH, 456 AppClientProject.class.getResource("resources/build-impl.xsl"), jaxWsFo); } catch (IOException e) { 458 ErrorManager.getDefault().notify(e); 459 } catch (IllegalStateException e) { 460 ErrorManager.getDefault().notify(e); 461 } 462 } 463 } 464 }; 465 if (askInCurrentThread) { 466 run.run(); 467 } else { 468 RequestProcessor.getDefault().post(run); 469 } 470 } else { 471 try { 472 genFilesHelper.refreshBuildScript( 473 GeneratedFilesHelper.BUILD_IMPL_XML_PATH, 474 AppClientProject.class.getResource("resources/build-impl.xsl"), jaxWsFo, false); 476 } catch (IOException e) { 477 ErrorManager.getDefault().notify(e); 478 } 479 } 480 } 481 482 484 private final class Info implements ProjectInformation { 485 486 private final PropertyChangeSupport pcs = new PropertyChangeSupport (this); 487 488 Info() {} 489 490 void firePropertyChange(String prop) { 491 pcs.firePropertyChange(prop, null, null); 492 } 493 494 public String getName() { 495 return PropertyUtils.getUsablePropertyName(getDisplayName()); 496 } 497 498 public String getDisplayName() { 499 return (String ) ProjectManager.mutex().readAccess(new Mutex.Action() { 500 public Object run() { 501 Element data = updateHelper.getPrimaryConfigurationData(true); 502 NodeList nl = data.getElementsByTagNameNS(AppClientProjectType.PROJECT_CONFIGURATION_NAMESPACE, "name"); if (nl.getLength() == 1) { 505 nl = nl.item(0).getChildNodes(); 506 if (nl.getLength() == 1 && nl.item(0).getNodeType() == Node.TEXT_NODE) { 507 return ((Text ) nl.item(0)).getNodeValue(); 508 } 509 } 510 return "???"; } 512 }); 513 } 514 515 public Icon getIcon() { 516 return CAR_PROJECT_ICON; 517 } 518 519 public Project getProject() { 520 return AppClientProject.this; 521 } 522 523 public void addPropertyChangeListener(PropertyChangeListener listener) { 524 pcs.addPropertyChangeListener(listener); 525 } 526 527 public void removePropertyChangeListener(PropertyChangeListener listener) { 528 pcs.removePropertyChangeListener(listener); 529 } 530 531 } 532 533 private final class ProjectXmlSavedHookImpl extends ProjectXmlSavedHook { 534 535 ProjectXmlSavedHookImpl() {} 536 537 protected void projectXmlSaved() throws IOException { 538 refreshBuildImplXml(0, false); 539 540 genFilesHelper.refreshBuildScript( 541 getBuildXmlName(), 542 AppClientProject.class.getResource("resources/build.xsl"), jaxWsFo, false); 544 } 545 546 } 547 548 549 final class ProjectOpenedHookImpl extends ProjectOpenedHook { 550 551 ProjectOpenedHookImpl() {} 552 553 protected void projectOpened() { 554 try { 556 String libFolderName = helper.getStandardPropertyEvaluator ().getProperty (AppClientProjectProperties.LIBRARIES_DIR); 558 559 try { 561 FileObject ddFO = appClient.getDeploymentDescriptor(); 562 if (ddFO != null) { 563 DataObject.find(ddFO); 564 } 565 } catch (DataObjectNotFoundException ex) {} 566 567 if (libFolderName != null && helper.resolveFile (libFolderName).isDirectory ()) { 568 libFolder = helper.resolveFileObject(libFolderName); 569 FileObject children [] = libFolder.getChildren (); 570 List <FileObject> libs = new LinkedList <FileObject>(); 571 for (int i = 0; i < children.length; i++) { 572 if (FileUtil.isArchiveFile(children[i])) { 573 libs.add(children[i]); 574 } 575 } 576 FileObject[] libsArray = new FileObject[libs.size()]; 577 libs.toArray(libsArray); 578 classpathExtender.addArchiveFiles(AppClientProjectProperties.JAVAC_CLASSPATH, libsArray, ClassPathSupport.ELEMENT_INCLUDED_LIBRARIES); 579 libFolder.addFileChangeListener (AppClientProject.this); 580 } 581 582 584 refreshBuildImplXml( GeneratedFilesHelper.FLAG_OLD_PROJECT_XML, true); 585 586 genFilesHelper.refreshBuildScript( 587 getBuildXmlName(), 588 AppClientProject.class.getResource("resources/build.xsl"), jaxWsFo, true); 590 591 String servInstID = getProperty(AntProjectHelper.PRIVATE_PROPERTIES_PATH, AppClientProjectProperties.J2EE_SERVER_INSTANCE); 592 J2eePlatform platform = Deployment.getDefault().getJ2eePlatform(servInstID); 593 if (platform != null) { 594 AppClientProjectProperties.setServerInstance(AppClientProject.this, AppClientProject.this.helper, servInstID); 596 } else { 597 String serverType = getProperty(AntProjectHelper.PROJECT_PROPERTIES_PATH, AppClientProjectProperties.J2EE_SERVER_TYPE); 600 if (serverType != null) { 601 String [] servInstIDs = Deployment.getDefault().getInstancesOfServer(serverType); 602 if (servInstIDs.length > 0) { 603 AppClientProjectProperties.setServerInstance(AppClientProject.this, AppClientProject.this.helper, servInstIDs[0]); 604 platform = Deployment.getDefault().getJ2eePlatform(servInstIDs[0]); 605 } 606 } 607 if (platform == null) { 608 BrokenServerSupport.showAlert(); 609 } 610 } 611 } catch (IOException e) { 612 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e); 613 } 614 615 616 ClassPathProviderImpl cpProvider = (ClassPathProviderImpl)lookup.lookup(ClassPathProviderImpl.class); 618 GlobalPathRegistry.getDefault().register(ClassPath.BOOT, cpProvider.getProjectClassPaths(ClassPath.BOOT)); 619 GlobalPathRegistry.getDefault().register(ClassPath.SOURCE, cpProvider.getProjectClassPaths(ClassPath.SOURCE)); 620 GlobalPathRegistry.getDefault().register(ClassPath.COMPILE, cpProvider.getProjectClassPaths(ClassPath.COMPILE)); 621 622 appClient.getConfigSupport().ensureConfigurationReady(); 626 627 mainClassUpdater = new MainClassUpdater(AppClientProject.this, eval, updateHelper, 630 cpProvider.getProjectClassPaths(ClassPath.SOURCE)[0], AppClientProjectProperties.MAIN_CLASS); 631 632 ProjectManager.mutex().writeAccess(new Mutex.Action() { 634 public Object run() { 635 EditableProperties ep = updateHelper.getProperties(AntProjectHelper.PRIVATE_PROPERTIES_PATH); 636 File buildProperties = new File (System.getProperty("netbeans.user"), "build.properties"); ep.setProperty("user.properties.file", buildProperties.getAbsolutePath()); 639 WSUtils.setJaxWsEndorsedDirProperty(ep); 641 642 updateHelper.putProperties(AntProjectHelper.PRIVATE_PROPERTIES_PATH, ep); 643 try { 644 ProjectManager.getDefault().saveProject(AppClientProject.this); 645 } catch (IOException e) { 646 ErrorManager.getDefault().notify(e); 647 } 648 return null; 649 } 650 }); 651 AppClientLogicalViewProvider physicalViewProvider = (AppClientLogicalViewProvider) 652 AppClientProject.this.getLookup().lookup(AppClientLogicalViewProvider.class); 653 if (physicalViewProvider != null && physicalViewProvider.hasBrokenLinks()) { 654 BrokenReferencesSupport.showAlert(); 655 } 656 } 657 658 protected void projectClosed() { 659 660 String servInstID = getProperty(AntProjectHelper.PRIVATE_PROPERTIES_PATH, AppClientProjectProperties.J2EE_SERVER_INSTANCE); 662 J2eePlatform platform = Deployment.getDefault().getJ2eePlatform(servInstID); 663 if (platform != null) { 664 unregisterJ2eePlatformListener(platform); 665 } 666 667 if (jaxWsFo!=null) { 669 jaxWsFo.removeFileChangeListener(jaxWsListener); 670 } 671 672 try { 674 ProjectManager.getDefault().saveProject(AppClientProject.this); 675 } catch (IOException e) { 676 ErrorManager.getDefault().notify(e); 677 } 678 679 ClassPathProviderImpl cpProvider = (ClassPathProviderImpl)lookup.lookup(ClassPathProviderImpl.class); 681 GlobalPathRegistry.getDefault().unregister(ClassPath.BOOT, cpProvider.getProjectClassPaths(ClassPath.BOOT)); 682 GlobalPathRegistry.getDefault().unregister(ClassPath.SOURCE, cpProvider.getProjectClassPaths(ClassPath.SOURCE)); 683 GlobalPathRegistry.getDefault().unregister(ClassPath.COMPILE, cpProvider.getProjectClassPaths(ClassPath.COMPILE)); 684 if (mainClassUpdater != null) { 685 mainClassUpdater.unregister(); 686 mainClassUpdater = null; 687 } 688 } 689 690 } 691 692 public WebServicesClientSupport getAPIWebServicesClientSupport() { 693 return apiWebServicesClientSupport; 694 } 695 696 public JAXWSClientSupport getAPIJAXWSClientSupport() { 697 return apiJAXWSClientSupport; 698 } 699 700 701 705 public void createJaxWsFileObject() throws IOException { 706 FileObject projectDir = helper.getProjectDirectory(); 707 WSUtils.retrieveJaxWsFromResource(projectDir); 708 709 jaxWsFo = findJaxWsFileObject(projectDir); 710 if (jaxWsFo!=null) { 711 jaxWsListener = new JaxWsListener(); 712 jaxWsFo.addFileChangeListener(jaxWsListener); 713 714 if (jaxWsModel!=null) { 715 jaxWsModel.setJaxWsFile(jaxWsFo); 716 } else { 717 jaxWsModel = JaxWsModelProvider.getDefault().getJaxWsModel(jaxWsFo); 718 } 719 } 720 } 721 722 private JaxWsModel getJaxWsModel() { 723 if (jaxWsModel==null) 724 try { 725 final FileObject projectDir = helper.getProjectDirectory(); 726 jaxWsFo = findJaxWsFileObject(projectDir); 727 if (jaxWsFo==null) { 728 jaxWsModel = JaxWsModelProvider.getDefault().getJaxWsModel( 730 WSUtils.class.getResourceAsStream("/org/netbeans/modules/websvc/jaxwsmodel/resources/jax-ws.xml")); jaxWsModel.setJaxWsFile(projectDir); 732 } else { 733 jaxWsListener = new JaxWsListener(); 734 try { 735 jaxWsModel = JaxWsModelProvider.getDefault().getJaxWsModel(jaxWsFo); 736 jaxWsFo.addFileChangeListener(jaxWsListener); 737 } catch (RuntimeException ex) { 738 jaxWsModel = JaxWsModelProvider.getDefault().getJaxWsModel( 740 WSUtils.class.getResourceAsStream("/org/netbeans/modules/websvc/jaxwsmodel/resources/jax-ws.xml")); jaxWsModel.setJaxWsFile(projectDir); 742 final FileObject oldJaxWsFo = jaxWsFo; 743 jaxWsFo=null; 744 final RuntimeException exception = ex; 745 RequestProcessor.getDefault().post(new Runnable () { 746 public void run() { 747 try { 748 jaxWsFo = WSUtils.backupAndGenerateJaxWs(projectDir, oldJaxWsFo, exception); 749 if (jaxWsFo!=null) { 750 jaxWsModel.setJaxWsFile(jaxWsFo); 751 jaxWsFo.addFileChangeListener(jaxWsListener); 752 } 753 } catch (IOException ex) { 754 ErrorManager.getDefault().log(ex.getLocalizedMessage()); 755 } 756 } 757 }); 758 } 759 } 760 } catch (IOException ex) { 761 ErrorManager.getDefault().log(ex.getLocalizedMessage()); 762 } 763 return jaxWsModel; 764 } 765 766 public FileObject findJaxWsFileObject() { 767 return findJaxWsFileObject(helper.getProjectDirectory()); 768 } 769 770 private FileObject findJaxWsFileObject(FileObject projectDir) { 771 return projectDir.getFileObject(GeneratedFilesHelper.JAX_WS_XML_PATH); 772 } 773 774 778 private final class AntArtifactProviderImpl implements AntArtifactProvider { 779 780 public AntArtifact[] getBuildArtifacts() { 781 return new AntArtifact[] { 782 helper.createSimpleAntArtifact(JavaProjectConstants.ARTIFACT_TYPE_JAR, "dist.jar", helper.getStandardPropertyEvaluator(), "dist", "clean"), new CarAntArtifact(helper.createSimpleAntArtifact(AppClientProjectConstants.ARTIFACT_TYPE_J2EE_MODULE_IN_EAR_ARCHIVE, "dist.ear.jar", helper.getStandardPropertyEvaluator(), "dist-ear", "clean-ear")) }; 786 } 787 788 } 789 790 private static final class RecommendedTemplatesImpl implements RecommendedTemplates, PrivilegedTemplates { 791 792 RecommendedTemplatesImpl(UpdateHelper helper) { 793 this.helper = helper; 794 } 795 796 transient private final UpdateHelper helper; 797 transient private boolean isArchive = false; 798 799 801 private static final String [] APPLICATION_TYPES = new String [] { 802 "java-classes", "java-main-class", "j2ee-types", "java-forms", "gui-java-application", "java-beans", "persistence", "oasis-XML-catalogs", "XML", "ant-script", "ant-task", "web-service-clients", "wsdl", "sunresource-types", "junit", "simple-files" }; 821 822 private static final String [] PRIVILEGED_NAMES = new String [] { 823 "Templates/Classes/Class.java", "Templates/Classes/Package", "Templates/Classes/Interface.java", "Templates/GUIForms/JPanel.java", "Templates/GUIForms/JFrame.java", "Templates/J2EE/CachingServiceLocator.java", "Templates/WebServices/WebServiceClient" }; 831 832 private static final String [] APPLICATION_TYPES_ARCHIVE = new String [] { 833 "deployment-descriptor", "XML", }; 836 837 private static final String [] PRIVILEGED_NAMES_ARCHIVE = new String [] { 838 "Templates/J2EE/applicationClientXml," }; 840 841 public String [] getRecommendedTypes() { 842 String [] retVal = null; 843 checkEnvironment(); 844 if (isArchive) { 845 retVal = APPLICATION_TYPES_ARCHIVE.clone(); 846 } else { 847 retVal = APPLICATION_TYPES.clone(); 848 } 849 return retVal; 850 } 851 852 public String [] getPrivilegedTemplates() { 853 String [] retVal = null; 854 checkEnvironment(); 855 if (isArchive) { 856 retVal = PRIVILEGED_NAMES_ARCHIVE.clone(); 857 } else { 858 retVal = PRIVILEGED_NAMES.clone(); 859 } 860 return retVal; 861 } 862 863 transient private boolean checked = false; 864 865 private void checkEnvironment() { 866 if (!checked) { 867 final Object srcType = helper.getAntProjectHelper(). 868 getStandardPropertyEvaluator().getProperty(AppClientProjectProperties.JAVA_SOURCE_BASED); 869 if ("false".equals(srcType)) { 870 isArchive = true; 871 } 872 checked = true; 873 } 874 } 875 876 } 877 878 private final class CarAntArtifact extends AntArtifact { 879 880 private final AntArtifact impl; 881 882 CarAntArtifact(AntArtifact aa) { 883 impl = aa; 884 } 885 886 public String getID() { 887 if (AppClientProjectConstants.ARTIFACT_TYPE_J2EE_MODULE_IN_EAR_ARCHIVE.equals(getType())) { 888 return AppClientProjectConstants.CAR_ANT_ARTIFACT_ID; 889 } 890 return impl.getID(); 891 } 892 893 public String getType() { 894 return impl.getType(); 895 } 896 897 public String getTargetName() { 898 return impl.getTargetName(); 899 } 900 901 public File getScriptLocation() { 902 return impl.getScriptLocation(); 903 } 904 905 public String getCleanTargetName() { 906 return impl.getCleanTargetName(); 907 } 908 909 public URI [] getArtifactLocations() { 910 return impl.getArtifactLocations(); 911 } 912 913 public Project getProject() { 914 return impl.getProject(); 915 } 916 917 } 918 919 private class JaxWsListener extends FileChangeAdapter { 920 public void fileChanged(FileEvent fe) { 921 try { 922 final JaxWsModel newModel = JaxWsModelProvider.getDefault().getJaxWsModel(fe.getFile()); 923 RequestProcessor.getDefault().post(new Runnable () { 924 public void run() { 925 if (jaxWsModel!=null && newModel!=null) { 926 jaxWsModel.merge(newModel); 927 } 928 try { 929 genFilesHelper.refreshBuildScript( 930 GeneratedFilesHelper.BUILD_IMPL_XML_PATH, 931 AppClientProject.class.getResource("resources/build-impl.xsl"), jaxWsFo, false); 933 } catch (IOException ex) {} 934 } 935 936 }); 937 938 } catch (IOException ex) {} 939 } 940 } 941 942 } 943 944 | Popular Tags |