KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > java > j2seproject > J2SEProject


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.java.j2seproject;
21
22 import java.beans.PropertyChangeEvent JavaDoc;
23 import java.beans.PropertyChangeListener JavaDoc;
24 import java.beans.PropertyChangeSupport JavaDoc;
25 import java.io.File JavaDoc;
26 import java.io.IOException JavaDoc;
27 import java.util.Collections JavaDoc;
28 import java.util.logging.Level JavaDoc;
29 import java.util.logging.Logger JavaDoc;
30 import javax.swing.Icon JavaDoc;
31 import javax.swing.ImageIcon JavaDoc;
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 JavaDoc;
95 import org.w3c.dom.Text JavaDoc;
96 import org.w3c.dom.Node JavaDoc;
97 import org.w3c.dom.NodeList JavaDoc;
98
99 /**
100  * Represents one plain J2SE project.
101  * @author Jesse Glick, et al.
102  */

103 public final class J2SEProject implements Project, AntProjectListener {
104     
105     private static final Icon JavaDoc J2SE_PROJECT_ICON = new ImageIcon JavaDoc(Utilities.loadImage("org/netbeans/modules/java/j2seproject/ui/resources/j2seProject.gif")); // NOI18N
106

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     // WS client support
119
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 JavaDoc {
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     /**
145      * Returns the project directory
146      * @return the directory the project is located in
147      */

148     public FileObject getProjectDirectory() {
149         return helper.getProjectDirectory();
150     }
151
152     public String JavaDoc toString() {
153         return "J2SEProject[" + FileUtil.getFileDisplayName(getProjectDirectory()) + "]"; // NOI18N
154
}
155     
156     private PropertyEvaluator createEvaluator() {
157         // It is currently safe to not use the UpdateHelper for PropertyEvaluator; UH.getProperties() delegates to APH
158
// Adapted from APH.getStandardPropertyEvaluator (delegates to ProjectProperties):
159
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), // NOI18N
169
helper.getPropertyProvider(AntProjectHelper.PRIVATE_PROPERTIES_PATH),
170                 PropertyUtils.userPropertiesProvider(baseEval2,
171                     "user.properties.file", FileUtil.toFile(getProjectDirectory())), // NOI18N
172
new ConfigPropertyProvider(baseEval1, "nbproject/configs", helper), // NOI18N
173
helper.getPropertyProvider(AntProjectHelper.PROJECT_PROPERTIES_PATH));
174     }
175     private static final class ConfigPropertyProvider extends FilterPropertyProvider implements PropertyChangeListener JavaDoc {
176         private final PropertyEvaluator baseEval;
177         private final String JavaDoc prefix;
178         private final AntProjectHelper helper;
179         public ConfigPropertyProvider(PropertyEvaluator baseEval, String JavaDoc 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 JavaDoc 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 JavaDoc prefix, AntProjectHelper helper) {
192             String JavaDoc config = baseEval.getProperty(J2SEConfigurationProvider.PROP_CONFIG);
193             if (config != null) {
194                 return helper.getPropertyProvider(prefix + "/" + config + ".properties"); // NOI18N
195
} else {
196                 return PropertyUtils.fixedPropertyProvider(Collections.<String JavaDoc,String JavaDoc>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 JavaDoc[] {
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 J2SECustomizerProvider(this, this.updateHelper, evaluator(), refHelper),
234
new CustomizerProviderImpl(this, this.updateHelper, evaluator(), refHelper, this.genFilesHelper),
235             new ClassPathProviderImpl(this.helper, evaluator(), getSourceRoots(),getTestSourceRoots()), //Does not use APH to get/put properties/cfgdata
236
new CompiledSourceForBinaryQuery(this.helper, evaluator(),getSourceRoots(),getTestSourceRoots()), //Does not use APH to get/put properties/cfgdata
237
new JavadocForBinaryQueryImpl(this.helper, evaluator()), //Does not use APH to get/put properties/cfgdata
238
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()), //Does not use APH to get/put properties/cfgdata
245
new J2SEFileBuiltQuery (this.helper, evaluator(),getSourceRoots(),getTestSourceRoots()), //Does not use APH to get/put properties/cfgdata
246
new RecommendedTemplatesImpl (this.updateHelper),
247             new J2SEProjectClassPathExtender(cpMod),
248             cpMod,
249             this, // never cast an externally obtained Project to J2SEProject - use lookup instead
250
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) //Does not use APH to get/put properties/cfgdata
260
});
261         return LookupProviderSupport.createCompositeLookup(base, "Projects/org-netbeans-modules-java-j2seproject/Lookup"); //NOI18N
262
}
263
264     public void configurationXmlChanged(AntProjectEvent ev) {
265         if (ev.getPath().equals(AntProjectHelper.PROJECT_XML_PATH)) {
266             // Could be various kinds of changes, but name & displayName might have changed.
267
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         // currently ignored (probably better to listen to evaluator() if you need to)
275
}
276     
277     // Package private methods -------------------------------------------------
278

279     /**
280      * Returns the source roots of this project
281      * @return project's source roots
282      */

283     public synchronized SourceRoots getSourceRoots() {
284         if (this.sourceRoots == null) { //Local caching, no project metadata access
285
this.sourceRoots = new SourceRoots(this.updateHelper, evaluator(), getReferenceHelper(), "source-roots", false, "src.{0}{1}.dir"); //NOI18N
286
}
287         return this.sourceRoots;
288     }
289     
290     public synchronized SourceRoots getTestSourceRoots() {
291         if (this.testRoots == null) { //Local caching, no project metadata access
292
this.testRoots = new SourceRoots(this.updateHelper, evaluator(), getReferenceHelper(), "test-roots", true, "test.{0}{1}.dir"); //NOI18N
293
}
294         return this.testRoots;
295     }
296     
297     File JavaDoc getTestClassesDirectory() {
298         String JavaDoc testClassesDir = evaluator().getProperty(J2SEProjectProperties.BUILD_TEST_CLASSES_DIR);
299         if (testClassesDir == null) {
300             return null;
301         }
302         return helper.resolveFile(testClassesDir);
303     }
304     
305     // Currently unused (but see #47230):
306
/** Store configured project name. */
307     public void setName(final String JavaDoc name) {
308         ProjectManager.mutex().writeAccess(new Mutex.Action<Void JavaDoc>() {
309             public Void JavaDoc run() {
310                 Element JavaDoc data = helper.getPrimaryConfigurationData(true);
311                 // XXX replace by XMLUtil when that has findElement, findText, etc.
312
NodeList JavaDoc nl = data.getElementsByTagNameNS(J2SEProjectType.PROJECT_CONFIGURATION_NAMESPACE, "name");
313                 Element JavaDoc nameEl;
314                 if (nl.getLength() == 1) {
315                     nameEl = (Element JavaDoc) nl.item(0);
316                     NodeList JavaDoc 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, /* OK if null */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     // Private innerclasses ----------------------------------------------------
335

336     private final class Info implements ProjectInformation {
337         
338         private final PropertyChangeSupport JavaDoc pcs = new PropertyChangeSupport JavaDoc(this);
339         
340         Info() {}
341         
342         void firePropertyChange(String JavaDoc prop) {
343             pcs.firePropertyChange(prop, null, null);
344         }
345         
346         public String JavaDoc getName() {
347             return PropertyUtils.getUsablePropertyName(getDisplayName());
348         }
349         
350         public String JavaDoc getDisplayName() {
351             return ProjectManager.mutex().readAccess(new Mutex.Action<String JavaDoc>() {
352                 public String JavaDoc run() {
353                     Element JavaDoc data = updateHelper.getPrimaryConfigurationData(true);
354                     // XXX replace by XMLUtil when that has findElement, findText, etc.
355
NodeList JavaDoc nl = data.getElementsByTagNameNS(J2SEProjectType.PROJECT_CONFIGURATION_NAMESPACE, "name"); // NOI18N
356
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 JavaDoc) nl.item(0)).getNodeValue();
360                         }
361                     }
362                     return "???"; // NOI18N
363
}
364             });
365         }
366         
367         public Icon JavaDoc getIcon() {
368             return J2SE_PROJECT_ICON;
369         }
370         
371         public Project getProject() {
372             return J2SEProject.this;
373         }
374         
375         public void addPropertyChangeListener(PropertyChangeListener JavaDoc listener) {
376             pcs.addPropertyChangeListener(listener);
377         }
378         
379         public void removePropertyChangeListener(PropertyChangeListener JavaDoc 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 JavaDoc {
390             //May be called by {@link AuxiliaryConfiguration#putConfigurationFragment}
391
//which didn't affect the j2seproject
392
if (updateHelper.isCurrent()) {
393                 //Refresh build-impl.xml only for j2seproject/2
394
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             // Check up on build scripts.
415
try {
416                 if (updateHelper.isCurrent()) {
417                     //Refresh build-impl.xml only for j2seproject/2
418
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 JavaDoc e) {
430                 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
431             }
432             
433             // register project's classpaths to GlobalPathRegistry
434
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             //register updater of main.class
440
//the updater is active only on the opened projects
441
mainClassUpdater = new MainClassUpdater (J2SEProject.this, eval, updateHelper,
442                     cpProvider.getProjectClassPaths(ClassPath.SOURCE)[0], J2SEProjectProperties.MAIN_CLASS);
443
444             // Make it easier to run headless builds on the same machine at least.
445
ProjectManager.mutex().writeAccess(new Mutex.Action<Void JavaDoc>() {
446                 public Void JavaDoc run() {
447                     EditableProperties ep = updateHelper.getProperties(AntProjectHelper.PRIVATE_PROPERTIES_PATH);
448                     File JavaDoc buildProperties = new File JavaDoc(System.getProperty("netbeans.user"), "build.properties"); // NOI18N
449
ep.setProperty("user.properties.file", buildProperties.getAbsolutePath()); //NOI18N
450

451                     // set jaxws.endorsed.dir property (for endorsed mechanism to be used with wsimport, wsgen)
452
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, "**"); // NOI18N
458
}
459                     if (!ep.containsKey(J2SEProjectProperties.EXCLUDES)) {
460                         ep.setProperty(J2SEProjectProperties.EXCLUDES, ""); // NOI18N
461
}
462                     helper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, ep);
463                     try {
464                         ProjectManager.getDefault().saveProject(J2SEProject.this);
465                     } catch (IOException JavaDoc e) {
466                         //#91398 provide a better error message in case of read-only location of project.
467
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             // Probably unnecessary, but just in case:
486
try {
487                 ProjectManager.getDefault().saveProject(J2SEProject.this);
488             } catch (IOException JavaDoc e) {
489                 if (!J2SEProject.this.getProjectDirectory().canWrite()) {
490                     // #91398 - ignore, we already reported on project open.
491
// not counting with someone setting the ro flag while the project is opened.
492
} else {
493                     ErrorManager.getDefault().notify(e);
494                 }
495             }
496             
497             // unregister project's classpaths to GlobalPathRegistry
498
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     /**
521      * Exports the main JAR as an official build product for use from other scripts.
522      * The type of the artifact will be {@link AntArtifact#TYPE_JAR}.
523      */

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"), // NOI18N
529
};
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         // List of primarily supported templates
542

543         private static final String JavaDoc[] APPLICATION_TYPES = new String JavaDoc[] {
544             "java-classes", // NOI18N
545
"java-main-class", // NOI18N
546
"java-forms", // NOI18N
547
"gui-java-application", // NOI18N
548
"java-beans", // NOI18N
549
"persistence", // NOI18N
550
"oasis-XML-catalogs", // NOI18N
551
"XML", // NOI18N
552
"ant-script", // NOI18N
553
"ant-task", // NOI18N
554
"web-service-clients", // NOI18N
555
"wsdl", // NOI18N
556
// "servlet-types", // NOI18N
557
// "web-types", // NOI18N
558
"junit", // NOI18N
559
// "MIDP", // NOI18N
560
"simple-files" // NOI18N
561
};
562         
563         private static final String JavaDoc[] LIBRARY_TYPES = new String JavaDoc[] {
564             "java-classes", // NOI18N
565
"java-main-class", // NOI18N
566
"java-forms", // NOI18N
567
//"gui-java-application", // NOI18N
568
"java-beans", // NOI18N
569
"persistence", // NOI18N
570
"oasis-XML-catalogs", // NOI18N
571
"XML", // NOI18N
572
"ant-script", // NOI18N
573
"ant-task", // NOI18N
574
"servlet-types", // NOI18N
575
"web-service-clients", // NOI18N
576
"wsdl", // NOI18N
577
// "web-types", // NOI18N
578
"junit", // NOI18N
579
// "MIDP", // NOI18N
580
"simple-files" // NOI18N
581
};
582         
583         private static final String JavaDoc[] PRIVILEGED_NAMES = new String JavaDoc[] {
584             "Templates/Classes/Class.java", // NOI18N
585
"Templates/Classes/Package", // NOI18N
586
"Templates/Classes/Interface.java", // NOI18N
587
"Templates/GUIForms/JPanel.java", // NOI18N
588
"Templates/GUIForms/JFrame.java", // NOI18N
589
"Templates/Persistence/Entity.java", // NOI18N
590
"Templates/Persistence/RelatedCMP", // NOI18N
591
"Templates/WebServices/WebServiceClient" // NOI18N
592
};
593         
594         public String JavaDoc[] getRecommendedTypes() {
595             
596             EditableProperties ep = helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
597             // if the project has no main class, it's not really an application
598
boolean isLibrary = ep.getProperty (J2SEProjectProperties.MAIN_CLASS) == null || "".equals (ep.getProperty (J2SEProjectProperties.MAIN_CLASS)); // NOI18N
599
return isLibrary ? LIBRARY_TYPES : APPLICATION_TYPES;
600         }
601         
602         public String JavaDoc[] 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 JavaDoc {
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     /** copy jax-ws.xml from default filesystem to nbproject directory,
630      * generate JaxWsModel,
631      * add FileChangeListener to jax-ws.xml file object
632      */

633     public void createJaxWsFileObject() throws IOException JavaDoc {
634         WSUtils.retrieveJaxWsFromResource(helper.getProjectDirectory());
635         jaxWsFo = findJaxWsFileObject();
636         assert jaxWsFo != null : "Cannot find jax-ws.xml in project's nbproject directory"; //NOI18N
637
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"));//NOI18N
656
else
657                     jaxWsModel = JaxWsModelProvider.getDefault().getJaxWsModel(fo);
658             } catch (IOException JavaDoc 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 JavaDoc() {
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"), // NOI18N
675
jaxWsFo, false);
676                         } catch (IOException JavaDoc ex) {}
677                     }
678                     
679                 });
680                 
681             } catch (IOException JavaDoc ex) {}
682         }
683     }
684
685 }
686
Popular Tags