KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > ejbjarproject > EjbJarProject


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.ejbjarproject;
21
22 import java.awt.Dialog JavaDoc;
23 import java.beans.PropertyChangeEvent JavaDoc;
24 import java.beans.PropertyChangeListener JavaDoc;
25 import java.beans.PropertyChangeSupport JavaDoc;
26 import java.io.IOException JavaDoc;
27 import java.util.*;
28 import javax.swing.Icon JavaDoc;
29 import javax.swing.ImageIcon JavaDoc;
30 import javax.swing.JButton JavaDoc;
31 import javax.swing.SwingUtilities 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.FileOwnerQuery;
36 import org.netbeans.api.project.Project;
37 import org.netbeans.api.project.ProjectManager;
38 import org.netbeans.api.project.ant.AntArtifact;
39 import org.netbeans.modules.j2ee.api.ejbjar.EjbJar;
40 import org.netbeans.modules.j2ee.api.ejbjar.EjbProjectConstants;
41 import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule;
42 import org.netbeans.modules.j2ee.ejbjarproject.classpath.ClassPathSupport;
43 import org.netbeans.modules.j2ee.ejbjarproject.classpath.ClassPathProviderImpl;
44 import org.netbeans.modules.j2ee.ejbjarproject.classpath.EjbJarProjectClassPathExtender;
45 import org.netbeans.modules.j2ee.ejbjarproject.jaxws.EjbJAXWSMetadataFinder;
46 import org.netbeans.modules.j2ee.ejbjarproject.jaxws.EjbProjectJAXWSClientSupport;
47 import org.netbeans.modules.j2ee.ejbjarproject.jaxws.EjbProjectJAXWSSupport;
48 import org.netbeans.modules.j2ee.ejbjarproject.queries.CompiledSourceForBinaryQuery;
49 import org.netbeans.modules.j2ee.ejbjarproject.queries.JavadocForBinaryQueryImpl;
50 import org.netbeans.modules.j2ee.ejbjarproject.queries.UnitTestForSourceQueryImpl;
51 import org.netbeans.modules.j2ee.ejbjarproject.ui.EjbJarLogicalViewProvider;
52 import org.netbeans.modules.j2ee.ejbjarproject.ui.customizer.EjbJarProjectProperties;
53 import org.netbeans.api.project.ProjectInformation;
54 import org.netbeans.modules.j2ee.common.ui.BrokenServerSupport;
55 import org.netbeans.modules.j2ee.spi.ejbjar.EjbJarFactory;
56 import org.netbeans.modules.j2ee.spi.ejbjar.support.EjbEnterpriseReferenceContainerSupport;
57 import org.netbeans.modules.websvc.api.jaxws.client.JAXWSClientSupport;
58 import org.netbeans.modules.websvc.api.jaxws.project.WSUtils;
59 import org.netbeans.modules.websvc.jaxws.api.JAXWSSupport;
60 import org.netbeans.modules.websvc.api.jaxws.project.config.JaxWsModel;
61 import org.netbeans.modules.websvc.api.jaxws.project.config.JaxWsModelProvider;
62 import org.netbeans.modules.websvc.api.jaxws.project.GeneratedFilesHelper;
63 import org.netbeans.modules.websvc.jaxws.spi.JAXWSSupportFactory;
64 import org.netbeans.modules.websvc.spi.client.WebServicesClientSupportFactory;
65 import org.netbeans.modules.websvc.spi.jaxws.client.JAXWSClientSupportFactory;
66 import org.netbeans.spi.project.SubprojectProvider;
67 import org.netbeans.spi.project.ant.AntArtifactProvider;
68 import org.netbeans.spi.project.support.ant.AntProjectEvent;
69 import org.netbeans.spi.project.support.ant.AntProjectHelper;
70 import org.netbeans.spi.project.support.ant.AntProjectListener;
71 import org.netbeans.spi.project.support.ant.ProjectXmlSavedHook;
72 import org.netbeans.spi.project.ui.PrivilegedTemplates;
73 import org.netbeans.spi.project.ui.RecommendedTemplates;
74 import org.netbeans.spi.project.support.ant.ReferenceHelper;
75 import org.netbeans.spi.project.support.ant.PropertyEvaluator;
76 import org.netbeans.spi.project.support.ant.SourcesHelper;
77 import org.netbeans.spi.project.ui.ProjectOpenedHook;
78 import org.openide.ErrorManager;
79 import org.openide.filesystems.FileChangeAdapter;
80 import org.openide.filesystems.FileChangeListener;
81 import org.openide.filesystems.FileEvent;
82 import org.openide.filesystems.FileObject;
83 import org.openide.filesystems.FileUtil;
84 import org.openide.loaders.DataObject;
85 import org.openide.util.Lookup;
86 import org.openide.util.Mutex;
87 import org.openide.util.RequestProcessor;
88 import org.openide.util.Utilities;
89 import org.openide.util.WeakListeners;
90 import org.openide.util.lookup.Lookups;
91 import org.netbeans.modules.j2ee.deployment.devmodules.api.Deployment;
92 import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eePlatform;
93 import org.netbeans.modules.j2ee.ejbjarproject.ui.BrokenReferencesAlertPanel;
94 import org.netbeans.modules.j2ee.ejbjarproject.ui.FoldersListSettings;
95 import org.netbeans.modules.j2ee.ejbjarproject.ui.customizer.CustomizerProviderImpl;
96 import org.netbeans.modules.j2ee.ejbjarproject.queries.SourceLevelQueryImpl;
97 import org.netbeans.spi.java.project.support.ui.BrokenReferencesSupport;
98 import org.netbeans.spi.project.AuxiliaryConfiguration;
99 import org.netbeans.spi.project.support.ant.EditableProperties;
100 import org.openide.DialogDescriptor;
101 import org.openide.DialogDisplayer;
102 import org.openide.util.NbBundle;
103 import org.w3c.dom.Document JavaDoc;
104 import org.w3c.dom.Comment JavaDoc;
105 import org.w3c.dom.Element JavaDoc;
106 import org.w3c.dom.Node JavaDoc;
107 import org.w3c.dom.NodeList JavaDoc;
108 import org.w3c.dom.Text JavaDoc;
109 import org.netbeans.modules.websvc.api.webservices.WebServicesSupport;
110 import org.netbeans.modules.websvc.api.client.WebServicesClientSupport;
111 import org.netbeans.modules.websvc.spi.webservices.WebServicesSupportFactory;
112 import org.netbeans.spi.project.support.LookupProviderSupport;
113 import org.netbeans.spi.project.ui.support.UILookupMergerSupport;
114 import org.openide.NotifyDescriptor;
115
116 /**
117  * Represents one ejb module project
118  * @author Chris Webster
119  */

