KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > clientproject > AppClientProject


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.j2ee.clientproject;
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.net.URI JavaDoc;
28 import java.util.LinkedList JavaDoc;
29 import java.util.List JavaDoc;
30 import javax.swing.Icon JavaDoc;
31 import javax.swing.ImageIcon JavaDoc;
32 import javax.swing.JButton JavaDoc;
33 import org.netbeans.api.java.classpath.ClassPath;
34 import org.netbeans.api.java.classpath.GlobalPathRegistry;
35 import org.netbeans.api.java.project.JavaProjectConstants;
36 import org.netbeans.api.project.FileOwnerQuery;
37 import org.netbeans.api.project.Project;
38 import org.netbeans.api.project.ProjectInformation;
39 import org.netbeans.api.project.ProjectManager;
40 import org.netbeans.api.project.ant.AntArtifact;
41 import org.netbeans.modules.j2ee.api.ejbjar.Car;
42 import org.netbeans.modules.j2ee.clientproject.classpath.AppClientProjectClassPathExtender;
43 import org.netbeans.modules.j2ee.clientproject.classpath.ClassPathProviderImpl;
44 import org.netbeans.modules.j2ee.clientproject.classpath.ClassPathSupport;
45 import org.netbeans.modules.j2ee.clientproject.queries.CompiledSourceForBinaryQuery;
46 import org.netbeans.modules.j2ee.clientproject.queries.JavadocForBinaryQueryImpl;
47 import org.netbeans.modules.j2ee.clientproject.queries.SourceLevelQueryImpl;
48 import org.netbeans.modules.j2ee.clientproject.queries.UnitTestForSourceQueryImpl;
49 import org.netbeans.modules.j2ee.clientproject.ui.AppClientLogicalViewProvider;
50 import org.netbeans.modules.j2ee.clientproject.ui.customizer.AppClientProjectProperties;
51 import org.netbeans.modules.j2ee.clientproject.ui.customizer.CustomizerProviderImpl;
52 import org.netbeans.modules.j2ee.clientproject.wsclient.AppClientProjectJAXWSClientSupport;
53 import org.netbeans.modules.j2ee.clientproject.wsclient.AppClientProjectWebServicesClientSupport;
54 import org.netbeans.modules.j2ee.clientproject.wsclient.AppClientProjectWebServicesSupportProvider;
55 import org.netbeans.modules.j2ee.common.ui.BrokenServerSupport;
56 import org.netbeans.modules.j2ee.deployment.devmodules.api.Deployment;
57 import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eePlatform;
58 import org.netbeans.modules.j2ee.spi.ejbjar.CarFactory;
59 import org.netbeans.modules.websvc.api.client.WebServicesClientSupport;
60 import org.netbeans.modules.websvc.api.jaxws.client.JAXWSClientSupport;
61 import org.netbeans.modules.websvc.api.jaxws.project.GeneratedFilesHelper;
62 import org.netbeans.modules.websvc.api.jaxws.project.WSUtils;
63 import org.netbeans.modules.websvc.api.jaxws.project.config.JaxWsModel;
64 import org.netbeans.modules.websvc.api.jaxws.project.config.JaxWsModelProvider;
65 import org.netbeans.modules.websvc.spi.client.WebServicesClientSupportFactory;
66 import org.netbeans.modules.websvc.spi.jaxws.client.JAXWSClientSupportFactory;
67 import org.netbeans.spi.java.project.support.ui.BrokenReferencesSupport;
68 import org.netbeans.spi.project.AuxiliaryConfiguration;
69 import org.netbeans.spi.project.SubprojectProvider;
70 import org.netbeans.spi.project.ant.AntArtifactProvider;
71 import org.netbeans.spi.project.support.LookupProviderSupport;
72 import org.netbeans.spi.project.support.ant.AntProjectEvent;
73 import org.netbeans.spi.project.support.ant.AntProjectHelper;
74 import org.netbeans.spi.project.support.ant.AntProjectListener;
75 import org.netbeans.spi.project.support.ant.EditableProperties;
76 import org.netbeans.spi.project.support.ant.ProjectXmlSavedHook;
77 import org.netbeans.spi.project.support.ant.PropertyEvaluator;
78 import org.netbeans.spi.project.support.ant.PropertyUtils;
79 import org.netbeans.spi.project.support.ant.ReferenceHelper;
80 import org.netbeans.spi.project.support.ant.SourcesHelper;
81 import org.netbeans.spi.project.ui.PrivilegedTemplates;
82 import org.netbeans.spi.project.ui.ProjectOpenedHook;
83 import org.netbeans.spi.project.ui.RecommendedTemplates;
84 import org.netbeans.spi.project.ui.support.UILookupMergerSupport;
85 import org.openide.DialogDisplayer;
86 import org.openide.ErrorManager;
87 import org.openide.NotifyDescriptor;
88 import org.openide.filesystems.FileAttributeEvent;
89 import org.openide.filesystems.FileChangeAdapter;
90 import org.openide.filesystems.FileChangeListener;
91 import org.openide.filesystems.FileEvent;
92 import org.openide.filesystems.FileObject;
93 import org.openide.filesystems.FileRenameEvent;
94 import org.openide.filesystems.FileUtil;
95 import org.openide.loaders.DataObject;
96 import org.openide.loaders.DataObjectNotFoundException;
97 import org.openide.util.Lookup;
98 import org.openide.util.Mutex;
99 import org.openide.util.NbBundle;
100 import org.openide.util.RequestProcessor;
101 import org.openide.util.Utilities;
102 import org.openide.util.lookup.Lookups;
103 import org.w3c.dom.Element JavaDoc;
104 import org.w3c.dom.Node JavaDoc;
105 import org.w3c.dom.NodeList JavaDoc;
106 import org.w3c.dom.Text JavaDoc;
107
108 /**
109  * Represents one plain Application Client project.
110  * @author Jesse Glick, et al.
111  */

