1 19 20 package org.netbeans.modules.j2ee.ejbjarproject; 21 22 import java.awt.Dialog ; 23 import java.beans.PropertyChangeEvent ; 24 import java.beans.PropertyChangeListener ; 25 import java.beans.PropertyChangeSupport ; 26 import java.io.IOException ; 27 import java.util.*; 28 import javax.swing.Icon ; 29 import javax.swing.ImageIcon ; 30 import javax.swing.JButton ; 31 import javax.swing.SwingUtilities ; 32 import org.netbeans.api.java.classpath.ClassPath; 33 import org.netbeans.api.java.classpath.GlobalPathRegistry; 34 import org.netbeans.api.java.project.JavaProjectConstants; 35 import org.netbeans.api.project.FileOwnerQuery; 36 import org.netbeans.api.project.Project; 37 import org.netbeans.api.project.ProjectManager; 38 import org.netbeans.api.project.ant.AntArtifact; 39 import org.netbeans.modules.j2ee.api.ejbjar.EjbJar; 40 import org.netbeans.modules.j2ee.api.ejbjar.EjbProjectConstants; 41 import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule; 42 import org.netbeans.modules.j2ee.ejbjarproject.classpath.ClassPathSupport; 43 import org.netbeans.modules.j2ee.ejbjarproject.classpath.ClassPathProviderImpl; 44 import org.netbeans.modules.j2ee.ejbjarproject.classpath.EjbJarProjectClassPathExtender; 45 import org.netbeans.modules.j2ee.ejbjarproject.jaxws.EjbJAXWSMetadataFinder; 46 import org.netbeans.modules.j2ee.ejbjarproject.jaxws.EjbProjectJAXWSClientSupport; 47 import org.netbeans.modules.j2ee.ejbjarproject.jaxws.EjbProjectJAXWSSupport; 48 import org.netbeans.modules.j2ee.ejbjarproject.queries.CompiledSourceForBinaryQuery; 49 import org.netbeans.modules.j2ee.ejbjarproject.queries.JavadocForBinaryQueryImpl; 50 import org.netbeans.modules.j2ee.ejbjarproject.queries.UnitTestForSourceQueryImpl; 51 import org.netbeans.modules.j2ee.ejbjarproject.ui.EjbJarLogicalViewProvider; 52 import org.netbeans.modules.j2ee.ejbjarproject.ui.customizer.EjbJarProjectProperties; 53 import org.netbeans.api.project.ProjectInformation; 54 import org.netbeans.modules.j2ee.common.ui.BrokenServerSupport; 55 import org.netbeans.modules.j2ee.spi.ejbjar.EjbJarFactory; 56 import org.netbeans.modules.j2ee.spi.ejbjar.support.EjbEnterpriseReferenceContainerSupport; 57 import org.netbeans.modules.websvc.api.jaxws.client.JAXWSClientSupport; 58 import org.netbeans.modules.websvc.api.jaxws.project.WSUtils; 59 import org.netbeans.modules.websvc.jaxws.api.JAXWSSupport; 60 import org.netbeans.modules.websvc.api.jaxws.project.config.JaxWsModel; 61 import org.netbeans.modules.websvc.api.jaxws.project.config.JaxWsModelProvider; 62 import org.netbeans.modules.websvc.api.jaxws.project.GeneratedFilesHelper; 63 import org.netbeans.modules.websvc.jaxws.spi.JAXWSSupportFactory; 64 import org.netbeans.modules.websvc.spi.client.WebServicesClientSupportFactory; 65 import org.netbeans.modules.websvc.spi.jaxws.client.JAXWSClientSupportFactory; 66 import org.netbeans.spi.project.SubprojectProvider; 67 import org.netbeans.spi.project.ant.AntArtifactProvider; 68 import org.netbeans.spi.project.support.ant.AntProjectEvent; 69 import org.netbeans.spi.project.support.ant.AntProjectHelper; 70 import org.netbeans.spi.project.support.ant.AntProjectListener; 71 import org.netbeans.spi.project.support.ant.ProjectXmlSavedHook; 72 import org.netbeans.spi.project.ui.PrivilegedTemplates; 73 import org.netbeans.spi.project.ui.RecommendedTemplates; 74 import org.netbeans.spi.project.support.ant.ReferenceHelper; 75 import org.netbeans.spi.project.support.ant.PropertyEvaluator; 76 import org.netbeans.spi.project.support.ant.SourcesHelper; 77 import org.netbeans.spi.project.ui.ProjectOpenedHook; 78 import org.openide.ErrorManager; 79 import org.openide.filesystems.FileChangeAdapter; 80 import org.openide.filesystems.FileChangeListener; 81 import org.openide.filesystems.FileEvent; 82 import org.openide.filesystems.FileObject; 83 import org.openide.filesystems.FileUtil; 84 import org.openide.loaders.DataObject; 85 import org.openide.util.Lookup; 86 import org.openide.util.Mutex; 87 import org.openide.util.RequestProcessor; 88 import org.openide.util.Utilities; 89 import org.openide.util.WeakListeners; 90 import org.openide.util.lookup.Lookups; 91 import org.netbeans.modules.j2ee.deployment.devmodules.api.Deployment; 92 import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eePlatform; 93 import org.netbeans.modules.j2ee.ejbjarproject.ui.BrokenReferencesAlertPanel; 94 import org.netbeans.modules.j2ee.ejbjarproject.ui.FoldersListSettings; 95 import org.netbeans.modules.j2ee.ejbjarproject.ui.customizer.CustomizerProviderImpl; 96 import org.netbeans.modules.j2ee.ejbjarproject.queries.SourceLevelQueryImpl; 97 import org.netbeans.spi.java.project.support.ui.BrokenReferencesSupport; 98 import org.netbeans.spi.project.AuxiliaryConfiguration; 99 import org.netbeans.spi.project.support.ant.EditableProperties; 100 import org.openide.DialogDescriptor; 101 import org.openide.DialogDisplayer; 102 import org.openide.util.NbBundle; 103 import org.w3c.dom.Document ; 104 import org.w3c.dom.Comment ; 105 import org.w3c.dom.Element ; 106 import org.w3c.dom.Node ; 107 import org.w3c.dom.NodeList ; 108 import org.w3c.dom.Text ; 109 import org.netbeans.modules.websvc.api.webservices.WebServicesSupport; 110 import org.netbeans.modules.websvc.api.client.WebServicesClientSupport; 111 import org.netbeans.modules.websvc.spi.webservices.WebServicesSupportFactory; 112 import org.netbeans.spi.project.support.LookupProviderSupport; 113 import org.netbeans.spi.project.ui.support.UILookupMergerSupport; 114 import org.openide.NotifyDescriptor; 115 116 120 public class EjbJarProject implements Project, AntProjectListener, FileChangeListener, PropertyChangeListener { 121 122 private static final Icon PROJECT_ICON = new ImageIcon (Utilities.loadImage("org/netbeans/modules/j2ee/ejbjarproject/ui/resources/ejbjarProjectIcon.gif")); 124 private final AuxiliaryConfiguration aux; 125 private final AntProjectHelper helper; 126 private final PropertyEvaluator eval; 127 private final ReferenceHelper refHelper; 128 private FileObject libFolder = null; 129 private final GeneratedFilesHelper genFilesHelper; 130 private final Lookup lookup; 131 private final UpdateHelper updateHelper; 132 private final EjbJarProvider ejbModule; 133 private final EjbJar apiEjbJar; 134 private WebServicesSupport apiWebServicesSupport; 135 private JAXWSSupport apiJaxwsSupport; 136 private EjbProjectJAXWSSupport jaxwsSupport; 137 private WebServicesClientSupport apiWebServicesClientSupport; 138 private JAXWSClientSupport apiJAXWSClientSupport; 139 private EjbJarWebServicesSupport ejbJarWebServicesSupport; 140 private EjbJarWebServicesClientSupport ejbJarWebServicesClientSupport; 141 private EjbProjectJAXWSClientSupport jaxWsClientSupport; 142 private SourceRoots sourceRoots; 143 private SourceRoots testRoots; 144 private PropertyHelper propertyHelper; 145 private final EjbJarProjectClassPathExtender classpathExtender; 146 private PropertyChangeListener j2eePlatformListener; 147 private PropertyChangeListener evalListener; 148 private JaxWsModel jaxWsModel; 149 private JaxWsListener jaxWsListener; 150 private FileObject jaxWsFo; 151 private JaxWsModel.ServiceListener jaxWsServiceListener; 152 153 209 210 EjbJarProject(final AntProjectHelper helper) throws IOException { 211 this.helper = helper; 212 eval = createEvaluator(); 213 aux = helper.createAuxiliaryConfiguration(); 215 refHelper = new ReferenceHelper(helper, aux, helper.getStandardPropertyEvaluator()); 216 genFilesHelper = new GeneratedFilesHelper(helper); 217 ejbModule = new EjbJarProvider(this, helper); 218 apiEjbJar = EjbJarFactory.createEjbJar(ejbModule); 219 ejbJarWebServicesSupport = new EjbJarWebServicesSupport(this, helper, refHelper); 220 jaxwsSupport = new EjbProjectJAXWSSupport(this, helper); 221 ejbJarWebServicesClientSupport = new EjbJarWebServicesClientSupport(this, helper, refHelper); 222 jaxWsClientSupport = new EjbProjectJAXWSClientSupport(this); 223 apiWebServicesSupport = WebServicesSupportFactory.createWebServicesSupport(ejbJarWebServicesSupport); 224 apiJaxwsSupport = JAXWSSupportFactory.createJAXWSSupport(jaxwsSupport); 225 apiWebServicesClientSupport = WebServicesClientSupportFactory.createWebServicesClientSupport(ejbJarWebServicesClientSupport); 226 apiJAXWSClientSupport = JAXWSClientSupportFactory.createJAXWSClientSupport(jaxWsClientSupport); 227 this.updateHelper = new UpdateHelper (this, this.helper, this.aux, this.genFilesHelper, 228 UpdateHelper.createDefaultNotifier()); 229 classpathExtender = new EjbJarProjectClassPathExtender(this, updateHelper, evaluator(), refHelper); 230 lookup = createLookup(aux); 231 helper.addAntProjectListener(this); 232 ProjectManager.mutex().postWriteRequest( 233 new Runnable () { 234 public void run() { 235 try { 236 updateProjectXML (); 237 } catch (IOException ioe) { 238 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ioe); 239 } 240 } 241 } 242 ); 243 } 244 245 249 public FileObject getProjectDirectory() { 250 return helper.getProjectDirectory(); 251 } 252 253 public String toString() { 254 return "EjbJarProject[" + getProjectDirectory() + "]"; } 256 257 private PropertyEvaluator createEvaluator() { 258 PropertyEvaluator eval = helper.getStandardPropertyEvaluator(); 259 evalListener = WeakListeners.propertyChange(this, eval); 260 eval.addPropertyChangeListener(evalListener); 261 return eval; 262 } 263 264 PropertyEvaluator evaluator() { 265 return eval; 266 } 267 268 public ReferenceHelper getReferenceHelper () { 269 return this.refHelper; 270 } 271 272 public UpdateHelper getUpdateHelper() { 273 return updateHelper; 274 } 275 276 public Lookup getLookup() { 277 return lookup; 278 } 279 280 public AntProjectHelper getAntProjectHelper() { 281 return helper; 282 } 283 284 private Lookup createLookup(AuxiliaryConfiguration aux) { 285 SubprojectProvider spp = refHelper.createSubprojectProvider(); 286 287 final SourcesHelper sourcesHelper = new SourcesHelper(helper, evaluator()); 288 String ejbModuleLabel = org.openide.util.NbBundle.getMessage(EjbJarLogicalViewProvider.class, "LBL_Node_EJBModule"); String configFilesLabel = org.openide.util.NbBundle.getMessage(EjbJarLogicalViewProvider.class, "LBL_Node_DocBase"); 291 sourcesHelper.addPrincipalSourceRoot("${"+EjbJarProjectProperties.SOURCE_ROOT+"}", ejbModuleLabel, null, null); 292 sourcesHelper.addPrincipalSourceRoot("${"+EjbJarProjectProperties.META_INF+"}", configFilesLabel, null, null); 293 294 ProjectManager.mutex().postWriteRequest(new Runnable () { 295 public void run() { 296 sourcesHelper.registerExternalRoots(FileOwnerQuery.EXTERNAL_ALGORITHM_TRANSIENT); 297 } 298 }); 299 Lookup base = Lookups.fixed(new Object [] { 300 new Info(), 301 aux, 302 helper.createCacheDirectoryProvider(), 303 new ProjectWebServicesSupportProvider(), spp, 305 EjbEnterpriseReferenceContainerSupport.createEnterpriseReferenceContainer(this, helper), 306 new ProjectEjbJarProvider(this), 307 ejbModule, new EjbJarActionProvider( this, helper, refHelper ), 309 new EjbJarLogicalViewProvider(this, updateHelper, evaluator(), spp, refHelper), 310 new CustomizerProviderImpl( this, updateHelper, evaluator(), refHelper ), 311 new ClassPathProviderImpl(helper, evaluator(), getSourceRoots(),getTestSourceRoots()), 312 new CompiledSourceForBinaryQuery(helper,evaluator(),getSourceRoots(),getTestSourceRoots()), 313 new JavadocForBinaryQueryImpl(helper, evaluator()), 314 new AntArtifactProviderImpl(), 315 new ProjectXmlSavedHookImpl(), 316 new ProjectOpenedHookImpl(), 317 new UnitTestForSourceQueryImpl(getSourceRoots(),getTestSourceRoots()), 318 new SourceLevelQueryImpl(helper, evaluator()), 319 new EjbJarSources (helper, evaluator(), getSourceRoots(), getTestSourceRoots()), 320 new EjbJarSharabilityQuery(helper, evaluator(), getSourceRoots(), getTestSourceRoots()), 321 new EjbJarFileBuiltQuery (helper, evaluator(),getSourceRoots(),getTestSourceRoots()), 322 new RecommendedTemplatesImpl(updateHelper), 323 refHelper, 324 classpathExtender, 325 new EjbJarProjectOperations(this), 326 new EjbJarPersistenceProvider(this, evaluator()), 327 new EjbJAXWSMetadataFinder(this), 328 getJaxWsModel(), 329 new EjbJarEMGenStrategyResolver(), 330 new EjbJarJPASupport(this), 331 new EjbJarServerStatusProvider(this), 332 new EjbJarJPAModuleInfo(this), 333 UILookupMergerSupport.createPrivilegedTemplatesMerger(), 334 UILookupMergerSupport.createRecommendedTemplatesMerger(), 335 LookupProviderSupport.createSourcesMerger() 336 }); 338 return LookupProviderSupport.createCompositeLookup(base, "Projects/org-netbeans-modules-j2ee-ejbjarproject/Lookup"); } 340 341 public void configurationXmlChanged(AntProjectEvent ev) { 342 if (ev.getPath().equals(AntProjectHelper.PROJECT_XML_PATH)) { 343 Info info = (Info)getLookup().lookup(ProjectInformation.class); 345 info.firePropertyChange(ProjectInformation.PROP_NAME); 346 info.firePropertyChange(ProjectInformation.PROP_DISPLAY_NAME); 347 } 348 } 349 350 public void propertiesChanged(AntProjectEvent ev) { 351 } 354 355 String getBuildXmlName() { 356 String storedName = helper.getStandardPropertyEvaluator().getProperty(EjbJarProjectProperties.BUILD_FILE); 357 return storedName == null ? GeneratedFilesHelper.BUILD_XML_PATH : storedName; 358 } 359 360 362 366 public synchronized SourceRoots getSourceRoots() { 367 if (this.sourceRoots == null) { this.sourceRoots = new SourceRoots(this.updateHelper, evaluator(), getReferenceHelper(), "source-roots", false, "src.{0}{1}.dir"); } 370 return this.sourceRoots; 371 } 372 373 public synchronized SourceRoots getTestSourceRoots() { 374 if (this.testRoots == null) { this.testRoots = new SourceRoots(this.updateHelper, evaluator(), getReferenceHelper(), "test-roots", true, "test.{0}{1}.dir"); } 377 return this.testRoots; 378 } 379 380 381 382 WebServicesSupport getAPIWebServicesSupport() { 383 return apiWebServicesSupport; 384 } 385 386 JAXWSSupport getAPIJAXWSSupport () { 387 return apiJaxwsSupport; 388 } 389 390 WebServicesClientSupport getAPIWebServicesClientSupport () { 391 return apiWebServicesClientSupport; 392 } 393 394 JAXWSClientSupport getAPIJAXWSClientSupport () { 395 return apiJAXWSClientSupport; 396 } 397 398 401 402 public PropertyHelper getPropertyHelper() { 403 if (propertyHelper == null) { 404 this.propertyHelper = new PropertyHelper(this, this.updateHelper); 405 } 406 return this.propertyHelper; 407 } 408 409 public EjbJarProvider getEjbModule() { 410 return ejbModule; 411 } 412 413 public EjbJar getAPIEjbJar() { 414 return apiEjbJar; 415 } 416 417 418 private static long brokenAlertLastTime = 0; 419 420 421 private static boolean brokenAlertShown = false; 422 423 424 private static int BROKEN_ALERT_TIMEOUT = 1000; 425 426 private static synchronized void showBrokenReferencesAlert() { 427 if (brokenAlertShown || 430 brokenAlertLastTime+BROKEN_ALERT_TIMEOUT > System.currentTimeMillis() || 431 !FoldersListSettings.getDefault().isShowAgainBrokenRefAlert()) { 432 return; 433 } 434 brokenAlertShown = true; 435 SwingUtilities.invokeLater(new Runnable () { 436 public void run() { 437 try { 438 Object ok = NbBundle.getMessage(BrokenReferencesAlertPanel.class,"MSG_Broken_References_OK"); 439 DialogDescriptor dd = new DialogDescriptor(new BrokenReferencesAlertPanel(), 440 NbBundle.getMessage(BrokenReferencesAlertPanel.class, "MSG_Broken_References_Title"), 441 true, new Object [] {ok}, ok, DialogDescriptor.DEFAULT_ALIGN, null, null); 442 Dialog dlg = null; 443 try { 444 dlg = DialogDisplayer.getDefault().createDialog(dd); 445 dlg.setVisible(true); 446 } finally { 447 if (dlg != null) 448 dlg.dispose(); 449 } 450 } finally { 451 synchronized (EjbJarProject.class) { 452 brokenAlertLastTime = System.currentTimeMillis(); 453 brokenAlertShown = false; 454 } 455 } 456 } 457 }); 458 } 459 460 461 public String getName() { 462 return (String ) ProjectManager.mutex().readAccess(new Mutex.Action() { 463 public Object run() { 464 Element data = updateHelper.getPrimaryConfigurationData(true); 465 NodeList nl = data.getElementsByTagNameNS(EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE, "name"); 467 if (nl.getLength() == 1) { 468 nl = nl.item(0).getChildNodes(); 469 if (nl.getLength() == 1 && nl.item(0).getNodeType() == Node.TEXT_NODE) { 470 return ((Text ) nl.item(0)).getNodeValue(); 471 } 472 } 473 return "EJB???"; } 475 }); 476 } 477 478 479 public void setName(final String name) { 480 ProjectManager.mutex().writeAccess(new Mutex.Action() { 481 public Object run() { 482 Element data = helper.getPrimaryConfigurationData(true); 483 NodeList nl = data.getElementsByTagNameNS(EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE, "name"); 485 Element nameEl; 486 if (nl.getLength() == 1) { 487 nameEl = (Element ) nl.item(0); 488 NodeList deadKids = nameEl.getChildNodes(); 489 while (deadKids.getLength() > 0) { 490 nameEl.removeChild(deadKids.item(0)); 491 } 492 } else { 493 nameEl = data.getOwnerDocument().createElementNS(EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE, "name"); 494 data.insertBefore(nameEl, data.getChildNodes().item(0)); 495 } 496 nameEl.appendChild(data.getOwnerDocument().createTextNode(name)); 497 helper.putPrimaryConfigurationData(data, true); 498 return null; 499 } 500 }); 501 } 502 503 private void updateProjectXML () throws IOException { 504 Element element = aux.getConfigurationFragment("data","http://www.netbeans.org/ns/EjbJar-project/1",true); if (element != null) { 506 Document doc = element.getOwnerDocument(); 507 Element newRoot = doc.createElementNS (EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE,"data"); copyDocument (doc, element, newRoot); 509 Element sourceRoots = doc.createElementNS(EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE,"source-roots"); Element root = doc.createElementNS (EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE,"root"); root.setAttribute ("id","src.dir"); sourceRoots.appendChild(root); 513 newRoot.appendChild (sourceRoots); 514 Element testRoots = doc.createElementNS(EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE,"test-roots"); root = doc.createElementNS (EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE,"root"); root.setAttribute ("id","test.src.dir"); testRoots.appendChild (root); 518 newRoot.appendChild (testRoots); 519 helper.putPrimaryConfigurationData (newRoot, true); 520 ProjectManager.getDefault().saveProject(this); 521 } 522 } 523 524 private static void copyDocument (Document doc, Element from, Element to) { 525 NodeList nl = from.getChildNodes(); 526 int length = nl.getLength(); 527 for (int i=0; i< length; i++) { 528 Node node = nl.item (i); 529 Node newNode = null; 530 switch (node.getNodeType()) { 531 case Node.ELEMENT_NODE: 532 Element oldElement = (Element ) node; 533 newNode = doc.createElementNS(EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE,oldElement.getTagName()); 534 copyDocument(doc,oldElement,(Element )newNode); 535 break; 536 case Node.TEXT_NODE: 537 Text oldText = (Text ) node; 538 newNode = doc.createTextNode(oldText.getData()); 539 break; 540 case Node.COMMENT_NODE: 541 Comment oldComment = (Comment ) node; 542 newNode = doc.createComment(oldComment.getData()); 543 break; 544 } 545 if (newNode != null) { 546 to.appendChild (newNode); 547 } 548 } 549 } 550 551 public void fileAttributeChanged (org.openide.filesystems.FileAttributeEvent fe) { 552 } 553 554 public void fileChanged (org.openide.filesystems.FileEvent fe) { 555 } 556 557 public void fileDataCreated (org.openide.filesystems.FileEvent fe) { 558 FileObject fo = fe.getFile (); 559 checkLibraryFolder (fo); 560 } 561 562 public void fileDeleted (org.openide.filesystems.FileEvent fe) { 563 } 564 565 public void registerJ2eePlatformListener(final J2eePlatform platform) { 566 j2eePlatformListener = new PropertyChangeListener () { 568 public void propertyChange(PropertyChangeEvent evt) { 569 if (evt.getPropertyName().equals(J2eePlatform.PROP_CLASSPATH)) { 570 ProjectManager.mutex().writeAccess(new Mutex.Action() { 571 public Object run() { 572 EditableProperties ep = helper.getProperties(AntProjectHelper.PRIVATE_PROPERTIES_PATH); 573 String classpath = Utils.toClasspathString(platform.getClasspathEntries()); 574 ep.setProperty(EjbJarProjectProperties.J2EE_PLATFORM_CLASSPATH, classpath); 575 helper.putProperties(AntProjectHelper.PRIVATE_PROPERTIES_PATH, ep); 576 try { 577 ProjectManager.getDefault().saveProject(EjbJarProject.this); 578 } catch (IOException e) { 579 ErrorManager.getDefault().notify(e); 580 } 581 return null; 582 } 583 }); 584 } 585 } 586 }; 587 platform.addPropertyChangeListener(j2eePlatformListener); 588 } 589 590 public void unregisterJ2eePlatformListener(J2eePlatform platform) { 591 if (j2eePlatformListener != null) { 592 platform.removePropertyChangeListener(j2eePlatformListener); 593 } 594 } 595 596 public void fileFolderCreated (org.openide.filesystems.FileEvent fe) { 597 } 598 599 public void fileRenamed (org.openide.filesystems.FileRenameEvent fe) { 600 FileObject fo = fe.getFile (); 601 checkLibraryFolder (fo); 602 } 603 604 private void checkLibraryFolder (FileObject fo) { 605 if (!FileUtil.isArchiveFile(fo)) 606 return; 607 608 if (fo.getParent ().equals (libFolder)) { 609 try { 610 classpathExtender.addArchiveFile(fo); 611 } 612 catch (IOException e) { 613 ErrorManager.getDefault().notify(e); 614 } 615 } 616 } 617 618 private String getProperty(String path, String name) { 619 return helper.getProperties(path).getProperty(name); 620 } 621 622 633 private void refreshBuildImplXml(int askUserIfFlags, boolean askInCurrentThread, boolean checkForProjectXmlModified) { 634 askUserIfFlags |= GeneratedFilesHelper.FLAG_MODIFIED; 635 int flags = genFilesHelper.getBuildScriptState( 636 GeneratedFilesHelper.BUILD_IMPL_XML_PATH, 637 EjbJarProject.class.getResource("resources/build-impl.xsl"), jaxWsFo); 639 if ((flags & askUserIfFlags) == askUserIfFlags) { 640 Runnable run = new Runnable () { 641 public void run () { 642 JButton updateOption = new JButton (NbBundle.getMessage(EjbJarProject.class, "CTL_Regenerate")); 643 if (DialogDisplayer.getDefault().notify( 644 new NotifyDescriptor (NbBundle.getMessage(EjbJarProject.class,"TXT_BuildImplRegenerate"), 645 NbBundle.getMessage(EjbJarProject.class,"TXT_BuildImplRegenerateTitle"), 646 NotifyDescriptor.DEFAULT_OPTION, 647 NotifyDescriptor.WARNING_MESSAGE, 648 new Object [] { 649 updateOption, 650 NotifyDescriptor.CANCEL_OPTION 651 }, 652 updateOption)) == updateOption) { 653 try { 654 genFilesHelper.generateBuildScriptFromStylesheet( 655 GeneratedFilesHelper.BUILD_IMPL_XML_PATH, 656 EjbJarProject.class.getResource("resources/build-impl.xsl"),jaxWsFo); } catch (IOException e) { 658 ErrorManager.getDefault().notify(e); 659 } catch (IllegalStateException e) { 660 ErrorManager.getDefault().notify(e); 661 } 662 } 663 } 664 }; 665 if (askInCurrentThread) 666 run.run(); 667 else 668 RequestProcessor.getDefault().post(run); 669 } else { 670 try { 671 genFilesHelper.refreshBuildScript( 672 GeneratedFilesHelper.BUILD_IMPL_XML_PATH, 673 EjbJarProject.class.getResource("resources/build-impl.xsl"), jaxWsFo, 675 checkForProjectXmlModified); 676 } catch (IOException e) { 677 ErrorManager.getDefault().notify(e); 678 } 679 } 680 } 681 682 684 private final class Info implements ProjectInformation { 685 686 private final PropertyChangeSupport pcs = new PropertyChangeSupport (this); 687 688 Info() {} 689 690 void firePropertyChange(String prop) { 691 pcs.firePropertyChange(prop, null, null); 692 } 693 694 public String getName() { 695 return EjbJarProject.this.getName(); 696 } 697 698 public String getDisplayName() { 699 return EjbJarProject.this.getName(); 700 } 701 702 public Icon getIcon() { 703 return PROJECT_ICON; 704 } 705 706 public Project getProject() { 707 return EjbJarProject.this; 708 } 709 710 public void addPropertyChangeListener(PropertyChangeListener listener) { 711 pcs.addPropertyChangeListener(listener); 712 } 713 714 public void removePropertyChangeListener(PropertyChangeListener listener) { 715 pcs.removePropertyChangeListener(listener); 716 } 717 718 } 719 720 private final class ProjectXmlSavedHookImpl extends ProjectXmlSavedHook { 721 722 ProjectXmlSavedHookImpl() {} 723 724 protected void projectXmlSaved() throws IOException { 725 refreshBuildImplXml(0, false, false); 726 727 genFilesHelper.refreshBuildScript( 728 getBuildXmlName(), 729 EjbJarProject.class.getResource("resources/build.xsl"), 730 jaxWsFo, 731 false); 732 } 733 734 } 735 736 private final class ProjectOpenedHookImpl extends ProjectOpenedHook { 737 738 ProjectOpenedHookImpl() {} 739 740 protected void projectOpened() { 741 try { 742 String libFolderName = helper.getStandardPropertyEvaluator ().getProperty (EjbJarProjectProperties.LIBRARIES_DIR); 744 746 try { 748 FileObject ddFO = ejbModule.getDeploymentDescriptor(); 749 if (ddFO != null) { 750 DataObject.find(ddFO); 751 } 752 } catch (org.openide.loaders.DataObjectNotFoundException ex) {} 753 754 if (libFolderName != null && helper.resolveFile (libFolderName).isDirectory ()) { 755 libFolder = helper.resolveFileObject(libFolderName); 756 FileObject children [] = libFolder.getChildren (); 757 List libs = new LinkedList(); 758 for (int i = 0; i < children.length; i++) { 759 if (FileUtil.isArchiveFile(children[i])) 760 libs.add(children[i]); 761 } 762 FileObject[] libsArray = new FileObject[libs.size()]; 763 libs.toArray(libsArray); 764 classpathExtender.addArchiveFiles(EjbJarProjectProperties.JAVAC_CLASSPATH, libsArray, ClassPathSupport.ELEMENT_INCLUDED_LIBRARIES); 765 libFolder.addFileChangeListener (EjbJarProject.this); 766 } 767 768 770 refreshBuildImplXml( GeneratedFilesHelper.FLAG_OLD_PROJECT_XML, true, true); 771 772 genFilesHelper.refreshBuildScript( 773 getBuildXmlName(), 774 EjbJarProject.class.getResource("resources/build.xsl"), 775 jaxWsFo, 776 true); 777 778 String servInstID = getProperty(AntProjectHelper.PRIVATE_PROPERTIES_PATH, EjbJarProjectProperties.J2EE_SERVER_INSTANCE); 779 J2eePlatform platform = Deployment.getDefault().getJ2eePlatform(servInstID); 780 if (platform != null) { 781 EjbJarProjectProperties.setServerInstance(EjbJarProject.this, EjbJarProject.this.helper, servInstID); 783 } else { 784 String serverType = getProperty(AntProjectHelper.PROJECT_PROPERTIES_PATH, EjbJarProjectProperties.J2EE_SERVER_TYPE); 787 if (serverType != null) { 788 String [] servInstIDs = Deployment.getDefault().getInstancesOfServer(serverType); 789 if (servInstIDs.length > 0) { 790 EjbJarProjectProperties.setServerInstance(EjbJarProject.this, EjbJarProject.this.helper, servInstIDs[0]); 791 platform = Deployment.getDefault().getJ2eePlatform(servInstIDs[0]); 792 } 793 } 794 if (platform == null) { 795 BrokenServerSupport.showAlert(); 796 } 797 } 798 } catch (IOException e) { 799 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e); 800 } 801 802 ClassPathProviderImpl cpProvider = (ClassPathProviderImpl)lookup.lookup(ClassPathProviderImpl.class); 804 GlobalPathRegistry.getDefault().register(ClassPath.BOOT, cpProvider.getProjectClassPaths(ClassPath.BOOT)); 805 GlobalPathRegistry.getDefault().register(ClassPath.SOURCE, cpProvider.getProjectClassPaths(ClassPath.SOURCE)); 806 GlobalPathRegistry.getDefault().register(ClassPath.COMPILE, cpProvider.getProjectClassPaths(ClassPath.COMPILE)); 807 808 ejbModule.getConfigSupport().ensureConfigurationReady(); 812 813 ProjectManager.mutex().writeAccess(new Mutex.Action() { 815 public Object run() { 816 EditableProperties ep = helper.getProperties(AntProjectHelper.PRIVATE_PROPERTIES_PATH); 817 ep.setProperty("netbeans.user", System.getProperty("netbeans.user")); 818 819 WSUtils.setJaxWsEndorsedDirProperty(ep); 821 822 helper.putProperties(AntProjectHelper.PRIVATE_PROPERTIES_PATH, ep); 823 try { 824 ProjectManager.getDefault().saveProject(EjbJarProject.this); 825 } catch (IOException e) { 826 ErrorManager.getDefault().notify(e); 827 } 828 return null; 829 } 830 }); 831 EjbJarLogicalViewProvider physicalViewProvider = (EjbJarLogicalViewProvider) 832 EjbJarProject.this.getLookup().lookup (EjbJarLogicalViewProvider.class); 833 if (physicalViewProvider != null && physicalViewProvider.hasBrokenLinks()) { 834 BrokenReferencesSupport.showAlert(); 835 } 836 } 837 838 protected void projectClosed() { 839 840 843 String servInstID = getProperty(AntProjectHelper.PRIVATE_PROPERTIES_PATH, EjbJarProjectProperties.J2EE_SERVER_INSTANCE); 844 J2eePlatform platform = Deployment.getDefault().getJ2eePlatform(servInstID); 845 if (platform != null) { 846 unregisterJ2eePlatformListener(platform); 847 } 848 849 if (evalListener != null) { 851 evaluator().removePropertyChangeListener(evalListener); 852 } 853 854 if (jaxWsFo!=null) jaxWsFo.removeFileChangeListener(jaxWsListener); 856 857 if (jaxWsModel!=null) jaxWsModel.removeServiceListener(jaxWsServiceListener); 859 860 try { 862 ProjectManager.getDefault().saveProject(EjbJarProject.this); 863 } catch (IOException e) { 864 ErrorManager.getDefault().notify(e); 865 } 866 867 ClassPathProviderImpl cpProvider = (ClassPathProviderImpl)lookup.lookup(ClassPathProviderImpl.class); 869 GlobalPathRegistry.getDefault().unregister(ClassPath.BOOT, cpProvider.getProjectClassPaths(ClassPath.BOOT)); 870 GlobalPathRegistry.getDefault().unregister(ClassPath.SOURCE, cpProvider.getProjectClassPaths(ClassPath.SOURCE)); 871 GlobalPathRegistry.getDefault().unregister(ClassPath.COMPILE, cpProvider.getProjectClassPaths(ClassPath.COMPILE)); 872 } 873 874 } 875 876 public void propertyChange(PropertyChangeEvent evt) { 877 if (evt.getPropertyName().equals(EjbJarProjectProperties.JAVAC_CLASSPATH)) { 878 ProjectManager.mutex().postWriteRequest(new Runnable () { 879 public void run() { 880 EditableProperties props = helper.getProperties (AntProjectHelper.PROJECT_PROPERTIES_PATH); EditableProperties privateProps = helper.getProperties(AntProjectHelper.PRIVATE_PROPERTIES_PATH); 883 Iterator cpItems = classpathExtender.getClassPathSupport().itemsIterator(props.getProperty(EjbJarProjectProperties.JAVAC_CLASSPATH), ClassPathSupport.ELEMENT_INCLUDED_LIBRARIES); 884 EjbJarProjectProperties.storeLibrariesLocations(cpItems, privateProps); 885 helper.putProperties(AntProjectHelper.PRIVATE_PROPERTIES_PATH, privateProps); 886 } 887 }); 888 } 889 } 890 891 895 private final class AntArtifactProviderImpl implements AntArtifactProvider { 896 897 public AntArtifact[] getBuildArtifacts() { 898 return new AntArtifact[] { 899 helper.createSimpleAntArtifact(JavaProjectConstants.ARTIFACT_TYPE_JAR, "dist.jar", helper.getStandardPropertyEvaluator(), "dist", "clean"), helper.createSimpleAntArtifact(EjbProjectConstants.ARTIFACT_TYPE_EJBJAR, "dist.jar", helper.getStandardPropertyEvaluator(), "dist", "clean"), helper.createSimpleAntArtifact(EjbProjectConstants.ARTIFACT_TYPE_J2EE_MODULE_IN_EAR_ARCHIVE, "dist.ear.jar", helper.getStandardPropertyEvaluator(), "dist-ear", "clean-ear") }; 903 } 904 } 905 906 private static final String [] TYPES = new String [] { 908 "java-classes", "ejb-types_2_1", "ejb-types", "ejb-types-server", "web-services", "wsdl", "j2ee-14-types", "j2ee-types", "java-beans", "java-main-class", "persistence", "oasis-XML-catalogs", "XML", "ant-script", "ant-task", "junit", "simple-files" }; 926 927 930 private static final String [] JAVAEE5_TYPES = new String [] { 931 "java-classes", "ejb-types", "ejb-types-server", "ejb-types_3_0", "web-services", "web-service-clients", "wsdl", "j2ee-types", "java-beans", "java-main-class", "persistence", "oasis-XML-catalogs", "XML", "ant-script", "ant-task", "junit", "simple-files" }; 949 950 953 private static final String [] ARCHIVE_TYPES = new String [] { 954 "ejb-deployment-descriptor", "deployment-descriptor", "XML", }; 958 959 private static final String [] PRIVILEGED_NAMES = new String [] { 960 "Templates/J2EE/Session", "Templates/J2EE/Entity", "Templates/J2EE/RelatedCMP", "Templates/J2EE/Message", "Templates/Classes/Class.java", "Templates/Classes/Package", "Templates/WebServices/WebService.java", "Templates/WebServices/MessageHandler" }; 969 970 private static final String [] PRIVILEGED_NAMES_EE5 = new String [] { 971 "Templates/J2EE/Session", "Templates/J2EE/Message", "Templates/Classes/Class.java", "Templates/Classes/Package", "Templates/Persistence/Entity.java", "Templates/Persistence/RelatedCMP", "Templates/WebServices/WebService.java", "Templates/WebServices/WebServiceClient" }; 980 981 private static final String [] PRIVILEGED_NAMES_ARCHIVE = new String [] { 982 "Templates/J2EE/ejbJarXml", }; 984 985 private final class RecommendedTemplatesImpl implements RecommendedTemplates, PrivilegedTemplates { 986 transient private boolean isEE5 = false; 987 transient private boolean checked = false; 988 transient private boolean isArchive = false; 989 transient private UpdateHelper helper = null; 990 991 RecommendedTemplatesImpl(UpdateHelper helper) { 992 this.helper = helper; 993 } 994 995 public String [] getRecommendedTypes() { 996 checkEnvironment(); 997 String [] retVal = null; 998 if (isArchive) { 999 retVal = ARCHIVE_TYPES; 1000 } else if (isEE5) { 1001 retVal = JAVAEE5_TYPES; 1002 } else { 1003 retVal = TYPES; 1004 } 1005 return retVal; 1006 } 1007 1008 public String [] getPrivilegedTemplates() { 1009 checkEnvironment(); 1010 String [] retVal = null; 1011 if (isArchive) { 1012 retVal = PRIVILEGED_NAMES_ARCHIVE; 1013 } else if (isEE5) { 1014 retVal = PRIVILEGED_NAMES_EE5; 1015 } else { 1016 retVal = PRIVILEGED_NAMES; 1017 } 1018 return retVal; 1019 } 1020 1021 private void checkEnvironment(){ 1022 if (!checked){ 1023 isEE5 = J2eeModule.JAVA_EE_5.equals(getEjbModule().getJ2eePlatformVersion()); 1024 final Object srcType = helper.getAntProjectHelper(). 1025 getStandardPropertyEvaluator().getProperty(EjbJarProjectProperties.JAVA_SOURCE_BASED); 1026 if ("false".equals(srcType)) { 1027 isArchive = true; 1028 } 1029 checked = true; 1030 } 1031 } 1032 } 1033 1034 1038 public void createJaxWsFileObject() throws IOException { 1039 FileObject projectDir = helper.getProjectDirectory(); 1040 WSUtils.retrieveJaxWsFromResource(projectDir); 1041 1042 jaxWsFo = findJaxWsFileObject(projectDir); 1043 if (jaxWsFo!=null) { 1044 jaxWsListener = new JaxWsListener(); 1045 jaxWsFo.addFileChangeListener(jaxWsListener); 1046 1047 if (jaxWsModel!=null) { 1048 jaxWsModel.setJaxWsFile(jaxWsFo); 1049 } else { 1050 jaxWsModel = JaxWsModelProvider.getDefault().getJaxWsModel(jaxWsFo); 1051 if (jaxWsModel!=null) { 1052 attachServiceListener(jaxWsModel); 1053 } 1054 } 1055 } 1056 } 1057 1058 public FileObject findJaxWsFileObject() { 1059 return findJaxWsFileObject(helper.getProjectDirectory()); 1060 } 1061 1062 private FileObject findJaxWsFileObject(FileObject projectDir) { 1063 return projectDir.getFileObject(GeneratedFilesHelper.JAX_WS_XML_PATH); 1064 } 1065 1066 private JaxWsModel getJaxWsModel() { 1067 if (jaxWsModel==null) 1068 try { 1069 final FileObject projectDir = helper.getProjectDirectory(); 1070 jaxWsFo = findJaxWsFileObject(projectDir); 1071 if (jaxWsFo==null) { 1072 jaxWsModel = JaxWsModelProvider.getDefault().getJaxWsModel( 1074 WSUtils.class.getResourceAsStream("/org/netbeans/modules/websvc/jaxwsmodel/resources/jax-ws.xml")); jaxWsModel.setJaxWsFile(projectDir); 1076 } else { 1077 jaxWsListener = new JaxWsListener(); 1078 try { 1079 jaxWsModel = JaxWsModelProvider.getDefault().getJaxWsModel(jaxWsFo); 1080 jaxWsFo.addFileChangeListener(jaxWsListener); 1081 } catch (RuntimeException ex) { 1082 jaxWsModel = JaxWsModelProvider.getDefault().getJaxWsModel( 1084 WSUtils.class.getResourceAsStream("/org/netbeans/modules/websvc/jaxwsmodel/resources/jax-ws.xml")); jaxWsModel.setJaxWsFile(projectDir); 1086 final FileObject oldJaxWsFo = jaxWsFo; 1087 jaxWsFo=null; 1088 final RuntimeException exception = ex; 1089 RequestProcessor.getDefault().post(new Runnable () { 1090 public void run() { 1091 try { 1092 jaxWsFo = WSUtils.backupAndGenerateJaxWs(projectDir, oldJaxWsFo, exception); 1093 if (jaxWsFo!=null) { 1094 jaxWsModel.setJaxWsFile(jaxWsFo); 1095 jaxWsFo.addFileChangeListener(jaxWsListener); 1096 } 1097 } catch (IOException ex) { 1098 ErrorManager.getDefault().log(ex.getLocalizedMessage()); 1099 } 1100 } 1101 }); 1102 } 1103 } 1104 if (jaxWsModel!=null) { 1105 attachServiceListener(jaxWsModel); 1106 } 1107 } catch (IOException ex) { 1108 ErrorManager.getDefault().log(ex.getLocalizedMessage()); 1109 } 1110 return jaxWsModel; 1111 } 1112 1113 private void attachServiceListener(JaxWsModel jaxWsModel) { 1114 jaxWsServiceListener = new JaxWsModel.ServiceListener() { 1115 public void serviceAdded(String name, String implementationClass) { 1116 getAPIJAXWSSupport().addService(name, implementationClass, isJsr109Supported()); 1117 } 1118 1119 public void serviceRemoved(String name) { 1120 getAPIJAXWSSupport().serviceFromJavaRemoved(name); 1121 } 1122 }; 1123 jaxWsModel.addServiceListener(jaxWsServiceListener); 1124 } 1125 1126 private boolean isJsr109Supported() { 1127 boolean jsr109Supported = true; 1128 String serverInstance = evaluator().getProperty(EjbJarProjectProperties.J2EE_SERVER_INSTANCE); 1129 if (serverInstance != null) { 1130 J2eePlatform j2eePlatform = Deployment.getDefault().getJ2eePlatform(serverInstance); 1131 if (j2eePlatform != null) { 1132 jsr109Supported = j2eePlatform.isToolSupported(J2eePlatform.TOOL_JSR109); 1133 } 1134 } 1135 return jsr109Supported; 1136 } 1137 1138 private class JaxWsListener extends FileChangeAdapter { 1139 public void fileChanged(FileEvent fe) { 1140 try { 1141 final JaxWsModel newModel = JaxWsModelProvider.getDefault().getJaxWsModel(fe.getFile()); 1142 RequestProcessor.getDefault().post(new Runnable () { 1143 public void run() { 1144 if (jaxWsModel!=null && newModel!=null) jaxWsModel.merge(newModel); 1145 try { 1146 genFilesHelper.refreshBuildScript( 1147 GeneratedFilesHelper.BUILD_IMPL_XML_PATH, 1148 EjbJarProject.class.getResource("resources/build-impl.xsl"), 1149 jaxWsFo, false); 1150 } catch (IOException ex) {} 1151 } 1152 1153 }); 1154 1155 } catch (IOException ex) {} 1156 } 1157 } 1158} 1159 | Popular Tags |