120 public class EjbJarProject implements Project, AntProjectListener, FileChangeListener, PropertyChangeListener JavaDoc {
121     
122     private static final Icon JavaDoc PROJECT_ICON = new ImageIcon JavaDoc(Utilities.loadImage("org/netbeans/modules/j2ee/ejbjarproject/ui/resources/ejbjarProjectIcon.gif")); // NOI18N
123

124     private final AuxiliaryConfiguration aux;
125     private final AntProjectHelper helper;
126     private final PropertyEvaluator eval;
127     private final ReferenceHelper refHelper;
128     private FileObject libFolder = null;
129     private final GeneratedFilesHelper genFilesHelper;
130     private final Lookup lookup;
131     private final UpdateHelper updateHelper;
132     private final EjbJarProvider ejbModule;
133     private final EjbJar apiEjbJar;
134     private WebServicesSupport apiWebServicesSupport;
135     private JAXWSSupport apiJaxwsSupport;
136     private EjbProjectJAXWSSupport jaxwsSupport;
137     private WebServicesClientSupport apiWebServicesClientSupport;
138     private JAXWSClientSupport apiJAXWSClientSupport;
139     private EjbJarWebServicesSupport ejbJarWebServicesSupport;
140     private EjbJarWebServicesClientSupport ejbJarWebServicesClientSupport;
141     private EjbProjectJAXWSClientSupport jaxWsClientSupport;
142     private SourceRoots sourceRoots;
143     private SourceRoots testRoots;
144     private PropertyHelper propertyHelper;
145     private final EjbJarProjectClassPathExtender classpathExtender;
146     private PropertyChangeListener JavaDoc j2eePlatformListener;
147     private PropertyChangeListener JavaDoc evalListener;
148     private JaxWsModel jaxWsModel;
149     private JaxWsListener jaxWsListener;
150     private FileObject jaxWsFo;
151     private JaxWsModel.ServiceListener jaxWsServiceListener;
152     
153     // TODO: AB: replace the code in EjbJarProjectProperties.setNewServerInstanceValue with this
154
/*private String propJ2eeServerInstance;
155     private PropertyChangeListener evalListener = new PropertyChangeListener() {
156         
157         public void propertyChange(final PropertyChangeEvent evt) {
158             String propertyName = evt.getPropertyName();
159             if (propertyName == null || propertyName.equals(EjbJarProjectProperties.J2EE_SERVER_INSTANCE)) {
160                 org.openide.util.RequestProcessor.getDefault().post(new Runnable() {
161                     public void run() {
162                         ProjectManager.mutex().writeAccess(new Runnable() {
163                             public void run() {
164                                 // try to unregister the old J2EE platform
165                                 String oldJ2eeServerInstance = null;
166                                 if (propJ2eeServerInstance != null) {
167                                     oldJ2eeServerInstance = propJ2eeServerInstance;
168                                 } else {
169                                     oldJ2eeServerInstance = (String)evt.getOldValue();
170                                 }
171                                 if (oldJ2eeServerInstance != null) {
172                                     J2eePlatform oldJ2eePlatform = Deployment.getDefault().getJ2eePlatform(oldJ2eeServerInstance);
173                                     unregisterJ2eePlatformListener(oldJ2eePlatform);
174                                     propJ2eeServerInstance = null;
175                                 }
176
177                                 // now register the new platform
178                                 //String newJ2eeServerInstance = (String)evt.getNewValue();
179                                 EditableProperties props = helper.getProperties(AntProjectHelper.PRIVATE_PROPERTIES_PATH);
180                                 //if (newJ2eeServerInstance == null)
181                                 String newJ2eeServerInstance = props.getProperty(EjbJarProjectProperties.J2EE_SERVER_INSTANCE);
182
183                                 if (newJ2eeServerInstance != null) {
184                                     J2eePlatform newJ2eePlatform = Deployment.getDefault().getJ2eePlatform(newJ2eeServerInstance);
185                                     registerJ2eePlatformListener(newJ2eePlatform);
186                                     propJ2eeServerInstance = newJ2eeServerInstance;
187
188                                     putJ2eePlatformClassPath(newJ2eePlatform, props);
189                                     String serverType = Deployment.getDefault().getServerID(newJ2eeServerInstance);
190                                     props.setProperty(EjbJarProjectProperties.J2EE_SERVER_TYPE, serverType);
191                                     
192                                     // TODO: AB: should update wscompile classpath too
193
194                                     helper.putProperties(AntProjectHelper.PRIVATE_PROPERTIES_PATH, props);
195                                     try {
196                                         ProjectManager.getDefault().saveProject(EjbJarProject.this);
197                                     }
198                                     catch (IOException e) {
199                                         ErrorManager.getDefault().notify(e);
200                                     }
201                                 }
202                             }
203                         });
204                     }
205                 });
206             }
207         }
208     };*/

209     
210     EjbJarProject(final AntProjectHelper helper) throws IOException JavaDoc {
211         this.helper = helper;
212         eval = createEvaluator();
213         //eval.addPropertyChangeListener(evalListener);
214
aux = helper.createAuxiliaryConfiguration();
215         refHelper = new ReferenceHelper(helper, aux, helper.getStandardPropertyEvaluator());
216         genFilesHelper = new GeneratedFilesHelper(helper);
217         ejbModule = new EjbJarProvider(this, helper);
218         apiEjbJar = EjbJarFactory.createEjbJar(ejbModule);
219         ejbJarWebServicesSupport = new EjbJarWebServicesSupport(this, helper, refHelper);
220         jaxwsSupport = new EjbProjectJAXWSSupport(this, helper);
221         ejbJarWebServicesClientSupport = new EjbJarWebServicesClientSupport(this, helper, refHelper);
222         jaxWsClientSupport = new EjbProjectJAXWSClientSupport(this);
223         apiWebServicesSupport = WebServicesSupportFactory.createWebServicesSupport(ejbJarWebServicesSupport);
224         apiJaxwsSupport = JAXWSSupportFactory.createJAXWSSupport(jaxwsSupport);
225         apiWebServicesClientSupport = WebServicesClientSupportFactory.createWebServicesClientSupport(ejbJarWebServicesClientSupport);
226         apiJAXWSClientSupport = JAXWSClientSupportFactory.createJAXWSClientSupport(jaxWsClientSupport);
227         this.updateHelper = new UpdateHelper (this, this.helper, this.aux, this.genFilesHelper,
228             UpdateHelper.createDefaultNotifier());
229         classpathExtender = new EjbJarProjectClassPathExtender(this, updateHelper, evaluator(), refHelper);
230         lookup = createLookup(aux);
231         helper.addAntProjectListener(this);
232         ProjectManager.mutex().postWriteRequest(
233              new Runnable JavaDoc () {
234                  public void run() {
235                      try {
236                          updateProjectXML ();
237                      } catch (IOException JavaDoc ioe) {
238                          ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ioe);
239                      }
240                  }
241              }
242          );
243     }
244
245     /**
246      * Returns the project directory
247      * @return the directory the project is located in
248      */