112 public final class AppClientProject implements Project, AntProjectListener, FileChangeListener {
113     
114     private static final Icon JavaDoc CAR_PROJECT_ICON = new ImageIcon JavaDoc(Utilities.loadImage("org/netbeans/modules/j2ee/clientproject/ui/resources/appclient.gif")); // NOI18N
115

116     private final AuxiliaryConfiguration aux;
117     private final AntProjectHelper helper;
118     private final PropertyEvaluator eval;
119     private final ReferenceHelper refHelper;
120     private final GeneratedFilesHelper genFilesHelper;
121     private final Lookup lookup;
122     private final UpdateHelper updateHelper;
123     private MainClassUpdater mainClassUpdater;
124     private SourceRoots sourceRoots;
125     private SourceRoots testRoots;
126     
127     // WS client support
128
private AppClientProjectWebServicesClientSupport carProjectWebServicesClientSupport;
129     private AppClientProjectJAXWSClientSupport jaxWsClientSupport;
130     private WebServicesClientSupport apiWebServicesClientSupport;
131     private JAXWSClientSupport apiJAXWSClientSupport;
132     private JaxWsModel jaxWsModel;
133     private JaxWsListener jaxWsListener;
134     private FileObject jaxWsFo;
135     
136     private PropertyChangeListener JavaDoc j2eePlatformListener;
137     private final AppClientProvider appClient;
138     private final Car apiJar;
139     private JarContainerImpl enterpriseResourceSupport;
140     private FileObject libFolder;
141     private final AppClientProjectClassPathExtender classpathExtender;
142
143     
144     AppClientProject(AntProjectHelper helper) throws IOException JavaDoc {
145         this.helper = helper;
146         eval = createEvaluator();
147         aux = helper.createAuxiliaryConfiguration();
148         refHelper = new ReferenceHelper(helper, aux, eval);
149         genFilesHelper = new GeneratedFilesHelper(helper);
150         this.updateHelper = new UpdateHelper(this, this.helper, this.aux, this.genFilesHelper,
151                 UpdateHelper.createDefaultNotifier());
152         carProjectWebServicesClientSupport = new AppClientProjectWebServicesClientSupport(this, helper, refHelper);
153         jaxWsClientSupport = new AppClientProjectJAXWSClientSupport(this, helper);
154         apiWebServicesClientSupport = WebServicesClientSupportFactory.createWebServicesClientSupport(carProjectWebServicesClientSupport);
155         apiJAXWSClientSupport = JAXWSClientSupportFactory.createJAXWSClientSupport(jaxWsClientSupport);
156         appClient = new AppClientProvider(this, helper);
157         apiJar = CarFactory.createCar(appClient);
158         enterpriseResourceSupport = new JarContainerImpl(this, refHelper, helper);
159         classpathExtender = new AppClientProjectClassPathExtender(this, updateHelper, evaluator(), refHelper);
160         lookup = createLookup(aux);
161         helper.addAntProjectListener(this);
162     }
163     
164     /**
165      * Returns the project directory
166      * @return the directory the project is located in
167      */

168     public FileObject getProjectDirectory() {
169         return helper.getProjectDirectory();
170     }
171     
172     public String JavaDoc toString() {
173         return "CarProject[" + getProjectDirectory() + "]"; // NOI18N
174
}
175     
176     private PropertyEvaluator createEvaluator() {
177         // XXX might need to use a custom evaluator to handle active platform substitutions... TBD
178
// It is currently safe to not use the UpdateHelper for PropertyEvaluator; UH.getProperties() delegates to APH
179
return helper.getStandardPropertyEvaluator();
180     }
181     
182     PropertyEvaluator evaluator() {
183         return eval;
184     }
185     
186     public ReferenceHelper getReferenceHelper() {
187         return this.refHelper;
188     }
189     
190     public UpdateHelper getUpdateHelper() {
191         return this.updateHelper;
192     }
193     
194     public Lookup getLookup() {
195         return lookup;
196     }
197     
198     public AntProjectHelper getAntProjectHelper() {
199         return helper;
200     }
201     
202     private Lookup createLookup(AuxiliaryConfiguration aux) {
203         SubprojectProvider spp = refHelper.createSubprojectProvider();
204
205         final SourcesHelper sourcesHelper = new SourcesHelper(helper, evaluator());
206         String JavaDoc configFilesLabel = NbBundle.getMessage(AppClientLogicalViewProvider.class, "LBL_Node_ConfFiles"); //NOI18N
207

208         //sourcesHelper.addPrincipalSourceRoot("${"+AppClientProjectProperties.SOURCE_ROOT+"}", ejbModuleLabel, /*XXX*/null, null);
209
sourcesHelper.addPrincipalSourceRoot("${"+AppClientProjectProperties.META_INF+"}", configFilesLabel, /*XXX*/null, null); // NOI18N
210

211         ProjectManager.mutex().postWriteRequest(new Runnable JavaDoc() {
212             public void run() {
213                 sourcesHelper.registerExternalRoots(FileOwnerQuery.EXTERNAL_ALGORITHM_TRANSIENT);
214             }
215         });
216         Lookup base = Lookups.fixed(new Object JavaDoc[] {
217             new Info(),
218             aux,
219             helper.createCacheDirectoryProvider(),
220             spp,
221             new AppClientActionProvider( this, helper, this.updateHelper ),
222             new AppClientLogicalViewProvider(this, this.updateHelper, evaluator(), refHelper),
223             // new J2SECustomizerProvider(this, this.updateHelper, evaluator(), refHelper),
224
new CustomizerProviderImpl(this, this.updateHelper, evaluator(), refHelper, this.genFilesHelper),
225             new ClassPathProviderImpl(this.helper, evaluator(), getSourceRoots(),getTestSourceRoots()), //Does not use APH to get/put properties/cfgdata
226
new CompiledSourceForBinaryQuery(this.helper, evaluator(),getSourceRoots(),getTestSourceRoots()), //Does not use APH to get/put properties/cfgdata
227
new JavadocForBinaryQueryImpl(this.helper, evaluator()), //Does not use APH to get/put properties/cfgdata
228
new AntArtifactProviderImpl(),
229             new ProjectXmlSavedHookImpl(),
230             new ProjectOpenedHookImpl(),
231             new UnitTestForSourceQueryImpl(getSourceRoots(),getTestSourceRoots()),
232             new SourceLevelQueryImpl(evaluator()),
233             new AppClientSources(this.helper, evaluator(), getSourceRoots(), getTestSourceRoots()),
234             new AppClientSharabilityQuery(this.helper, evaluator(), getSourceRoots(), getTestSourceRoots()), //Does not use APH to get/put properties/cfgdata
235
new AppClientFileBuiltQuery(this.helper, evaluator(),getSourceRoots(),getTestSourceRoots()), //Does not use APH to get/put properties/cfgdata
236
new RecommendedTemplatesImpl(this.updateHelper),
237             classpathExtender,
238             this, // never cast an externally obtained Project to AppClientProject - use lookup instead
239
new AppClientProjectOperations(this),
240             new AppClientProjectWebServicesSupportProvider(),
241             
242             new ProjectAppClientProvider(this),
243             appClient,
244             new AppClientPersistenceProvider(this, evaluator()),
245             enterpriseResourceSupport,
246             getJaxWsModel(),
247             UILookupMergerSupport.createPrivilegedTemplatesMerger(),
248             UILookupMergerSupport.createRecommendedTemplatesMerger(),
249             LookupProviderSupport.createSourcesMerger()
250         });
251         return LookupProviderSupport.createCompositeLookup(base, "Projects/org-netbeans-modules-j2ee-clientproject/Lookup"); //NOI18N
252
}
253     
254     public void configurationXmlChanged(AntProjectEvent ev) {
255         if (ev.getPath().equals(AntProjectHelper.PROJECT_XML_PATH)) {
256             // Could be various kinds of changes, but name & displayName might have changed.
257
Info info = (Info)getLookup().lookup(ProjectInformation.class);
258             info.firePropertyChange(ProjectInformation.PROP_NAME);
259             info.firePropertyChange(ProjectInformation.PROP_DISPLAY_NAME);
260         }
261     }
262     
263     public void propertiesChanged(AntProjectEvent ev) {
264         // currently ignored (probably better to listen to evaluator() if you need to)
265
}
266     
267     // Package private methods -------------------------------------------------
268

269     /**
270      * Returns the source roots of this project
271      * @return project's source roots
272      */

273     public synchronized SourceRoots getSourceRoots() {
274         if (this.sourceRoots == null) { //Local caching, no project metadata access
275
this.sourceRoots = new SourceRoots(this.updateHelper, evaluator(), getReferenceHelper(), "source-roots", false, "src.{0}{1}.dir"); //NOI18N
276
}
277         return this.sourceRoots;
278     }
279     
280     public synchronized SourceRoots getTestSourceRoots() {
281         if (this.testRoots == null) { //Local caching, no project metadata access
282
this.testRoots = new SourceRoots(this.updateHelper, evaluator(), getReferenceHelper(), "test-roots", true, "test.{0}{1}.dir"); //NOI18N
283
}
284         return this.testRoots;
285     }
286     
287     File JavaDoc getTestClassesDirectory() {
288         String JavaDoc testClassesDir = evaluator().getProperty(AppClientProjectProperties.BUILD_TEST_CLASSES_DIR);
289         if (testClassesDir == null) {
290             return null;
291         }
292         return helper.resolveFile(testClassesDir);
293     }
294     
295     // Currently unused (but see #47230):
296
/** Store configured project name. */
297     public void setName(final String JavaDoc name) {
298         ProjectManager.mutex().writeAccess(new Mutex.Action() {
299             public Object JavaDoc run() {
300                 Element JavaDoc data = helper.getPrimaryConfigurationData(true);
301                 // XXX replace by XMLUtil when that has findElement, findText, etc.
302
NodeList JavaDoc nl = data.getElementsByTagNameNS(AppClientProjectType.PROJECT_CONFIGURATION_NAMESPACE, "name"); // NOI18N
303
Element JavaDoc nameEl;
304                 if (nl.getLength() == 1) {
305                     nameEl = (Element JavaDoc) nl.item(0);
306                     NodeList JavaDoc deadKids = nameEl.getChildNodes();
307                     while (deadKids.getLength() > 0) {
308                         nameEl.removeChild(deadKids.item(0));
309                     }
310                 } else {
311                     nameEl = data.getOwnerDocument().createElementNS(AppClientProjectType.PROJECT_CONFIGURATION_NAMESPACE, "name"); // NOI18N
312
data.insertBefore(nameEl, /* OK if null */data.getChildNodes().item(0));
313                 }
314                 nameEl.appendChild(data.getOwnerDocument().createTextNode(name));
315                 helper.putPrimaryConfigurationData(data, true);
316                 return null;
317             }
318         });
319     }
320     
321     /** Return configured project name. */
322     public String JavaDoc getName() {
323         return (String JavaDoc) ProjectManager.mutex().readAccess(new Mutex.Action() {
324             public Object JavaDoc run() {
325                 Element JavaDoc data = updateHelper.getPrimaryConfigurationData(true);
326                 // XXX replace by XMLUtil when that has findElement, findText, etc.
327
NodeList JavaDoc nl = data.getElementsByTagNameNS(AppClientProjectType.PROJECT_CONFIGURATION_NAMESPACE, "name"); // NOI18N
328
if (nl.getLength() == 1) {
329                     nl = nl.item(0).getChildNodes();
330                     if (nl.getLength() == 1 && nl.item(0).getNodeType() == Node.TEXT_NODE) {
331                         return ((Text JavaDoc) nl.item(0)).getNodeValue();
332                     }
333                 }
334                 return "CAR???"; // NOI18N
335
}
336         });
337     }
338
339     public void fileAttributeChanged (FileAttributeEvent fe) {
340     }
341     
342     public void fileChanged (FileEvent fe) {
343     }
344     
345     public void fileDataCreated (FileEvent fe) {
346         FileObject fo = fe.getFile ();
347         checkLibraryFolder (fo);
348     }
349     
350     public void fileDeleted (FileEvent fe) {
351     }
352     
353     public void fileFolderCreated (FileEvent fe) {
354     }
355     
356     public void fileRenamed (FileRenameEvent fe) {
357         FileObject fo = fe.getFile ();
358         checkLibraryFolder (fo);
359     }
360
361     private void checkLibraryFolder (FileObject fo) {
362         if (!FileUtil.isArchiveFile(fo)) {
363             return;
364         }
365         
366         if (fo.getParent ().equals (libFolder)) {
367             try {
368                 classpathExtender.addArchiveFile(fo);
369             }
370             catch (IOException JavaDoc e) {
371                 ErrorManager.getDefault().notify(e);
372             }
373         }
374     }
375     
376     public void registerJ2eePlatformListener(final J2eePlatform platform) {
377         // listen to classpath changes
378
j2eePlatformListener = new PropertyChangeListener JavaDoc() {
379             public void propertyChange(PropertyChangeEvent JavaDoc evt) {
380                 if (evt.getPropertyName().equals(J2eePlatform.PROP_CLASSPATH)) {
381                     ProjectManager.mutex().writeAccess(new Mutex.Action() {
382                         public Object JavaDoc run() {
383                             EditableProperties ep = helper.getProperties(AntProjectHelper.PRIVATE_PROPERTIES_PATH);
384                             String JavaDoc classpath = Utils.toClasspathString(platform.getClasspathEntries());
385                             ep.setProperty(AppClientProjectProperties.J2EE_PLATFORM_CLASSPATH, classpath);
386                             helper.putProperties(AntProjectHelper.PRIVATE_PROPERTIES_PATH, ep);
387                             try {
388                                 ProjectManager.getDefault().saveProject(AppClientProject.this);
389                             } catch (IOException JavaDoc e) {
390                                 ErrorManager.getDefault().notify(e);
391                             }
392                             return null;
393                         }
394                     });
395                 }
396             }
397         };
398         platform.addPropertyChangeListener(j2eePlatformListener);
399     }
400     
401     public void unregisterJ2eePlatformListener(J2eePlatform platform) {
402         if (j2eePlatformListener != null) {
403             platform.removePropertyChangeListener(j2eePlatformListener);
404         }
405     }
406     
407     public Car getAPICar() {
408         return apiJar;
409     }
410     
411     public AppClientProvider getCarModule() {
412         return appClient;
413     }
414     
415     
416     private String JavaDoc getProperty(String JavaDoc path, String JavaDoc name) {
417         return helper.getProperties(path).getProperty(name);
418     }
419     
420     String JavaDoc getBuildXmlName() {
421         String JavaDoc storedName = helper.getStandardPropertyEvaluator().getProperty(AppClientProjectProperties.BUILD_FILE);
422         return storedName == null ? GeneratedFilesHelper.BUILD_XML_PATH : storedName;
423     }
424         
425     /**
426      * Refreshes the build-impl.xml script. If it was modified by the user, it
427      * displays a confirmation dialog.
428      *
429      * @param askUserIfFlags only display the dialog if the state of the build script
430      * contains these flags (along with {@link GeneratedFilesHelper#FLAG_MODIFIED},
431      * which is always checked)
432      * @param askInCurrentThread if false, asks in another thread
433      */

434     private void refreshBuildImplXml(int askUserIfFlags, boolean askInCurrentThread) {
435         askUserIfFlags |= GeneratedFilesHelper.FLAG_MODIFIED;
436         int flags = genFilesHelper.getBuildScriptState(
437             GeneratedFilesHelper.BUILD_IMPL_XML_PATH,
438             AppClientProject.class.getResource("resources/build-impl.xsl"), jaxWsFo); // NOI18N
439
if ((flags & askUserIfFlags) == askUserIfFlags) {
440             Runnable JavaDoc run = new Runnable JavaDoc () {
441                 public void run () {
442                     JButton JavaDoc updateOption = new JButton JavaDoc (NbBundle.getMessage(AppClientProject.class, "CTL_Regenerate"));
443                     if (DialogDisplayer.getDefault().notify(
444                         new NotifyDescriptor (NbBundle.getMessage(AppClientProject.class,"TXT_BuildImplRegenerate"),
445                             NbBundle.getMessage(AppClientProject.class,"TXT_BuildImplRegenerateTitle"),
446                             NotifyDescriptor.DEFAULT_OPTION,
447                             NotifyDescriptor.WARNING_MESSAGE,
448                             new Object JavaDoc[] {
449                                 updateOption,
450                                 NotifyDescriptor.CANCEL_OPTION
451                             },
452                             updateOption)) == updateOption) {
453                         try {
454                             genFilesHelper.generateBuildScriptFromStylesheet(
455                                 GeneratedFilesHelper.BUILD_IMPL_XML_PATH,
456                                 AppClientProject.class.getResource("resources/build-impl.xsl"), jaxWsFo); // NOI18N
457
} catch (IOException JavaDoc e) {
458                             ErrorManager.getDefault().notify(e);
459                         } catch (IllegalStateException JavaDoc e) {
460                             ErrorManager.getDefault().notify(e);
461                         }
462                     }
463                 }
464             };
465             if (askInCurrentThread) {
466                 run.run();
467             } else {
468                 RequestProcessor.getDefault().post(run);
469             }
470         } else {
471             try {
472                 genFilesHelper.refreshBuildScript(
473                     GeneratedFilesHelper.BUILD_IMPL_XML_PATH,
474                     AppClientProject.class.getResource("resources/build-impl.xsl"), // NOI18N
475
jaxWsFo, false);
476             } catch (IOException JavaDoc e) {
477                 ErrorManager.getDefault().notify(e);
478             }
479         }
480     }
481     
482     // Private innerclasses ----------------------------------------------------
483

484     private final class Info implements ProjectInformation {
485         
486         private final PropertyChangeSupport JavaDoc pcs = new PropertyChangeSupport JavaDoc(this);
487         
488         Info() {}
489         
490         void firePropertyChange(String JavaDoc prop) {
491             pcs.firePropertyChange(prop, null, null);
492         }
493         
494         public String JavaDoc getName() {
495             return PropertyUtils.getUsablePropertyName(getDisplayName());
496         }
497         
498         public String JavaDoc getDisplayName() {
499             return (String JavaDoc) ProjectManager.mutex().readAccess(new Mutex.Action() {
500                 public Object JavaDoc run() {
501                     Element JavaDoc data = updateHelper.getPrimaryConfigurationData(true);
502                     // XXX replace by XMLUtil when that has findElement, findText, etc.
503
NodeList JavaDoc nl = data.getElementsByTagNameNS(AppClientProjectType.PROJECT_CONFIGURATION_NAMESPACE, "name"); // NOI18N
504
if (nl.getLength() == 1) {
505                         nl = nl.item(0).getChildNodes();
506                         if (nl.getLength() == 1 && nl.item(0).getNodeType() == Node.TEXT_NODE) {
507                             return ((Text JavaDoc) nl.item(0)).getNodeValue();
508                         }
509                     }
510                     return "???"; // NOI18N
511
}
512             });
513         }
514         
515         public Icon JavaDoc getIcon() {
516             return CAR_PROJECT_ICON;
517         }
518         
519         public Project getProject() {
520             return AppClientProject.this;
521         }
522         
523         public void addPropertyChangeListener(PropertyChangeListener JavaDoc listener) {
524             pcs.addPropertyChangeListener(listener);
525         }
526         
527         public void removePropertyChangeListener(PropertyChangeListener JavaDoc listener) {
528             pcs.removePropertyChangeListener(listener);
529         }
530         
531     }
532     
533     private final class ProjectXmlSavedHookImpl extends ProjectXmlSavedHook {
534         
535         ProjectXmlSavedHookImpl() {}
536         
537         protected void projectXmlSaved() throws IOException JavaDoc {
538             refreshBuildImplXml(0, false);
539             
540             genFilesHelper.refreshBuildScript(
541                 getBuildXmlName(),
542                 AppClientProject.class.getResource("resources/build.xsl"), //NOI18N
543
jaxWsFo, false);
544         }
545         
546     }
547     
548     /** Package-private for unit tests only. */
549     final class ProjectOpenedHookImpl extends ProjectOpenedHook {
550         
551         ProjectOpenedHookImpl() {}
552         
553         protected void projectOpened() {
554             // Check up on build scripts.
555
try {
556                 //Check libraries and add them to classpath automatically
557
String JavaDoc libFolderName = helper.getStandardPropertyEvaluator ().getProperty (AppClientProjectProperties.LIBRARIES_DIR);
558
559                 //DDDataObject initialization to be ready to listen on changes (#49656)
560
try {
561                     FileObject ddFO = appClient.getDeploymentDescriptor();
562                     if (ddFO != null) {
563                         DataObject.find(ddFO);
564                     }
565                 } catch (DataObjectNotFoundException ex) {}
566                 
567                 if (libFolderName != null && helper.resolveFile (libFolderName).isDirectory ()) {
568                     libFolder = helper.resolveFileObject(libFolderName);
569                         FileObject children [] = libFolder.getChildren ();
570                         List JavaDoc<FileObject> libs = new LinkedList JavaDoc<FileObject>();
571                         for (int i = 0; i < children.length; i++) {
572                             if (FileUtil.isArchiveFile(children[i])) {
573                                 libs.add(children[i]);
574                             }
575                         }
576                         FileObject[] libsArray = new FileObject[libs.size()];
577                         libs.toArray(libsArray);
578                         classpathExtender.addArchiveFiles(AppClientProjectProperties.JAVAC_CLASSPATH, libsArray, ClassPathSupport.ELEMENT_INCLUDED_LIBRARIES);
579                         libFolder.addFileChangeListener (AppClientProject.this);
580                 }
581                 
582                 // Check up on build scripts.
583

584                 refreshBuildImplXml( GeneratedFilesHelper.FLAG_OLD_PROJECT_XML, true);
585                 
586                 genFilesHelper.refreshBuildScript(
587                     getBuildXmlName(),
588                     AppClientProject.class.getResource("resources/build.xsl"), //NOI18N
589
jaxWsFo, true);
590                 
591                 String JavaDoc servInstID = getProperty(AntProjectHelper.PRIVATE_PROPERTIES_PATH, AppClientProjectProperties.J2EE_SERVER_INSTANCE);
592                 J2eePlatform platform = Deployment.getDefault().getJ2eePlatform(servInstID);
593                 if (platform != null) {
594                     // updates j2ee.platform.cp & wscompile.cp & reg. j2ee platform listener
595
AppClientProjectProperties.setServerInstance(AppClientProject.this, AppClientProject.this.helper, servInstID);
596                 } else {
597                     // if there is some server instance of the type which was used
598
// previously do not ask and use it
599
String JavaDoc serverType = getProperty(AntProjectHelper.PROJECT_PROPERTIES_PATH, AppClientProjectProperties.J2EE_SERVER_TYPE);
600                     if (serverType != null) {
601                         String JavaDoc[] servInstIDs = Deployment.getDefault().getInstancesOfServer(serverType);
602                         if (servInstIDs.length > 0) {
603                             AppClientProjectProperties.setServerInstance(AppClientProject.this, AppClientProject.this.helper, servInstIDs[0]);
604                             platform = Deployment.getDefault().getJ2eePlatform(servInstIDs[0]);
605                         }
606                     }
607                     if (platform == null) {
608                         BrokenServerSupport.showAlert();
609                     }
610                 }
611             } catch (IOException JavaDoc e) {
612                 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
613             }
614
615             
616             // register project's classpaths to GlobalPathRegistry
617
ClassPathProviderImpl cpProvider = (ClassPathProviderImpl)lookup.lookup(ClassPathProviderImpl.class);
618             GlobalPathRegistry.getDefault().register(ClassPath.BOOT, cpProvider.getProjectClassPaths(ClassPath.BOOT));
619             GlobalPathRegistry.getDefault().register(ClassPath.SOURCE, cpProvider.getProjectClassPaths(ClassPath.SOURCE));
620             GlobalPathRegistry.getDefault().register(ClassPath.COMPILE, cpProvider.getProjectClassPaths(ClassPath.COMPILE));
621             
622             // initialize the server configuration
623
// it MUST BE called AFTER classpaths are registered to GlobalPathRegistry!
624
// AppClient DDProvider (used here) needs classpath set correctly when resolving Java Extents for annotations
625
appClient.getConfigSupport().ensureConfigurationReady();
626             
627             //register updater of main.class
628
//the updater is active only on the opened projects
629
mainClassUpdater = new MainClassUpdater(AppClientProject.this, eval, updateHelper,
630                     cpProvider.getProjectClassPaths(ClassPath.SOURCE)[0], AppClientProjectProperties.MAIN_CLASS);
631             
632             // Make it easier to run headless builds on the same machine at least.
633
ProjectManager.mutex().writeAccess(new Mutex.Action() {
634                 public Object JavaDoc run() {
635                     EditableProperties ep = updateHelper.getProperties(AntProjectHelper.PRIVATE_PROPERTIES_PATH);
636                     File JavaDoc buildProperties = new File JavaDoc(System.getProperty("netbeans.user"), "build.properties"); // NOI18N
637
ep.setProperty("user.properties.file", buildProperties.getAbsolutePath()); //NOI18N
638

639                     // set jaxws.endorsed.dir property (for endorsed mechanism to be used with wsimport, wsgen)
640
WSUtils.setJaxWsEndorsedDirProperty(ep);
641                     
642                     updateHelper.putProperties(AntProjectHelper.PRIVATE_PROPERTIES_PATH, ep);
643                     try {
644                         ProjectManager.getDefault().saveProject(AppClientProject.this);
645                     } catch (IOException JavaDoc e) {
646                         ErrorManager.getDefault().notify(e);
647                     }
648                     return null;
649                 }
650             });
651             AppClientLogicalViewProvider physicalViewProvider = (AppClientLogicalViewProvider)
652             AppClientProject.this.getLookup().lookup(AppClientLogicalViewProvider.class);
653             if (physicalViewProvider != null && physicalViewProvider.hasBrokenLinks()) {
654                 BrokenReferencesSupport.showAlert();
655             }
656         }
657         
658         protected void projectClosed() {
659             
660             // unregister j2ee platform classpath change listener
661
String JavaDoc servInstID = getProperty(AntProjectHelper.PRIVATE_PROPERTIES_PATH, AppClientProjectProperties.J2EE_SERVER_INSTANCE);
662             J2eePlatform platform = Deployment.getDefault().getJ2eePlatform(servInstID);
663             if (platform != null) {
664                 unregisterJ2eePlatformListener(platform);
665             }
666             
667             // remove file change listener from jax-ws.xml
668
if (jaxWsFo!=null) {
669                 jaxWsFo.removeFileChangeListener(jaxWsListener);
670             }
671
672             // Probably unnecessary, but just in case:
673
try {
674                 ProjectManager.getDefault().saveProject(AppClientProject.this);
675             } catch (IOException JavaDoc e) {
676                 ErrorManager.getDefault().notify(e);
677             }
678             
679             // unregister project's classpaths to GlobalPathRegistry
680
ClassPathProviderImpl cpProvider = (ClassPathProviderImpl)lookup.lookup(ClassPathProviderImpl.class);
681             GlobalPathRegistry.getDefault().unregister(ClassPath.BOOT, cpProvider.getProjectClassPaths(ClassPath.BOOT));
682             GlobalPathRegistry.getDefault().unregister(ClassPath.SOURCE, cpProvider.getProjectClassPaths(ClassPath.SOURCE));
683             GlobalPathRegistry.getDefault().unregister(ClassPath.COMPILE, cpProvider.getProjectClassPaths(ClassPath.COMPILE));
684             if (mainClassUpdater != null) {
685                 mainClassUpdater.unregister();
686                 mainClassUpdater = null;
687             }
688         }
689         
690     }
691     
692     public WebServicesClientSupport getAPIWebServicesClientSupport() {
693         return apiWebServicesClientSupport;
694     }
695
696     public JAXWSClientSupport getAPIJAXWSClientSupport() {
697         return apiJAXWSClientSupport;
698     }
699     
700     
701     /** copy jax-ws.xml from resource to nbproject directory,
702      * generate JaxWsModel,
703      * add FileChangeListener to jax-ws.xml file object
704      */

705     public void createJaxWsFileObject() throws IOException JavaDoc {
706         FileObject projectDir = helper.getProjectDirectory();
707         WSUtils.retrieveJaxWsFromResource(projectDir);
708         
709         jaxWsFo = findJaxWsFileObject(projectDir);
710         if (jaxWsFo!=null) {
711             jaxWsListener = new JaxWsListener();
712             jaxWsFo.addFileChangeListener(jaxWsListener);
713          
714             if (jaxWsModel!=null) {
715                 jaxWsModel.setJaxWsFile(jaxWsFo);
716             } else {
717                 jaxWsModel = JaxWsModelProvider.getDefault().getJaxWsModel(jaxWsFo);
718             }
719         }
720     }
721     
722     private JaxWsModel getJaxWsModel() {
723         if (jaxWsModel==null)
724             try {
725                 final FileObject projectDir = helper.getProjectDirectory();
726                 jaxWsFo = findJaxWsFileObject(projectDir);
727                 if (jaxWsFo==null) {
728                     // create jaxWsModel from the resource
729
jaxWsModel = JaxWsModelProvider.getDefault().getJaxWsModel(
730                             WSUtils.class.getResourceAsStream("/org/netbeans/modules/websvc/jaxwsmodel/resources/jax-ws.xml"));//NOI18N
731
jaxWsModel.setJaxWsFile(projectDir);
732                 } else {
733                     jaxWsListener = new JaxWsListener();
734                     try {
735                         jaxWsModel = JaxWsModelProvider.getDefault().getJaxWsModel(jaxWsFo);
736                         jaxWsFo.addFileChangeListener(jaxWsListener);
737                     } catch (RuntimeException JavaDoc ex) {
738                         // create jaxWsModel from the resource
739
jaxWsModel = JaxWsModelProvider.getDefault().getJaxWsModel(
740                                 WSUtils.class.getResourceAsStream("/org/netbeans/modules/websvc/jaxwsmodel/resources/jax-ws.xml"));//NOI18N
741
jaxWsModel.setJaxWsFile(projectDir);
742                         final FileObject oldJaxWsFo = jaxWsFo;
743                         jaxWsFo=null;
744                         final RuntimeException JavaDoc exception = ex;
745                         RequestProcessor.getDefault().post(new Runnable JavaDoc() {
746                             public void run() {
747                                 try {
748                                     jaxWsFo = WSUtils.backupAndGenerateJaxWs(projectDir, oldJaxWsFo, exception);
749                                     if (jaxWsFo!=null) {
750                                         jaxWsModel.setJaxWsFile(jaxWsFo);
751                                         jaxWsFo.addFileChangeListener(jaxWsListener);
752                                     }
753                                 } catch (IOException JavaDoc ex) {
754                                     ErrorManager.getDefault().log(ex.getLocalizedMessage());
755                                 }
756                             }
757                         });
758                     }
759                 }
760             } catch (IOException JavaDoc ex) {
761                 ErrorManager.getDefault().log(ex.getLocalizedMessage());
762             }
763         return jaxWsModel;
764     }
765
766     public FileObject findJaxWsFileObject() {
767         return findJaxWsFileObject(helper.getProjectDirectory());
768     }
769     
770     private FileObject findJaxWsFileObject(FileObject projectDir) {
771         return projectDir.getFileObject(GeneratedFilesHelper.JAX_WS_XML_PATH);
772     }
773     
774     /**
775      * Exports the main JAR as an official build product for use from other scripts.
776      * The type of the artifact will be {@link AntArtifact#TYPE_JAR}.
777      */

778     private final class AntArtifactProviderImpl implements AntArtifactProvider {
779         
780         public AntArtifact[] getBuildArtifacts() {
781             return new AntArtifact[] {
782                 helper.createSimpleAntArtifact(JavaProjectConstants.ARTIFACT_TYPE_JAR, "dist.jar", helper.getStandardPropertyEvaluator(), "dist", "clean"), // NOI18N
783
//new CarAntArtifact(helper.createSimpleAntArtifact(AppClientProjectConstants.ARTIFACT_TYPE_CAR, "dist.jar", helper.getStandardPropertyEvaluator(), "dist", "clean")), // NOI18N
784
new CarAntArtifact(helper.createSimpleAntArtifact(AppClientProjectConstants.ARTIFACT_TYPE_J2EE_MODULE_IN_EAR_ARCHIVE, "dist.ear.jar", helper.getStandardPropertyEvaluator(), "dist-ear", "clean-ear")) // NOI18N
785
};
786         }
787         
788     }
789     
790     private static final class RecommendedTemplatesImpl implements RecommendedTemplates, PrivilegedTemplates {
791         
792         RecommendedTemplatesImpl(UpdateHelper helper) {
793             this.helper = helper;
794         }
795         
796         transient private final UpdateHelper helper;
797         transient private boolean isArchive = false;
798         
799         // List of primarily supported templates
800

801         private static final String JavaDoc[] APPLICATION_TYPES = new String JavaDoc[] {
802             "java-classes", // NOI18N
803
"java-main-class", // NOI18N
804
"j2ee-types", // NOI18N
805
"java-forms", // NOI18N
806
"gui-java-application", // NOI18N
807
"java-beans", // NOI18N
808
"persistence", // NOI18N
809
"oasis-XML-catalogs", // NOI18N
810
"XML", // NOI18N
811
"ant-script", // NOI18N
812
"ant-task", // NOI18N
813
"web-service-clients", // NOI18N
814
"wsdl", // NOI18N
815
"sunresource-types", // NOI18N
816
// "web-types", // NOI18N
817
"junit", // NOI18N
818
// "MIDP", // NOI18N
819
"simple-files" // NOI18N
820
};
821
822         private static final String JavaDoc[] PRIVILEGED_NAMES = new String JavaDoc[] {
823             "Templates/Classes/Class.java", // NOI18N
824
"Templates/Classes/Package", // NOI18N
825
"Templates/Classes/Interface.java", // NOI18N
826
"Templates/GUIForms/JPanel.java", // NOI18N
827
"Templates/GUIForms/JFrame.java", // NOI18N
828
"Templates/J2EE/CachingServiceLocator.java", //NOI18N
829
"Templates/WebServices/WebServiceClient" // NOI18N
830
};
831         
832         private static final String JavaDoc[] APPLICATION_TYPES_ARCHIVE = new String JavaDoc[] {
833             "deployment-descriptor", // NOI18N
834
"XML", // NOI18N
835
};
836         
837         private static final String JavaDoc[] PRIVILEGED_NAMES_ARCHIVE = new String JavaDoc[] {
838             "Templates/J2EE/applicationClientXml," // NOI18N
839
};
840
841         public String JavaDoc[] getRecommendedTypes() {
842             String JavaDoc[] retVal = null;
843             checkEnvironment();
844             if (isArchive) {
845                 retVal = APPLICATION_TYPES_ARCHIVE.clone();
846             } else {
847                 retVal = APPLICATION_TYPES.clone();
848             }
849             return retVal;
850         }
851         
852         public String JavaDoc[] getPrivilegedTemplates() {
853             String JavaDoc[] retVal = null;
854             checkEnvironment();
855             if (isArchive) {
856                 retVal = PRIVILEGED_NAMES_ARCHIVE.clone();
857             } else {
858                 retVal = PRIVILEGED_NAMES.clone();
859             }
860             return retVal;
861         }
862
863         transient private boolean checked = false;
864         
865         private void checkEnvironment() {
866             if (!checked) {
867                 final Object JavaDoc srcType = helper.getAntProjectHelper().
868                         getStandardPropertyEvaluator().getProperty(AppClientProjectProperties.JAVA_SOURCE_BASED);
869                 if ("false".equals(srcType)) {
870                     isArchive = true;
871                 }
872                 checked = true;
873             }
874         }
875         
876     }
877
878     private final class CarAntArtifact extends AntArtifact {
879     
880         private final AntArtifact impl;
881     
882         CarAntArtifact(AntArtifact aa) {
883             impl = aa;
884         }
885     
886         public String JavaDoc getID() {
887             if (AppClientProjectConstants.ARTIFACT_TYPE_J2EE_MODULE_IN_EAR_ARCHIVE.equals(getType())) {
888                 return AppClientProjectConstants.CAR_ANT_ARTIFACT_ID;
889             }
890             return impl.getID();
891         }
892
893         public String JavaDoc getType() {
894             return impl.getType();
895         }
896
897         public String JavaDoc getTargetName() {
898             return impl.getTargetName();
899         }
900
901         public File JavaDoc getScriptLocation() {
902             return impl.getScriptLocation();
903         }
904
905         public String JavaDoc getCleanTargetName() {
906             return impl.getCleanTargetName();
907         }
908
909         public URI JavaDoc[] getArtifactLocations() {
910             return impl.getArtifactLocations();
911         }
912     
913         public Project getProject() {
914             return impl.getProject();
915         }
916     
917     }
918     
919     private class JaxWsListener extends FileChangeAdapter {
920         public void fileChanged(FileEvent fe) {
921             try {
922                 final JaxWsModel newModel = JaxWsModelProvider.getDefault().getJaxWsModel(fe.getFile());
923                 RequestProcessor.getDefault().post(new Runnable JavaDoc() {
924                     public void run() {
925                         if (jaxWsModel!=null && newModel!=null) {
926                             jaxWsModel.merge(newModel);
927                         }
928                         try {
929                             genFilesHelper.refreshBuildScript(
930                             GeneratedFilesHelper.BUILD_IMPL_XML_PATH,
931                             AppClientProject.class.getResource("resources/build-impl.xsl"), //NOI18N
932
jaxWsFo, false);
933                         } catch (IOException JavaDoc ex) {}
934                     }
935                     
936                 });
937                 
938             } catch (IOException JavaDoc ex) {}
939         }
940     }
941     
942 }
943
944
Popular Tags