1 19 20 package org.netbeans.modules.java.j2seproject; 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.util.Collections ; 28 import java.util.logging.Level ; 29 import java.util.logging.Logger ; 30 import javax.swing.Icon ; 31 import javax.swing.ImageIcon ; 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.Project; 36 import org.netbeans.api.project.ProjectInformation; 37 import org.netbeans.api.project.ProjectManager; 38 import org.netbeans.api.project.ant.AntArtifact; 39 import org.netbeans.modules.java.j2seproject.api.J2SEPropertyEvaluator; 40 import org.netbeans.modules.java.j2seproject.classpath.ClassPathProviderImpl; 41 import org.netbeans.modules.java.j2seproject.classpath.J2SEProjectClassPathExtender; 42 import org.netbeans.modules.java.j2seproject.classpath.J2SEProjectClassPathModifier; 43 import org.netbeans.modules.java.j2seproject.queries.CompiledSourceForBinaryQuery; 44 import org.netbeans.modules.java.j2seproject.queries.JavadocForBinaryQueryImpl; 45 import org.netbeans.modules.java.j2seproject.queries.SourceLevelQueryImpl; 46 import org.netbeans.modules.java.j2seproject.queries.UnitTestForSourceQueryImpl; 47 import org.netbeans.modules.java.j2seproject.ui.J2SELogicalViewProvider; 48 import org.netbeans.modules.java.j2seproject.ui.customizer.CustomizerProviderImpl; 49 import org.netbeans.modules.java.j2seproject.ui.customizer.J2SEProjectProperties; 50 import org.netbeans.modules.java.j2seproject.wsclient.J2SEProjectWebServicesClientSupport; 51 import org.netbeans.modules.java.j2seproject.jaxws.J2SEProjectJAXWSClientSupport; 52 import org.netbeans.modules.java.j2seproject.queries.BinaryForSourceQueryImpl; 53 import org.netbeans.modules.java.j2seproject.wsclient.J2SEProjectWebServicesSupportProvider; 54 import org.netbeans.modules.websvc.api.client.WebServicesClientSupport; 55 import org.netbeans.modules.websvc.api.jaxws.client.JAXWSClientSupport; 56 import org.netbeans.modules.websvc.api.jaxws.project.GeneratedFilesHelper; 57 import org.netbeans.modules.websvc.api.jaxws.project.WSUtils; 58 import org.netbeans.modules.websvc.api.jaxws.project.config.JaxWsModel; 59 import org.netbeans.modules.websvc.api.jaxws.project.config.JaxWsModelProvider; 60 import org.netbeans.modules.websvc.spi.client.WebServicesClientSupportFactory; 61 import org.netbeans.modules.websvc.spi.jaxws.client.JAXWSClientSupportFactory; 62 import org.netbeans.spi.java.project.support.ui.BrokenReferencesSupport; 63 import org.netbeans.spi.project.AuxiliaryConfiguration; 64 import org.netbeans.spi.project.SubprojectProvider; 65 import org.netbeans.spi.project.ant.AntArtifactProvider; 66 import org.netbeans.spi.project.support.LookupProviderSupport; 67 import org.netbeans.spi.project.support.ant.AntProjectEvent; 68 import org.netbeans.spi.project.support.ant.AntProjectHelper; 69 import org.netbeans.spi.project.support.ant.AntProjectListener; 70 import org.netbeans.spi.project.support.ant.EditableProperties; 71 import org.netbeans.spi.project.support.ant.FilterPropertyProvider; 72 import org.netbeans.spi.project.support.ant.ProjectXmlSavedHook; 73 import org.netbeans.spi.project.support.ant.PropertyEvaluator; 74 import org.netbeans.spi.project.support.ant.PropertyProvider; 75 import org.netbeans.spi.project.support.ant.PropertyUtils; 76 import org.netbeans.spi.project.support.ant.ReferenceHelper; 77 import org.netbeans.spi.project.ui.PrivilegedTemplates; 78 import org.netbeans.spi.project.ui.ProjectOpenedHook; 79 import org.netbeans.spi.project.ui.RecommendedTemplates; 80 import org.netbeans.spi.project.ui.support.UILookupMergerSupport; 81 import org.openide.DialogDisplayer; 82 import org.openide.ErrorManager; 83 import org.openide.NotifyDescriptor; 84 import org.openide.filesystems.FileChangeAdapter; 85 import org.openide.filesystems.FileEvent; 86 import org.openide.filesystems.FileObject; 87 import org.openide.filesystems.FileUtil; 88 import org.openide.util.Lookup; 89 import org.openide.util.Mutex; 90 import org.openide.util.NbBundle; 91 import org.openide.util.RequestProcessor; 92 import org.openide.util.Utilities; 93 import org.openide.util.lookup.Lookups; 94 import org.w3c.dom.Element ; 95 import org.w3c.dom.Text ; 96 import org.w3c.dom.Node ; 97 import org.w3c.dom.NodeList ; 98 99 103 public final class J2SEProject implements Project, AntProjectListener { 104 105 private static final Icon J2SE_PROJECT_ICON = new ImageIcon (Utilities.loadImage("org/netbeans/modules/java/j2seproject/ui/resources/j2seProject.gif")); 107 private final AuxiliaryConfiguration aux; 108 private final AntProjectHelper helper; 109 private final PropertyEvaluator eval; 110 private final ReferenceHelper refHelper; 111 private final GeneratedFilesHelper genFilesHelper; 112 private final Lookup lookup; 113 private final UpdateHelper updateHelper; 114 private MainClassUpdater mainClassUpdater; 115 private SourceRoots sourceRoots; 116 private SourceRoots testRoots; 117 118 private J2SEProjectWebServicesClientSupport j2seProjectWebServicesClientSupport; 120 private J2SEProjectJAXWSClientSupport j2seJAXWSClientSupport; 121 private WebServicesClientSupport apiWebServicesClientSupport; 122 private JAXWSClientSupport apiJaxwsClientSupport; 123 private JaxWsModel jaxWsModel; 124 private JaxWsListener jaxWsListener; 125 private FileObject jaxWsFo; 126 127 J2SEProject(AntProjectHelper helper) throws IOException { 128 this.helper = helper; 129 eval = createEvaluator(); 130 aux = helper.createAuxiliaryConfiguration(); 131 refHelper = new ReferenceHelper(helper, aux, eval); 132 genFilesHelper = new GeneratedFilesHelper(helper); 133 this.updateHelper = new UpdateHelper (this, this.helper, this.aux, this.genFilesHelper, 134 UpdateHelper.createDefaultNotifier()); 135 j2seProjectWebServicesClientSupport = new J2SEProjectWebServicesClientSupport(this, helper, refHelper); 136 apiWebServicesClientSupport = WebServicesClientSupportFactory.createWebServicesClientSupport (j2seProjectWebServicesClientSupport); 137 j2seJAXWSClientSupport = new J2SEProjectJAXWSClientSupport(this, updateHelper); 138 apiJaxwsClientSupport = JAXWSClientSupportFactory.createJAXWSClientSupport(j2seJAXWSClientSupport); 139 140 lookup = createLookup(aux); 141 helper.addAntProjectListener(this); 142 } 143 144 148 public FileObject getProjectDirectory() { 149 return helper.getProjectDirectory(); 150 } 151 152 public String toString() { 153 return "J2SEProject[" + FileUtil.getFileDisplayName(getProjectDirectory()) + "]"; } 155 156 private PropertyEvaluator createEvaluator() { 157 PropertyEvaluator baseEval1 = PropertyUtils.sequentialPropertyEvaluator( 160 helper.getStockPropertyPreprovider(), 161 helper.getPropertyProvider(J2SEConfigurationProvider.CONFIG_PROPS_PATH)); 162 PropertyEvaluator baseEval2 = PropertyUtils.sequentialPropertyEvaluator( 163 helper.getStockPropertyPreprovider(), 164 helper.getPropertyProvider(AntProjectHelper.PRIVATE_PROPERTIES_PATH)); 165 return PropertyUtils.sequentialPropertyEvaluator( 166 helper.getStockPropertyPreprovider(), 167 helper.getPropertyProvider(J2SEConfigurationProvider.CONFIG_PROPS_PATH), 168 new ConfigPropertyProvider(baseEval1, "nbproject/private/configs", helper), helper.getPropertyProvider(AntProjectHelper.PRIVATE_PROPERTIES_PATH), 170 PropertyUtils.userPropertiesProvider(baseEval2, 171 "user.properties.file", FileUtil.toFile(getProjectDirectory())), new ConfigPropertyProvider(baseEval1, "nbproject/configs", helper), helper.getPropertyProvider(AntProjectHelper.PROJECT_PROPERTIES_PATH)); 174 } 175 private static final class ConfigPropertyProvider extends FilterPropertyProvider implements PropertyChangeListener { 176 private final PropertyEvaluator baseEval; 177 private final String prefix; 178 private final AntProjectHelper helper; 179 public ConfigPropertyProvider(PropertyEvaluator baseEval, String prefix, AntProjectHelper helper) { 180 super(computeDelegate(baseEval, prefix, helper)); 181 this.baseEval = baseEval; 182 this.prefix = prefix; 183 this.helper = helper; 184 baseEval.addPropertyChangeListener(this); 185 } 186 public void propertyChange(PropertyChangeEvent ev) { 187 if (J2SEConfigurationProvider.PROP_CONFIG.equals(ev.getPropertyName())) { 188 setDelegate(computeDelegate(baseEval, prefix, helper)); 189 } 190 } 191 private static PropertyProvider computeDelegate(PropertyEvaluator baseEval, String prefix, AntProjectHelper helper) { 192 String config = baseEval.getProperty(J2SEConfigurationProvider.PROP_CONFIG); 193 if (config != null) { 194 return helper.getPropertyProvider(prefix + "/" + config + ".properties"); } else { 196 return PropertyUtils.fixedPropertyProvider(Collections.<String ,String >emptyMap()); 197 } 198 } 199 } 200 201 public PropertyEvaluator evaluator() { 202 return eval; 203 } 204 205 ReferenceHelper getReferenceHelper () { 206 return this.refHelper; 207 } 208 209 public UpdateHelper getUpdateHelper() { 210 return this.updateHelper; 211 } 212 213 public Lookup getLookup() { 214 return lookup; 215 } 216 217 public AntProjectHelper getAntProjectHelper() { 218 return helper; 219 } 220 221 private Lookup createLookup(AuxiliaryConfiguration aux) { 222 SubprojectProvider spp = refHelper.createSubprojectProvider(); 223 final J2SEProjectClassPathModifier cpMod = new J2SEProjectClassPathModifier(this, this.updateHelper, eval, refHelper); 224 final JaxWsModel jaxWsModel = getJaxWsModel(); 225 assert jaxWsModel != null; 226 Lookup base = Lookups.fixed(new Object [] { 227 new Info(), 228 aux, 229 helper.createCacheDirectoryProvider(), 230 spp, 231 new J2SEActionProvider( this, this.updateHelper ), 232 new J2SELogicalViewProvider(this, this.updateHelper, evaluator(), spp, refHelper), 233 new CustomizerProviderImpl(this, this.updateHelper, evaluator(), refHelper, this.genFilesHelper), 235 new ClassPathProviderImpl(this.helper, evaluator(), getSourceRoots(),getTestSourceRoots()), new CompiledSourceForBinaryQuery(this.helper, evaluator(),getSourceRoots(),getTestSourceRoots()), new JavadocForBinaryQueryImpl(this.helper, evaluator()), new AntArtifactProviderImpl(), 239 new ProjectXmlSavedHookImpl(), 240 new ProjectOpenedHookImpl(), 241 new UnitTestForSourceQueryImpl(getSourceRoots(),getTestSourceRoots()), 242 new SourceLevelQueryImpl(evaluator()), 243 new J2SESources (this.helper, evaluator(), getSourceRoots(), getTestSourceRoots()), 244 new J2SESharabilityQuery (this.helper, evaluator(), getSourceRoots(), getTestSourceRoots()), new J2SEFileBuiltQuery (this.helper, evaluator(),getSourceRoots(),getTestSourceRoots()), new RecommendedTemplatesImpl (this.updateHelper), 247 new J2SEProjectClassPathExtender(cpMod), 248 cpMod, 249 this, new J2SEProjectOperations(this), 251 new J2SEConfigurationProvider(this), 252 new J2SEProjectWebServicesSupportProvider(), 253 new J2SEPersistenceProvider(this), 254 jaxWsModel, 255 UILookupMergerSupport.createPrivilegedTemplatesMerger(), 256 UILookupMergerSupport.createRecommendedTemplatesMerger(), 257 LookupProviderSupport.createSourcesMerger(), 258 new J2SEPropertyEvaluatorImpl(evaluator()), 259 new BinaryForSourceQueryImpl(this.sourceRoots, this.testRoots, this.helper, this.eval) }); 261 return LookupProviderSupport.createCompositeLookup(base, "Projects/org-netbeans-modules-java-j2seproject/Lookup"); } 263 264 public void configurationXmlChanged(AntProjectEvent ev) { 265 if (ev.getPath().equals(AntProjectHelper.PROJECT_XML_PATH)) { 266 Info info = (Info)getLookup().lookup(ProjectInformation.class); 268 info.firePropertyChange(ProjectInformation.PROP_NAME); 269 info.firePropertyChange(ProjectInformation.PROP_DISPLAY_NAME); 270 } 271 } 272 273 public void propertiesChanged(AntProjectEvent ev) { 274 } 276 277 279 283 public synchronized SourceRoots getSourceRoots() { 284 if (this.sourceRoots == null) { this.sourceRoots = new SourceRoots(this.updateHelper, evaluator(), getReferenceHelper(), "source-roots", false, "src.{0}{1}.dir"); } 287 return this.sourceRoots; 288 } 289 290 public synchronized SourceRoots getTestSourceRoots() { 291 if (this.testRoots == null) { this.testRoots = new SourceRoots(this.updateHelper, evaluator(), getReferenceHelper(), "test-roots", true, "test.{0}{1}.dir"); } 294 return this.testRoots; 295 } 296 297 File getTestClassesDirectory() { 298 String testClassesDir = evaluator().getProperty(J2SEProjectProperties.BUILD_TEST_CLASSES_DIR); 299 if (testClassesDir == null) { 300 return null; 301 } 302 return helper.resolveFile(testClassesDir); 303 } 304 305 307 public void setName(final String name) { 308 ProjectManager.mutex().writeAccess(new Mutex.Action<Void >() { 309 public Void run() { 310 Element data = helper.getPrimaryConfigurationData(true); 311 NodeList nl = data.getElementsByTagNameNS(J2SEProjectType.PROJECT_CONFIGURATION_NAMESPACE, "name"); 313 Element nameEl; 314 if (nl.getLength() == 1) { 315 nameEl = (Element ) nl.item(0); 316 NodeList deadKids = nameEl.getChildNodes(); 317 while (deadKids.getLength() > 0) { 318 nameEl.removeChild(deadKids.item(0)); 319 } 320 } else { 321 nameEl = data.getOwnerDocument().createElementNS(J2SEProjectType.PROJECT_CONFIGURATION_NAMESPACE, "name"); 322 data.insertBefore(nameEl, data.getChildNodes().item(0)); 323 } 324 nameEl.appendChild(data.getOwnerDocument().createTextNode(name)); 325 helper.putPrimaryConfigurationData(data, true); 326 return null; 327 } 328 }); 329 } 330 331 332 333 334 336 private final class Info implements ProjectInformation { 337 338 private final PropertyChangeSupport pcs = new PropertyChangeSupport (this); 339 340 Info() {} 341 342 void firePropertyChange(String prop) { 343 pcs.firePropertyChange(prop, null, null); 344 } 345 346 public String getName() { 347 return PropertyUtils.getUsablePropertyName(getDisplayName()); 348 } 349 350 public String getDisplayName() { 351 return ProjectManager.mutex().readAccess(new Mutex.Action<String >() { 352 public String run() { 353 Element data = updateHelper.getPrimaryConfigurationData(true); 354 NodeList nl = data.getElementsByTagNameNS(J2SEProjectType.PROJECT_CONFIGURATION_NAMESPACE, "name"); if (nl.getLength() == 1) { 357 nl = nl.item(0).getChildNodes(); 358 if (nl.getLength() == 1 && nl.item(0).getNodeType() == Node.TEXT_NODE) { 359 return ((Text ) nl.item(0)).getNodeValue(); 360 } 361 } 362 return "???"; } 364 }); 365 } 366 367 public Icon getIcon() { 368 return J2SE_PROJECT_ICON; 369 } 370 371 public Project getProject() { 372 return J2SEProject.this; 373 } 374 375 public void addPropertyChangeListener(PropertyChangeListener listener) { 376 pcs.addPropertyChangeListener(listener); 377 } 378 379 public void removePropertyChangeListener(PropertyChangeListener listener) { 380 pcs.removePropertyChangeListener(listener); 381 } 382 383 } 384 385 private final class ProjectXmlSavedHookImpl extends ProjectXmlSavedHook { 386 387 ProjectXmlSavedHookImpl() {} 388 389 protected void projectXmlSaved() throws IOException { 390 if (updateHelper.isCurrent()) { 393 genFilesHelper.refreshBuildScript( 395 GeneratedFilesHelper.BUILD_IMPL_XML_PATH, 396 J2SEProject.class.getResource("resources/build-impl.xsl"), 397 jaxWsFo, 398 false); 399 genFilesHelper.refreshBuildScript( 400 GeneratedFilesHelper.BUILD_XML_PATH, 401 J2SEProject.class.getResource("resources/build.xsl"), 402 jaxWsFo, 403 false); 404 } 405 } 406 407 } 408 409 private final class ProjectOpenedHookImpl extends ProjectOpenedHook { 410 411 ProjectOpenedHookImpl() {} 412 413 protected void projectOpened() { 414 try { 416 if (updateHelper.isCurrent()) { 417 genFilesHelper.refreshBuildScript( 419 GeneratedFilesHelper.BUILD_IMPL_XML_PATH, 420 J2SEProject.class.getResource("resources/build-impl.xsl"), 421 jaxWsFo, 422 true); 423 genFilesHelper.refreshBuildScript( 424 GeneratedFilesHelper.BUILD_XML_PATH, 425 J2SEProject.class.getResource("resources/build.xsl"), 426 jaxWsFo, 427 true); 428 } 429 } catch (IOException e) { 430 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e); 431 } 432 433 ClassPathProviderImpl cpProvider = lookup.lookup(ClassPathProviderImpl.class); 435 GlobalPathRegistry.getDefault().register(ClassPath.BOOT, cpProvider.getProjectClassPaths(ClassPath.BOOT)); 436 GlobalPathRegistry.getDefault().register(ClassPath.SOURCE, cpProvider.getProjectClassPaths(ClassPath.SOURCE)); 437 GlobalPathRegistry.getDefault().register(ClassPath.COMPILE, cpProvider.getProjectClassPaths(ClassPath.COMPILE)); 438 439 mainClassUpdater = new MainClassUpdater (J2SEProject.this, eval, updateHelper, 442 cpProvider.getProjectClassPaths(ClassPath.SOURCE)[0], J2SEProjectProperties.MAIN_CLASS); 443 444 ProjectManager.mutex().writeAccess(new Mutex.Action<Void >() { 446 public Void run() { 447 EditableProperties ep = updateHelper.getProperties(AntProjectHelper.PRIVATE_PROPERTIES_PATH); 448 File buildProperties = new File (System.getProperty("netbeans.user"), "build.properties"); ep.setProperty("user.properties.file", buildProperties.getAbsolutePath()); 451 WSUtils.setJaxWsEndorsedDirProperty(ep); 453 454 updateHelper.putProperties(AntProjectHelper.PRIVATE_PROPERTIES_PATH, ep); 455 ep = helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); 456 if (!ep.containsKey(J2SEProjectProperties.INCLUDES)) { 457 ep.setProperty(J2SEProjectProperties.INCLUDES, "**"); } 459 if (!ep.containsKey(J2SEProjectProperties.EXCLUDES)) { 460 ep.setProperty(J2SEProjectProperties.EXCLUDES, ""); } 462 helper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, ep); 463 try { 464 ProjectManager.getDefault().saveProject(J2SEProject.this); 465 } catch (IOException e) { 466 if (!J2SEProject.this.getProjectDirectory().canWrite()) { 468 NotifyDescriptor nd = new NotifyDescriptor.Message(NbBundle.getMessage(J2SEProject.class, "ERR_ProjectReadOnly", 469 J2SEProject.this.getProjectDirectory().getName())); 470 DialogDisplayer.getDefault().notify(nd); 471 } else { 472 ErrorManager.getDefault().notify(e); 473 } 474 } 475 return null; 476 } 477 }); 478 J2SELogicalViewProvider physicalViewProvider = getLookup().lookup(J2SELogicalViewProvider.class); 479 if (physicalViewProvider != null && physicalViewProvider.hasBrokenLinks()) { 480 BrokenReferencesSupport.showAlert(); 481 } 482 } 483 484 protected void projectClosed() { 485 try { 487 ProjectManager.getDefault().saveProject(J2SEProject.this); 488 } catch (IOException e) { 489 if (!J2SEProject.this.getProjectDirectory().canWrite()) { 490 } else { 493 ErrorManager.getDefault().notify(e); 494 } 495 } 496 497 ClassPathProviderImpl cpProvider = lookup.lookup(ClassPathProviderImpl.class); 499 GlobalPathRegistry.getDefault().unregister(ClassPath.BOOT, cpProvider.getProjectClassPaths(ClassPath.BOOT)); 500 GlobalPathRegistry.getDefault().unregister(ClassPath.SOURCE, cpProvider.getProjectClassPaths(ClassPath.SOURCE)); 501 GlobalPathRegistry.getDefault().unregister(ClassPath.COMPILE, cpProvider.getProjectClassPaths(ClassPath.COMPILE)); 502 if (mainClassUpdater != null) { 503 mainClassUpdater.unregister (); 504 mainClassUpdater = null; 505 } 506 507 if (jaxWsFo!=null) jaxWsFo.removeFileChangeListener(jaxWsListener); 508 } 509 510 } 511 512 public WebServicesClientSupport getAPIWebServicesClientSupport () { 513 return apiWebServicesClientSupport; 514 } 515 516 public JAXWSClientSupport getAPIJAXWSClientSupport() { 517 return apiJaxwsClientSupport; 518 } 519 520 524 private final class AntArtifactProviderImpl implements AntArtifactProvider { 525 526 public AntArtifact[] getBuildArtifacts() { 527 return new AntArtifact[] { 528 helper.createSimpleAntArtifact(JavaProjectConstants.ARTIFACT_TYPE_JAR, "dist.jar", evaluator(), "jar", "clean"), }; 530 } 531 532 } 533 534 private static final class RecommendedTemplatesImpl implements RecommendedTemplates, PrivilegedTemplates { 535 RecommendedTemplatesImpl (UpdateHelper helper) { 536 this.helper = helper; 537 } 538 539 private UpdateHelper helper; 540 541 543 private static final String [] APPLICATION_TYPES = new String [] { 544 "java-classes", "java-main-class", "java-forms", "gui-java-application", "java-beans", "persistence", "oasis-XML-catalogs", "XML", "ant-script", "ant-task", "web-service-clients", "wsdl", "junit", "simple-files" }; 562 563 private static final String [] LIBRARY_TYPES = new String [] { 564 "java-classes", "java-main-class", "java-forms", "java-beans", "persistence", "oasis-XML-catalogs", "XML", "ant-script", "ant-task", "servlet-types", "web-service-clients", "wsdl", "junit", "simple-files" }; 582 583 private static final String [] PRIVILEGED_NAMES = new String [] { 584 "Templates/Classes/Class.java", "Templates/Classes/Package", "Templates/Classes/Interface.java", "Templates/GUIForms/JPanel.java", "Templates/GUIForms/JFrame.java", "Templates/Persistence/Entity.java", "Templates/Persistence/RelatedCMP", "Templates/WebServices/WebServiceClient" }; 593 594 public String [] getRecommendedTypes() { 595 596 EditableProperties ep = helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); 597 boolean isLibrary = ep.getProperty (J2SEProjectProperties.MAIN_CLASS) == null || "".equals (ep.getProperty (J2SEProjectProperties.MAIN_CLASS)); return isLibrary ? LIBRARY_TYPES : APPLICATION_TYPES; 600 } 601 602 public String [] getPrivilegedTemplates() { 603 return PRIVILEGED_NAMES; 604 } 605 606 } 607 608 private static final class J2SEPropertyEvaluatorImpl implements J2SEPropertyEvaluator { 609 private PropertyEvaluator evaluator; 610 public J2SEPropertyEvaluatorImpl (PropertyEvaluator eval) { 611 evaluator = eval; 612 } 613 public PropertyEvaluator evaluator() { 614 return evaluator; 615 } 616 } 617 618 private FileObject getJaxWsFileObject() throws IOException { 619 if (jaxWsFo==null) { 620 jaxWsFo = findJaxWsFileObject(); 621 if (jaxWsFo!=null) { 622 jaxWsListener = new JaxWsListener(); 623 jaxWsFo.addFileChangeListener(jaxWsListener); 624 } 625 } 626 return jaxWsFo; 627 } 628 629 633 public void createJaxWsFileObject() throws IOException { 634 WSUtils.retrieveJaxWsFromResource(helper.getProjectDirectory()); 635 jaxWsFo = findJaxWsFileObject(); 636 assert jaxWsFo != null : "Cannot find jax-ws.xml in project's nbproject directory"; if (jaxWsFo!=null) { 638 jaxWsListener = new JaxWsListener(); 639 jaxWsFo.addFileChangeListener(jaxWsListener); 640 if (jaxWsModel!=null) jaxWsModel.setJaxWsFile(jaxWsFo); 641 else jaxWsModel = JaxWsModelProvider.getDefault().getJaxWsModel(jaxWsFo); 642 } 643 } 644 645 public FileObject findJaxWsFileObject() { 646 return helper.getProjectDirectory().getFileObject(GeneratedFilesHelper.JAX_WS_XML_PATH); 647 } 648 649 private JaxWsModel getJaxWsModel() { 650 if (jaxWsModel==null) 651 try { 652 FileObject fo = getJaxWsFileObject(); 653 if (fo==null) 654 jaxWsModel = JaxWsModelProvider.getDefault().getJaxWsModel( 655 WSUtils.class.getResourceAsStream("/org/netbeans/modules/websvc/jaxwsmodel/resources/jax-ws.xml")); else 657 jaxWsModel = JaxWsModelProvider.getDefault().getJaxWsModel(fo); 658 } catch (IOException ex) { 659 660 } 661 return jaxWsModel; 662 } 663 664 private class JaxWsListener extends FileChangeAdapter { 665 public void fileChanged(FileEvent fe) { 666 try { 667 final JaxWsModel newModel = JaxWsModelProvider.getDefault().getJaxWsModel(fe.getFile()); 668 RequestProcessor.getDefault().post(new Runnable () { 669 public void run() { 670 if (jaxWsModel!=null && newModel!=null) jaxWsModel.merge(newModel); 671 try { 672 genFilesHelper.refreshBuildScript( 673 GeneratedFilesHelper.BUILD_IMPL_XML_PATH, 674 J2SEProject.class.getResource("resources/build-impl.xsl"), jaxWsFo, false); 676 } catch (IOException ex) {} 677 } 678 679 }); 680 681 } catch (IOException ex) {} 682 } 683 } 684 685 } 686 | Popular Tags |