249     public FileObject getProjectDirectory() {
250         return helper.getProjectDirectory();
251     }
252     
253     public String JavaDoc toString() {
254         return "EjbJarProject[" + getProjectDirectory() + "]"; // NOI18N
255
}
256     
257     private PropertyEvaluator createEvaluator() {
258         PropertyEvaluator eval = helper.getStandardPropertyEvaluator();
259         evalListener = WeakListeners.propertyChange(this, eval);
260         eval.addPropertyChangeListener(evalListener);
261         return eval;
262     }
263     
264     PropertyEvaluator evaluator() {
265         return eval;
266     }
267
268     public ReferenceHelper getReferenceHelper () {
269         return this.refHelper;
270     }
271     
272     public UpdateHelper getUpdateHelper() {
273         return updateHelper;
274     }
275
276     public Lookup getLookup() {
277         return lookup;
278     }
279     
280     public AntProjectHelper getAntProjectHelper() {
281         return helper;
282     }
283
284     private Lookup createLookup(AuxiliaryConfiguration aux) {
285         SubprojectProvider spp = refHelper.createSubprojectProvider();
286
287         final SourcesHelper sourcesHelper = new SourcesHelper(helper, evaluator());
288         String JavaDoc ejbModuleLabel = org.openide.util.NbBundle.getMessage(EjbJarLogicalViewProvider.class, "LBL_Node_EJBModule"); //NOI18N
289
String JavaDoc configFilesLabel = org.openide.util.NbBundle.getMessage(EjbJarLogicalViewProvider.class, "LBL_Node_DocBase"); //NOI18N
290

291         sourcesHelper.addPrincipalSourceRoot("${"+EjbJarProjectProperties.SOURCE_ROOT+"}", ejbModuleLabel, /*XXX*/null, null);
292         sourcesHelper.addPrincipalSourceRoot("${"+EjbJarProjectProperties.META_INF+"}", configFilesLabel, /*XXX*/null, null);
293         
294         ProjectManager.mutex().postWriteRequest(new Runnable JavaDoc() {
295             public void run() {
296                 sourcesHelper.registerExternalRoots(FileOwnerQuery.EXTERNAL_ALGORITHM_TRANSIENT);
297             }
298         });
299         Lookup base = Lookups.fixed(new Object JavaDoc[] {
300                 new Info(),
301                 aux,
302                 helper.createCacheDirectoryProvider(),
303                 new ProjectWebServicesSupportProvider(), // implementation of WebServicesClientSupportProvider commented out
304
spp,
305                 EjbEnterpriseReferenceContainerSupport.createEnterpriseReferenceContainer(this, helper),
306                 new ProjectEjbJarProvider(this),
307                 ejbModule, //implements J2eeModuleProvider
308
new EjbJarActionProvider( this, helper, refHelper ),
309                 new EjbJarLogicalViewProvider(this, updateHelper, evaluator(), spp, refHelper),
310                 new CustomizerProviderImpl( this, updateHelper, evaluator(), refHelper ),
311                 new ClassPathProviderImpl(helper, evaluator(), getSourceRoots(),getTestSourceRoots()),
312                 new CompiledSourceForBinaryQuery(helper,evaluator(),getSourceRoots(),getTestSourceRoots()),
313                 new JavadocForBinaryQueryImpl(helper, evaluator()),
314                 new AntArtifactProviderImpl(),
315                 new ProjectXmlSavedHookImpl(),
316                 new ProjectOpenedHookImpl(),
317                 new UnitTestForSourceQueryImpl(getSourceRoots(),getTestSourceRoots()),
318                 new SourceLevelQueryImpl(helper, evaluator()),
319                 new EjbJarSources (helper, evaluator(), getSourceRoots(), getTestSourceRoots()),
320                 new EjbJarSharabilityQuery(helper, evaluator(), getSourceRoots(), getTestSourceRoots()),
321                 new EjbJarFileBuiltQuery (helper, evaluator(),getSourceRoots(),getTestSourceRoots()),
322                 new RecommendedTemplatesImpl(updateHelper),
323                 refHelper,
324                 classpathExtender,
325                 new EjbJarProjectOperations(this),
326                 new EjbJarPersistenceProvider(this, evaluator()),
327                 new EjbJAXWSMetadataFinder(this),
328                 getJaxWsModel(),
329                 new EjbJarEMGenStrategyResolver(),
330                 new EjbJarJPASupport(this),
331                 new EjbJarServerStatusProvider(this),
332                 new EjbJarJPAModuleInfo(this),
333                 UILookupMergerSupport.createPrivilegedTemplatesMerger(),
334                 UILookupMergerSupport.createRecommendedTemplatesMerger(),
335                 LookupProviderSupport.createSourcesMerger()
336                 // TODO: AB: maybe add "this" to the lookup. You should not cast a Project to EjbJarProject, but use the lookup instead.
337
});
338             return LookupProviderSupport.createCompositeLookup(base, "Projects/org-netbeans-modules-j2ee-ejbjarproject/Lookup"); //NOI18N
339
}
340     
341     public void configurationXmlChanged(AntProjectEvent ev) {
342         if (ev.getPath().equals(AntProjectHelper.PROJECT_XML_PATH)) {
343             // Could be various kinds of changes, but name & displayName might have changed.
344
Info info = (Info)getLookup().lookup(ProjectInformation.class);
345             info.firePropertyChange(ProjectInformation.PROP_NAME);
346             info.firePropertyChange(ProjectInformation.PROP_DISPLAY_NAME);
347         }
348     }
349     
350     public void propertiesChanged(AntProjectEvent ev) {
351         // currently ignored
352
//TODO: should not be ignored!
353
}
354     
355     String JavaDoc getBuildXmlName() {
356         String JavaDoc storedName = helper.getStandardPropertyEvaluator().getProperty(EjbJarProjectProperties.BUILD_FILE);
357         return storedName == null ? GeneratedFilesHelper.BUILD_XML_PATH : storedName;
358     }
359     
360     // Package private methods -------------------------------------------------
361

362     /**
363      * Returns the source roots of this project
364      * @return project's source roots
365      */

366     public synchronized SourceRoots getSourceRoots() {
367         if (this.sourceRoots == null) { //Local caching, no project metadata access
368
this.sourceRoots = new SourceRoots(this.updateHelper, evaluator(), getReferenceHelper(), "source-roots", false, "src.{0}{1}.dir"); //NOI18N
369
}
370         return this.sourceRoots;
371     }
372     
373     public synchronized SourceRoots getTestSourceRoots() {
374         if (this.testRoots == null) { //Local caching, no project metadata access
375
this.testRoots = new SourceRoots(this.updateHelper, evaluator(), getReferenceHelper(), "test-roots", true, "test.{0}{1}.dir"); //NOI18N
376
}
377         return this.testRoots;
378     }
379
380     
381     
382     WebServicesSupport getAPIWebServicesSupport() {
383         return apiWebServicesSupport;
384     }
385
386     JAXWSSupport getAPIJAXWSSupport () {
387             return apiJaxwsSupport;
388     }
389     
390     WebServicesClientSupport getAPIWebServicesClientSupport () {
391         return apiWebServicesClientSupport;
392     }
393     
394     JAXWSClientSupport getAPIJAXWSClientSupport () {
395             return apiJAXWSClientSupport;
396     }
397     
398     /*public EjbJarProjectProperties getEjbJarProjectProperties() {
399         return new EjbJarProjectProperties (this, helper, refHelper);
400     }*/

401     
402     public PropertyHelper getPropertyHelper() {
403         if (propertyHelper == null) {
404             this.propertyHelper = new PropertyHelper(this, this.updateHelper);
405         }
406         return this.propertyHelper;
407     }
408     
409     public EjbJarProvider getEjbModule() {
410         return ejbModule;
411     }
412     
413     public EjbJar getAPIEjbJar() {
414         return apiEjbJar;
415     }
416     
417     /** Last time in ms when the Broken References alert was shown. */
418     private static long brokenAlertLastTime = 0;
419     
420     /** Is Broken References alert shown now? */
421     private static boolean brokenAlertShown = false;
422     
423     /** Timeout within which request to show alert will be ignored. */
424     private static int BROKEN_ALERT_TIMEOUT = 1000;
425     
426     private static synchronized void showBrokenReferencesAlert() {
427         // Do not show alert if it is already shown or if it was shown
428
// in last BROKEN_ALERT_TIMEOUT milliseconds or if user do not wish it.
429
if (brokenAlertShown ||
430         brokenAlertLastTime+BROKEN_ALERT_TIMEOUT > System.currentTimeMillis() ||
431         !FoldersListSettings.getDefault().isShowAgainBrokenRefAlert()) {
432             return;
433         }
434         brokenAlertShown = true;
435         SwingUtilities.invokeLater(new Runnable JavaDoc() {
436             public void run() {
437                 try {
438                     Object JavaDoc ok = NbBundle.getMessage(BrokenReferencesAlertPanel.class,"MSG_Broken_References_OK");
439                     DialogDescriptor dd = new DialogDescriptor(new BrokenReferencesAlertPanel(),
440                     NbBundle.getMessage(BrokenReferencesAlertPanel.class, "MSG_Broken_References_Title"),
441                     true, new Object JavaDoc[] {ok}, ok, DialogDescriptor.DEFAULT_ALIGN, null, null);
442                     Dialog JavaDoc dlg = null;
443                     try {
444                         dlg = DialogDisplayer.getDefault().createDialog(dd);
445                         dlg.setVisible(true);
446                     } finally {
447                         if (dlg != null)
448                             dlg.dispose();
449                     }
450                 } finally {
451                     synchronized (EjbJarProject.class) {
452                         brokenAlertLastTime = System.currentTimeMillis();
453                         brokenAlertShown = false;
454                     }
455                 }
456             }
457         });
458     }
459     
460     /** Return configured project name. */
461     public String JavaDoc getName() {
462         return (String JavaDoc) ProjectManager.mutex().readAccess(new Mutex.Action() {
463             public Object JavaDoc run() {
464                 Element JavaDoc data = updateHelper.getPrimaryConfigurationData(true);
465                 // XXX replace by XMLUtil when that has findElement, findText, etc.
466
NodeList JavaDoc nl = data.getElementsByTagNameNS(EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE, "name");
467                 if (nl.getLength() == 1) {
468                     nl = nl.item(0).getChildNodes();
469                     if (nl.getLength() == 1 && nl.item(0).getNodeType() == Node.TEXT_NODE) {
470                         return ((Text JavaDoc) nl.item(0)).getNodeValue();
471                     }
472                 }
473                 return "EJB???"; // NOI18N
474
}
475         });
476     }
477
478     /** Store configured project name. */
479     public void setName(final String JavaDoc name) {
480         ProjectManager.mutex().writeAccess(new Mutex.Action() {
481             public Object JavaDoc run() {
482                 Element JavaDoc data = helper.getPrimaryConfigurationData(true);
483                 // XXX replace by XMLUtil when that has findElement, findText, etc.
484
NodeList JavaDoc nl = data.getElementsByTagNameNS(EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE, "name");
485                 Element JavaDoc nameEl;
486                 if (nl.getLength() == 1) {
487                     nameEl = (Element JavaDoc) nl.item(0);
488                     NodeList JavaDoc deadKids = nameEl.getChildNodes();
489                     while (deadKids.getLength() > 0) {
490                         nameEl.removeChild(deadKids.item(0));
491                     }
492                 } else {
493                     nameEl = data.getOwnerDocument().createElementNS(EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE, "name");
494                     data.insertBefore(nameEl, /* OK if null */data.getChildNodes().item(0));
495                 }
496                 nameEl.appendChild(data.getOwnerDocument().createTextNode(name));
497                 helper.putPrimaryConfigurationData(data, true);
498                 return null;
499             }
500         });
501     }
502
503     private void updateProjectXML () throws IOException JavaDoc {
504         Element JavaDoc element = aux.getConfigurationFragment("data","http://www.netbeans.org/ns/EjbJar-project/1",true); //NOI18N
505
if (element != null) {
506             Document JavaDoc doc = element.getOwnerDocument();
507             Element JavaDoc newRoot = doc.createElementNS (EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE,"data"); //NOI18N
508
copyDocument (doc, element, newRoot);
509             Element JavaDoc sourceRoots = doc.createElementNS(EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE,"source-roots"); //NOI18N
510
Element JavaDoc root = doc.createElementNS (EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE,"root"); //NOI18N
511
root.setAttribute ("id","src.dir"); //NOI18N
512
sourceRoots.appendChild(root);
513             newRoot.appendChild (sourceRoots);
514             Element JavaDoc testRoots = doc.createElementNS(EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE,"test-roots"); //NOI18N
515
root = doc.createElementNS (EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE,"root"); //NOI18N
516
root.setAttribute ("id","test.src.dir"); //NOI18N
517
testRoots.appendChild (root);
518             newRoot.appendChild (testRoots);
519             helper.putPrimaryConfigurationData (newRoot, true);
520             ProjectManager.getDefault().saveProject(this);
521         }
522     }
523
524     private static void copyDocument (Document JavaDoc doc, Element JavaDoc from, Element JavaDoc to) {
525         NodeList JavaDoc nl = from.getChildNodes();
526         int length = nl.getLength();
527         for (int i=0; i< length; i++) {
528             Node JavaDoc node = nl.item (i);
529             Node JavaDoc newNode = null;
530             switch (node.getNodeType()) {
531                 case Node.ELEMENT_NODE:
532                     Element JavaDoc oldElement = (Element JavaDoc) node;
533                     newNode = doc.createElementNS(EjbJarProjectType.PROJECT_CONFIGURATION_NAMESPACE,oldElement.getTagName());
534                     copyDocument(doc,oldElement,(Element JavaDoc)newNode);
535                     break;
536                 case Node.TEXT_NODE:
537                     Text JavaDoc oldText = (Text JavaDoc) node;
538                     newNode = doc.createTextNode(oldText.getData());
539                     break;
540                 case Node.COMMENT_NODE:
541                     Comment JavaDoc oldComment = (Comment JavaDoc) node;
542                     newNode = doc.createComment(oldComment.getData());
543                     break;
544             }
545             if (newNode != null) {
546                 to.appendChild (newNode);
547             }
548         }
549     }
550
551     public void fileAttributeChanged (org.openide.filesystems.FileAttributeEvent fe) {
552     }
553     
554     public void fileChanged (org.openide.filesystems.FileEvent fe) {
555     }
556     
557     public void fileDataCreated (org.openide.filesystems.FileEvent fe) {
558         FileObject fo = fe.getFile ();
559         checkLibraryFolder (fo);
560     }
561     
562     public void fileDeleted (org.openide.filesystems.FileEvent fe) {
563     }
564     
565     public void registerJ2eePlatformListener(final J2eePlatform platform) {
566         // listen to classpath changes
567
j2eePlatformListener = new PropertyChangeListener JavaDoc() {
568             public void propertyChange(PropertyChangeEvent JavaDoc evt) {
569                 if (evt.getPropertyName().equals(J2eePlatform.PROP_CLASSPATH)) {
570                     ProjectManager.mutex().writeAccess(new Mutex.Action() {
571                         public Object JavaDoc run() {
572                             EditableProperties ep = helper.getProperties(AntProjectHelper.PRIVATE_PROPERTIES_PATH);
573                             String JavaDoc classpath = Utils.toClasspathString(platform.getClasspathEntries());
574                             ep.setProperty(EjbJarProjectProperties.J2EE_PLATFORM_CLASSPATH, classpath);
575                             helper.putProperties(AntProjectHelper.PRIVATE_PROPERTIES_PATH, ep);
576                             try {
577                                 ProjectManager.getDefault().saveProject(EjbJarProject.this);
578                             } catch (IOException JavaDoc e) {
579                                 ErrorManager.getDefault().notify(e);
580                             }
581                             return null;
582                         }
583                     });
584                 }
585             }
586         };
587         platform.addPropertyChangeListener(j2eePlatformListener);
588     }
589
590     public void unregisterJ2eePlatformListener(J2eePlatform platform) {
591         if (j2eePlatformListener != null) {
592             platform.removePropertyChangeListener(j2eePlatformListener);
593         }
594     }
595         
596     public void fileFolderCreated (org.openide.filesystems.FileEvent fe) {
597     }
598     
599     public void fileRenamed (org.openide.filesystems.FileRenameEvent fe) {
600         FileObject fo = fe.getFile ();
601         checkLibraryFolder (fo);
602     }
603
604     private void checkLibraryFolder (FileObject fo) {
605         if (!FileUtil.isArchiveFile(fo))
606             return;
607         
608         if (fo.getParent ().equals (libFolder)) {
609             try {
610                 classpathExtender.addArchiveFile(fo);
611             }
612             catch (IOException JavaDoc e) {
613                 ErrorManager.getDefault().notify(e);
614             }
615         }
616     }
617     
618     private String JavaDoc getProperty(String JavaDoc path, String JavaDoc name) {
619         return helper.getProperties(path).getProperty(name);
620     }
621     
622     /**
623      * Refreshes the build-impl.xml script. If it was modified by the user, it
624      * displays a confirmation dialog.
625      *
626      * @param askUserIfFlags only display the dialog if the state of the build script
627      * contains these flags (along with {@link GeneratedFilesHelper#FLAG_MODIFIED},
628      * which is always checked)
629      * @param askInCurrentThread if false, asks in another thread
630      * @param checkForProjectXmlModified true if it is necessary to check whether the
631      * script is out of date with respect to <code>project.xml</code> and/or the stylesheet
632      */

633     private void refreshBuildImplXml(int askUserIfFlags, boolean askInCurrentThread, boolean checkForProjectXmlModified) {
634         askUserIfFlags |= GeneratedFilesHelper.FLAG_MODIFIED;
635         int flags = genFilesHelper.getBuildScriptState(
636             GeneratedFilesHelper.BUILD_IMPL_XML_PATH,
637             EjbJarProject.class.getResource("resources/build-impl.xsl"), // NOI18N
638
jaxWsFo);
639         if ((flags & askUserIfFlags) == askUserIfFlags) {
640             Runnable JavaDoc run = new Runnable JavaDoc () {
641                 public void run () {
642                     JButton JavaDoc updateOption = new JButton JavaDoc (NbBundle.getMessage(EjbJarProject.class, "CTL_Regenerate"));
643                     if (DialogDisplayer.getDefault().notify(
644                         new NotifyDescriptor (NbBundle.getMessage(EjbJarProject.class,"TXT_BuildImplRegenerate"),
645                             NbBundle.getMessage(EjbJarProject.class,"TXT_BuildImplRegenerateTitle"),
646                             NotifyDescriptor.DEFAULT_OPTION,
647                             NotifyDescriptor.WARNING_MESSAGE,
648                             new Object JavaDoc[] {
649                                 updateOption,
650                                 NotifyDescriptor.CANCEL_OPTION
651                             },
652                             updateOption)) == updateOption) {
653                         try {
654                             genFilesHelper.generateBuildScriptFromStylesheet(
655                                 GeneratedFilesHelper.BUILD_IMPL_XML_PATH,
656                                 EjbJarProject.class.getResource("resources/build-impl.xsl"),jaxWsFo); // NOI18N
657
} catch (IOException JavaDoc e) {
658                             ErrorManager.getDefault().notify(e);
659                         } catch (IllegalStateException JavaDoc e) {
660                             ErrorManager.getDefault().notify(e);
661                         }
662                     }
663                 }
664             };
665             if (askInCurrentThread)
666                 run.run();
667             else
668                 RequestProcessor.getDefault().post(run);
669         } else {
670             try {
671                 genFilesHelper.refreshBuildScript(
672                     GeneratedFilesHelper.BUILD_IMPL_XML_PATH,
673                     EjbJarProject.class.getResource("resources/build-impl.xsl"), // NOI18N
674
jaxWsFo,
675                     checkForProjectXmlModified);
676             } catch (IOException JavaDoc e) {
677                 ErrorManager.getDefault().notify(e);
678             }
679         }
680     }
681
682     // Private innerclasses ----------------------------------------------------
683

684     private final class Info implements ProjectInformation {
685         
686         private final PropertyChangeSupport JavaDoc pcs = new PropertyChangeSupport JavaDoc(this);
687         
688         Info() {}
689         
690         void firePropertyChange(String JavaDoc prop) {
691             pcs.firePropertyChange(prop, null, null);
692         }
693         
694         public String JavaDoc getName() {
695             return EjbJarProject.this.getName();
696         }
697         
698         public String JavaDoc getDisplayName() {
699             return EjbJarProject.this.getName();
700         }
701         
702         public Icon JavaDoc getIcon() {
703             return PROJECT_ICON;
704         }
705         
706         public Project getProject() {
707             return EjbJarProject.this;
708         }
709         
710         public void addPropertyChangeListener(PropertyChangeListener JavaDoc listener) {
711             pcs.addPropertyChangeListener(listener);
712         }
713         
714         public void removePropertyChangeListener(PropertyChangeListener JavaDoc listener) {
715             pcs.removePropertyChangeListener(listener);
716         }
717         
718     }
719     
720     private final class ProjectXmlSavedHookImpl extends ProjectXmlSavedHook {
721         
722         ProjectXmlSavedHookImpl() {}
723         
724         protected void projectXmlSaved() throws IOException JavaDoc {
725             refreshBuildImplXml(0, false, false);
726             
727             genFilesHelper.refreshBuildScript(
728                 getBuildXmlName(),
729                 EjbJarProject.class.getResource("resources/build.xsl"),
730                 jaxWsFo,
731                 false);
732         }
733         
734     }
735
736     private final class ProjectOpenedHookImpl extends ProjectOpenedHook {
737         
738         ProjectOpenedHookImpl() {}
739         
740         protected void projectOpened() {
741             try {
742                 //Check libraries and add them to classpath automatically
743
String JavaDoc libFolderName = helper.getStandardPropertyEvaluator ().getProperty (EjbJarProjectProperties.LIBRARIES_DIR);
744                 //EjbJarProjectProperties ejbpp = getEjbJarProjectProperties();
745

746                 //DDDataObject initialization to be ready to listen on changes (#49656)
747
try {
748                     FileObject ddFO = ejbModule.getDeploymentDescriptor();
749                     if (ddFO != null) {
750                         DataObject.find(ddFO);
751                     }
752                 } catch (org.openide.loaders.DataObjectNotFoundException ex) {}
753                 
754                 if (libFolderName != null && helper.resolveFile (libFolderName).isDirectory ()) {
755                     libFolder = helper.resolveFileObject(libFolderName);
756                         FileObject children [] = libFolder.getChildren ();
757                         List JavaDoc libs = new LinkedList();
758                         for (int i = 0; i < children.length; i++) {
759                             if (FileUtil.isArchiveFile(children[i]))
760                                 libs.add(children[i]);
761                         }
762                         FileObject[] libsArray = new FileObject[libs.size()];
763                         libs.toArray(libsArray);
764                         classpathExtender.addArchiveFiles(EjbJarProjectProperties.JAVAC_CLASSPATH, libsArray, ClassPathSupport.ELEMENT_INCLUDED_LIBRARIES);
765                         libFolder.addFileChangeListener (EjbJarProject.this);
766                 }
767                 
768                 // Check up on build scripts.
769

770                  refreshBuildImplXml( GeneratedFilesHelper.FLAG_OLD_PROJECT_XML, true, true);
771                 
772                 genFilesHelper.refreshBuildScript(
773                     getBuildXmlName(),
774                     EjbJarProject.class.getResource("resources/build.xsl"),
775                     jaxWsFo,
776                     true);
777                 
778                 String JavaDoc servInstID = getProperty(AntProjectHelper.PRIVATE_PROPERTIES_PATH, EjbJarProjectProperties.J2EE_SERVER_INSTANCE);
779                 J2eePlatform platform = Deployment.getDefault().getJ2eePlatform(servInstID);
780                 if (platform != null) {
781                     // updates j2ee.platform.cp & wscompile.cp & reg. j2ee platform listener
782
EjbJarProjectProperties.setServerInstance(EjbJarProject.this, EjbJarProject.this.helper, servInstID);
783                 } else {
784                     // if there is some server instance of the type which was used
785
// previously do not ask and use it
786
String JavaDoc serverType = getProperty(AntProjectHelper.PROJECT_PROPERTIES_PATH, EjbJarProjectProperties.J2EE_SERVER_TYPE);
787                     if (serverType != null) {
788                         String JavaDoc[] servInstIDs = Deployment.getDefault().getInstancesOfServer(serverType);
789                         if (servInstIDs.length > 0) {
790                             EjbJarProjectProperties.setServerInstance(EjbJarProject.this, EjbJarProject.this.helper, servInstIDs[0]);
791                             platform = Deployment.getDefault().getJ2eePlatform(servInstIDs[0]);
792                         }
793                     }
794                     if (platform == null) {
795                         BrokenServerSupport.showAlert();
796                     }
797                 }
798             } catch (IOException JavaDoc e) {
799                 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
800             }
801             
802             // register project's classpaths to GlobalPathRegistry
803
ClassPathProviderImpl cpProvider = (ClassPathProviderImpl)lookup.lookup(ClassPathProviderImpl.class);
804             GlobalPathRegistry.getDefault().register(ClassPath.BOOT, cpProvider.getProjectClassPaths(ClassPath.BOOT));
805             GlobalPathRegistry.getDefault().register(ClassPath.SOURCE, cpProvider.getProjectClassPaths(ClassPath.SOURCE));
806             GlobalPathRegistry.getDefault().register(ClassPath.COMPILE, cpProvider.getProjectClassPaths(ClassPath.COMPILE));
807
808             // initialize the server configuration
809
// it MUST BE called AFTER classpaths are registered to GlobalPathRegistry!
810
// EJB DDProvider (used here) needs classpath set correctly when resolving Java Extents for annotations
811
ejbModule.getConfigSupport().ensureConfigurationReady();
812
813             // Make it easier to run headless builds on the same machine at least.
814
ProjectManager.mutex().writeAccess(new Mutex.Action() {
815                 public Object JavaDoc run() {
816                     EditableProperties ep = helper.getProperties(AntProjectHelper.PRIVATE_PROPERTIES_PATH);
817                     ep.setProperty("netbeans.user", System.getProperty("netbeans.user"));
818                     
819                     // set jaxws.endorsed.dir property (for endorsed mechanism to be used with wsimport, wsgen)
820
WSUtils.setJaxWsEndorsedDirProperty(ep);
821                     
822                     helper.putProperties(AntProjectHelper.PRIVATE_PROPERTIES_PATH, ep);
823                     try {
824                         ProjectManager.getDefault().saveProject(EjbJarProject.this);
825                     } catch (IOException JavaDoc e) {
826                         ErrorManager.getDefault().notify(e);
827                     }
828                     return null;
829                 }
830             });
831             EjbJarLogicalViewProvider physicalViewProvider = (EjbJarLogicalViewProvider)
832                 EjbJarProject.this.getLookup().lookup (EjbJarLogicalViewProvider.class);
833             if (physicalViewProvider != null && physicalViewProvider.hasBrokenLinks()) {
834                 BrokenReferencesSupport.showAlert();
835             }
836         }
837         
838         protected void projectClosed() {
839             
840             // unregister j2ee platform classpath change listener
841
/*EjbJarProjectProperties wpp = getEjbJarProjectProperties();
842             String servInstID = (String)wpp.get(EjbJarProjectProperties.J2EE_SERVER_INSTANCE);*/

843             String JavaDoc servInstID = getProperty(AntProjectHelper.PRIVATE_PROPERTIES_PATH, EjbJarProjectProperties.J2EE_SERVER_INSTANCE);
844             J2eePlatform platform = Deployment.getDefault().getJ2eePlatform(servInstID);
845             if (platform != null) {
846                 unregisterJ2eePlatformListener(platform);
847             }
848             
849             // unregister the property change listener on the prop evaluator
850
if (evalListener != null) {
851                 evaluator().removePropertyChangeListener(evalListener);
852             }
853             
854             // remove file change listener from jax-ws.xml
855
if (jaxWsFo!=null) jaxWsFo.removeFileChangeListener(jaxWsListener);
856             
857             // remove ServiceListener from jaxWsModel
858
if (jaxWsModel!=null) jaxWsModel.removeServiceListener(jaxWsServiceListener);
859             
860             // Probably unnecessary, but just in case:
861
try {
862                 ProjectManager.getDefault().saveProject(EjbJarProject.this);
863             } catch (IOException JavaDoc e) {
864                 ErrorManager.getDefault().notify(e);
865             }
866             
867             // unregister project's classpaths to GlobalPathRegistry
868
ClassPathProviderImpl cpProvider = (ClassPathProviderImpl)lookup.lookup(ClassPathProviderImpl.class);
869             GlobalPathRegistry.getDefault().unregister(ClassPath.BOOT, cpProvider.getProjectClassPaths(ClassPath.BOOT));
870             GlobalPathRegistry.getDefault().unregister(ClassPath.SOURCE, cpProvider.getProjectClassPaths(ClassPath.SOURCE));
871             GlobalPathRegistry.getDefault().unregister(ClassPath.COMPILE, cpProvider.getProjectClassPaths(ClassPath.COMPILE));
872         }
873         
874     }
875          
876     public void propertyChange(PropertyChangeEvent JavaDoc evt) {
877         if (evt.getPropertyName().equals(EjbJarProjectProperties.JAVAC_CLASSPATH)) {
878             ProjectManager.mutex().postWriteRequest(new Runnable JavaDoc () {
879                 public void run() {
880                     EditableProperties props = helper.getProperties (AntProjectHelper.PROJECT_PROPERTIES_PATH); //Reread the properties, PathParser changes them
881
//update lib references in private properties
882
EditableProperties privateProps = helper.getProperties(AntProjectHelper.PRIVATE_PROPERTIES_PATH);
883                     Iterator cpItems = classpathExtender.getClassPathSupport().itemsIterator(props.getProperty(EjbJarProjectProperties.JAVAC_CLASSPATH), ClassPathSupport.ELEMENT_INCLUDED_LIBRARIES);
884                     EjbJarProjectProperties.storeLibrariesLocations(cpItems, privateProps);
885                     helper.putProperties(AntProjectHelper.PRIVATE_PROPERTIES_PATH, privateProps);
886                 }
887             });
888         }
889     }
890     
891     /**
892      * Exports the main JAR as an official build product for use from other scripts.
893      * The type of the artifact will be {@link AntArtifact#TYPE_JAR}.
894      */

895     private final class AntArtifactProviderImpl implements AntArtifactProvider {
896         
897         public AntArtifact[] getBuildArtifacts() {
898             return new AntArtifact[] {
899                 helper.createSimpleAntArtifact(JavaProjectConstants.ARTIFACT_TYPE_JAR, "dist.jar", helper.getStandardPropertyEvaluator(), "dist", "clean"), // NOI18N
900
helper.createSimpleAntArtifact(EjbProjectConstants.ARTIFACT_TYPE_EJBJAR, "dist.jar", helper.getStandardPropertyEvaluator(), "dist", "clean"), // NOI18N
901
helper.createSimpleAntArtifact(EjbProjectConstants.ARTIFACT_TYPE_J2EE_MODULE_IN_EAR_ARCHIVE, "dist.ear.jar", helper.getStandardPropertyEvaluator(), "dist-ear", "clean-ear") // NOI18N
902
};
903         }
904     }
905     
906     // List of primarily supported templates
907
private static final String JavaDoc[] TYPES = new String JavaDoc[] {
908         "java-classes", // NOI18N
909
"ejb-types_2_1", // NOI18N
910
"ejb-types", // NOI18N
911
"ejb-types-server", // NOI18N
912
"web-services", // NOI18N
913
"wsdl", // NOI18N
914
"j2ee-14-types", // NOI18N
915
"j2ee-types", // NOI18N
916
"java-beans", // NOI18N
917
"java-main-class", // NOI18N
918
"persistence", // NOI18N
919
"oasis-XML-catalogs", // NOI18N
920
"XML", // NOI18N
921
"ant-script", // NOI18N
922
"ant-task", // NOI18N
923
"junit", // NOI18N
924
"simple-files" // NOI18N
925
};
926     
927     /**
928      * Supported template categories for Java EE 5 projects.
929      */

930     private static final String JavaDoc[] JAVAEE5_TYPES = new String JavaDoc[] {
931         "java-classes", // NOI18N
932
"ejb-types", // NOI18N
933
"ejb-types-server", // NOI18N
934
"ejb-types_3_0", // NOI18N
935
"web-services", // NOI18N
936
"web-service-clients", // NOI18N
937
"wsdl", // NOI18N
938
"j2ee-types", // NOI18N
939
"java-beans", // NOI18N
940
"java-main-class", // NOI18N
941
"persistence", // NOI18N
942
"oasis-XML-catalogs", // NOI18N
943
"XML", // NOI18N
944
"ant-script", // NOI18N
945
"ant-task", // NOI18N
946
"junit", // NOI18N
947
"simple-files" // NOI18N
948
};
949     
950     /**
951      * Supported template categories for archive projects.
952      */

953     private static final String JavaDoc[] ARCHIVE_TYPES = new String JavaDoc[] {
954         "ejb-deployment-descriptor", // NOI18N
955
"deployment-descriptor", // NOI18N
956
"XML", // NOI18N
957
};
958
959     private static final String JavaDoc[] PRIVILEGED_NAMES = new String JavaDoc[] {
960         "Templates/J2EE/Session", // NOI18N
961
"Templates/J2EE/Entity", // NOI18N
962
"Templates/J2EE/RelatedCMP", // NOI18N
963
"Templates/J2EE/Message", //NOI18N
964
"Templates/Classes/Class.java", // NOI18N
965
"Templates/Classes/Package", // NOI18N
966
"Templates/WebServices/WebService.java", // NOI18N
967
"Templates/WebServices/MessageHandler" // NOI18N
968
};
969     
970     private static final String JavaDoc[] PRIVILEGED_NAMES_EE5 = new String JavaDoc[] {
971         "Templates/J2EE/Session", // NOI18N
972
"Templates/J2EE/Message", // NOI18N
973
"Templates/Classes/Class.java", // NOI18N
974
"Templates/Classes/Package", // NOI18N
975
"Templates/Persistence/Entity.java", // NOI18N
976
"Templates/Persistence/RelatedCMP", // NOI18N
977
"Templates/WebServices/WebService.java", // NOI18N
978
"Templates/WebServices/WebServiceClient" // NOI18N
979
};
980     
981     private static final String JavaDoc[] PRIVILEGED_NAMES_ARCHIVE = new String JavaDoc[] {
982         "Templates/J2EE/ejbJarXml", // NOI18N
983
};
984
985     private final class RecommendedTemplatesImpl implements RecommendedTemplates, PrivilegedTemplates {
986         transient private boolean isEE5 = false;
987         transient private boolean checked = false;
988         transient private boolean isArchive = false;
989         transient private UpdateHelper helper = null;
990
991         RecommendedTemplatesImpl(UpdateHelper helper) {
992             this.helper = helper;
993         }
994
995         public String JavaDoc[] getRecommendedTypes() {
996             checkEnvironment();
997             String JavaDoc[] retVal = null;
998             if (isArchive) {
999                 retVal = ARCHIVE_TYPES;
1000            } else if (isEE5) {
1001                retVal = JAVAEE5_TYPES;
1002            } else {
1003                retVal = TYPES;
1004            }
1005            return retVal;
1006        }
1007        
1008        public String JavaDoc[] getPrivilegedTemplates() {
1009            checkEnvironment();
1010            String JavaDoc[] retVal = null;
1011            if (isArchive) {
1012                retVal = PRIVILEGED_NAMES_ARCHIVE;
1013            } else if (isEE5) {
1014                retVal = PRIVILEGED_NAMES_EE5;
1015            } else {
1016                retVal = PRIVILEGED_NAMES;
1017            }
1018            return retVal;
1019        }
1020        
1021        private void checkEnvironment(){
1022            if (!checked){
1023                isEE5 = J2eeModule.JAVA_EE_5.equals(getEjbModule().getJ2eePlatformVersion());
1024                final Object JavaDoc srcType = helper.getAntProjectHelper().
1025                        getStandardPropertyEvaluator().getProperty(EjbJarProjectProperties.JAVA_SOURCE_BASED);
1026                if ("false".equals(srcType)) {
1027                    isArchive = true;
1028                }
1029                checked = true;
1030            }
1031        }
1032    }
1033
1034    /** copy jax-ws.xml from resource to nbproject directory,
1035     * generate JaxWsModel,
1036     * add FileChangeListener to jax-ws.xml file object
1037     */

1038    public void createJaxWsFileObject() throws IOException JavaDoc {
1039        FileObject projectDir = helper.getProjectDirectory();
1040        WSUtils.retrieveJaxWsFromResource(projectDir);
1041        
1042        jaxWsFo = findJaxWsFileObject(projectDir);
1043        if (jaxWsFo!=null) {
1044            jaxWsListener = new JaxWsListener();
1045            jaxWsFo.addFileChangeListener(jaxWsListener);
1046         
1047            if (jaxWsModel!=null) {
1048                jaxWsModel.setJaxWsFile(jaxWsFo);
1049            } else {
1050                jaxWsModel = JaxWsModelProvider.getDefault().getJaxWsModel(jaxWsFo);
1051                if (jaxWsModel!=null) {
1052                    attachServiceListener(jaxWsModel);
1053                }
1054            }
1055        }
1056    }
1057    
1058    public FileObject findJaxWsFileObject() {
1059        return findJaxWsFileObject(helper.getProjectDirectory());
1060    }
1061    
1062    private FileObject findJaxWsFileObject(FileObject projectDir) {
1063        return projectDir.getFileObject(GeneratedFilesHelper.JAX_WS_XML_PATH);
1064    }
1065
1066    private JaxWsModel getJaxWsModel() {
1067        if (jaxWsModel==null)
1068            try {
1069                final FileObject projectDir = helper.getProjectDirectory();
1070                jaxWsFo = findJaxWsFileObject(projectDir);
1071                if (jaxWsFo==null) {
1072                    // create jaxWsModel from the resource
1073
jaxWsModel = JaxWsModelProvider.getDefault().getJaxWsModel(
1074                            WSUtils.class.getResourceAsStream("/org/netbeans/modules/websvc/jaxwsmodel/resources/jax-ws.xml"));//NOI18N
1075
jaxWsModel.setJaxWsFile(projectDir);
1076                } else {
1077                    jaxWsListener = new JaxWsListener();
1078                    try {
1079                        jaxWsModel = JaxWsModelProvider.getDefault().getJaxWsModel(jaxWsFo);
1080                        jaxWsFo.addFileChangeListener(jaxWsListener);
1081                    } catch (RuntimeException JavaDoc ex) {
1082                        // create jaxWsModel from the resource
1083
jaxWsModel = JaxWsModelProvider.getDefault().getJaxWsModel(
1084                                WSUtils.class.getResourceAsStream("/org/netbeans/modules/websvc/jaxwsmodel/resources/jax-ws.xml"));//NOI18N
1085
jaxWsModel.setJaxWsFile(projectDir);
1086                        final FileObject oldJaxWsFo = jaxWsFo;
1087                        jaxWsFo=null;
1088                        final RuntimeException JavaDoc exception = ex;
1089                        RequestProcessor.getDefault().post(new Runnable JavaDoc() {
1090                            public void run() {
1091                                try {
1092                                    jaxWsFo = WSUtils.backupAndGenerateJaxWs(projectDir, oldJaxWsFo, exception);
1093                                    if (jaxWsFo!=null) {
1094                                        jaxWsModel.setJaxWsFile(jaxWsFo);
1095                                        jaxWsFo.addFileChangeListener(jaxWsListener);
1096                                    }
1097                                } catch (IOException JavaDoc ex) {
1098                                    ErrorManager.getDefault().log(ex.getLocalizedMessage());
1099                                }
1100                            }
1101                        });
1102                    }
1103                }
1104                if (jaxWsModel!=null) {
1105                    attachServiceListener(jaxWsModel);
1106                }
1107            } catch (IOException JavaDoc ex) {
1108                ErrorManager.getDefault().log(ex.getLocalizedMessage());
1109            }
1110        return jaxWsModel;
1111    }
1112    
1113    private void attachServiceListener(JaxWsModel jaxWsModel) {
1114        jaxWsServiceListener = new JaxWsModel.ServiceListener() {
1115            public void serviceAdded(String JavaDoc name, String JavaDoc implementationClass) {
1116                getAPIJAXWSSupport().addService(name, implementationClass, isJsr109Supported());
1117            }
1118
1119            public void serviceRemoved(String JavaDoc name) {
1120                getAPIJAXWSSupport().serviceFromJavaRemoved(name);
1121            }
1122        };
1123        jaxWsModel.addServiceListener(jaxWsServiceListener);
1124    }
1125
1126    private boolean isJsr109Supported() {
1127        boolean jsr109Supported = true;
1128        String JavaDoc serverInstance = evaluator().getProperty(EjbJarProjectProperties.J2EE_SERVER_INSTANCE);
1129        if (serverInstance != null) {
1130            J2eePlatform j2eePlatform = Deployment.getDefault().getJ2eePlatform(serverInstance);
1131            if (j2eePlatform != null) {
1132                jsr109Supported = j2eePlatform.isToolSupported(J2eePlatform.TOOL_JSR109);
1133            }
1134        }
1135        return jsr109Supported;
1136    }
1137    
1138    private class JaxWsListener extends FileChangeAdapter {
1139        public void fileChanged(FileEvent fe) {
1140            try {
1141                final JaxWsModel newModel = JaxWsModelProvider.getDefault().getJaxWsModel(fe.getFile());
1142                RequestProcessor.getDefault().post(new Runnable JavaDoc() {
1143                    public void run() {
1144                        if (jaxWsModel!=null && newModel!=null) jaxWsModel.merge(newModel);
1145                        try {
1146                            genFilesHelper.refreshBuildScript(
1147                            GeneratedFilesHelper.BUILD_IMPL_XML_PATH,
1148                            EjbJarProject.class.getResource("resources/build-impl.xsl"),
1149                            jaxWsFo, false);
1150                        } catch (IOException JavaDoc ex) {}
1151                    }
1152                    
1153                });
1154                
1155            } catch (IOException JavaDoc ex) {}
1156        }
1157    }
1158}
1159
Popular Tags