KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > archive > project > ArchiveProject


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-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.j2ee.archive.project;
21
22 import java.beans.PropertyChangeListener JavaDoc;
23 import java.beans.PropertyChangeSupport JavaDoc;
24 import java.io.IOException JavaDoc;
25 import java.util.ArrayList JavaDoc;
26 import java.util.HashMap JavaDoc;
27 import java.util.Iterator JavaDoc;
28 import java.util.List JavaDoc;
29 import javax.swing.Icon JavaDoc;
30 import javax.swing.ImageIcon JavaDoc;
31 import org.netbeans.api.java.classpath.ClassPath;
32 import org.netbeans.api.java.classpath.GlobalPathRegistry;
33 import org.netbeans.api.project.Project;
34 import org.netbeans.api.project.ProjectInformation;
35 import org.netbeans.api.project.ProjectManager;
36 import org.netbeans.api.project.ant.AntArtifact;
37 import org.netbeans.modules.j2ee.archive.Util;
38 import org.netbeans.modules.j2ee.archive.customizer.ProvidesCustomizer;
39 import org.netbeans.modules.j2ee.common.ui.BrokenServerSupport;
40 import org.netbeans.modules.j2ee.dd.api.application.Application;
41 import org.netbeans.modules.j2ee.dd.api.application.Module;
42 import org.netbeans.modules.j2ee.dd.api.application.Web;
43 import org.netbeans.modules.j2ee.deployment.devmodules.api.Deployment;
44 import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule;
45 import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eePlatform;
46 import org.netbeans.modules.j2ee.deployment.devmodules.spi.J2eeModuleProvider;
47 import org.netbeans.modules.schema2beans.BaseBean;
48 import org.netbeans.modules.web.api.webmodule.WebProjectConstants;
49 import org.netbeans.spi.java.classpath.support.ClassPathSupport;
50 import org.netbeans.spi.project.AuxiliaryConfiguration;
51 import org.netbeans.spi.project.ant.AntArtifactProvider;
52 import org.netbeans.spi.project.support.ant.AntProjectHelper;
53 import org.netbeans.spi.project.support.ant.GeneratedFilesHelper;
54 import org.netbeans.spi.project.support.ant.PropertyEvaluator;
55 import org.netbeans.spi.project.ui.PrivilegedTemplates;
56 import org.netbeans.spi.project.ui.RecommendedTemplates;
57 import org.openide.ErrorManager;
58 import org.openide.filesystems.FileObject;
59 import org.openide.filesystems.FileUtil;
60 import org.openide.util.Lookup;
61 import org.openide.util.Mutex;
62 import org.openide.util.NbBundle;
63 import org.openide.util.Utilities;
64 import org.openide.util.lookup.Lookups;
65 import org.netbeans.spi.project.ui.ProjectOpenedHook;
66 import org.w3c.dom.Element JavaDoc;
67 import org.w3c.dom.Node JavaDoc;
68 import org.w3c.dom.NodeList JavaDoc;
69 import org.w3c.dom.Text JavaDoc;
70
71 public class ArchiveProject implements org.netbeans.api.project.Project {
72     
73     private final AuxiliaryConfiguration aux;
74     private final AntProjectHelper helper;
75     private final PropertyEvaluator eval;
76     private final GeneratedFilesHelper genFilesHelper;
77     private final Lookup lookup;
78     private ArchiveProjectProperties projProperties;
79     private static final Icon JavaDoc ARCHIVE_PROJECT_ICON = new ImageIcon JavaDoc(Utilities.loadImage("org/netbeans/modules/j2ee/archive/project/resources/application_assembler_16.gif")); // NOI18N
80
private final UpdateHelper updateHelper;
81     
82     private HashMap JavaDoc nameMap;
83     
84     public ArchiveProject(AntProjectHelper helper) {
85         this.helper = helper;
86         this.eval = helper.getStandardPropertyEvaluator();
87         aux = helper.createAuxiliaryConfiguration();
88         genFilesHelper = new GeneratedFilesHelper(helper);
89         lookup = new HelpfulLookup();
90         this.updateHelper = new UpdateHelper(this, this.helper, this.aux, this.genFilesHelper,
91                 UpdateHelper.createDefaultNotifier());
92         nameMap = new HashMap JavaDoc(5);
93     }
94     
95     public FileObject getProjectDirectory() {
96         return helper.getProjectDirectory();
97     }
98     
99     public AntProjectHelper getAntProjectHelper() {
100         return helper;
101     }
102     
103     public Lookup getLookup() {
104         return lookup;
105     }
106     
107     public PropertyEvaluator getPropertyEvaluator(){
108         return eval;
109         
110     }
111     
112     public String JavaDoc getProjectProperty(String JavaDoc propName){
113         
114         return (String JavaDoc) getArchiveProjectProperties().get(propName);
115     }
116     
117     public String JavaDoc getEarPath(String JavaDoc key) {
118         return (String JavaDoc) nameMap.get(key);
119     }
120     
121     public void setEarPath(String JavaDoc key, String JavaDoc val) {
122         nameMap.put(key,val);
123     }
124     
125     final private static String JavaDoc NAME_LIT = "name"; // NOI18N
126

127     /** Store configured project name. */
128     public void setName(final String JavaDoc name) {
129         ProjectManager.mutex().writeAccess(new Mutex.Action() {
130             public Object JavaDoc run() {
131                 Element JavaDoc data = helper.getPrimaryConfigurationData(true);
132                 // XXX replace by XMLUtil when that has findElement, findText, etc.
133
NodeList JavaDoc nl = data.getElementsByTagNameNS(ArchiveProjectType.PROJECT_CONFIGURATION_NS, NAME_LIT);
134                 Element JavaDoc nameEl;
135                 if (nl.getLength() == 1) {
136                     nameEl = (Element JavaDoc) nl.item(0);
137                     NodeList JavaDoc deadKids = nameEl.getChildNodes();
138                     while (deadKids.getLength() > 0) {
139                         nameEl.removeChild(deadKids.item(0));
140                     }
141                 } else {
142                     nameEl = data.getOwnerDocument().createElementNS(ArchiveProjectType.PROJECT_CONFIGURATION_NS, NAME_LIT);
143                     data.insertBefore(nameEl, /* OK if null */data.getChildNodes().item(0));
144                 }
145                 nameEl.appendChild(data.getOwnerDocument().createTextNode(name));
146                 helper.putPrimaryConfigurationData(data, true);
147                 return null;
148             }
149         });
150     }
151     
152     /** Return configured project name. */
153     public String JavaDoc getName() {
154         return (String JavaDoc) ProjectManager.mutex().readAccess(new Mutex.Action() {
155             public Object JavaDoc run() {
156                 Element JavaDoc data = updateHelper.getPrimaryConfigurationData(true);
157                 // XXX replace by XMLUtil when that has findElement, findText, etc.
158
NodeList JavaDoc nl = data.getElementsByTagNameNS(ArchiveProjectType.PROJECT_CONFIGURATION_NS, NAME_LIT);
159                 if (nl.getLength() == 1) {
160                     nl = nl.item(0).getChildNodes();
161                     if (nl.getLength() == 1 && nl.item(0).getNodeType() == Node.TEXT_NODE) {
162                         return ((Text JavaDoc) nl.item(0)).getNodeValue();
163                     }
164                 }
165                 return "BINARCHIVE???"; // NOI18N
166
}
167         });
168         
169     }
170     
171     public ArchiveProjectProperties getArchiveProjectProperties() {
172         projProperties= new ArchiveProjectProperties(this,getAntProjectHelper());
173         return projProperties ;
174     }
175     
176     // TODO automate the archive type discovery mechanism... see branch_ludo_changes_14_apr
177

178     // having a Lookup that can be noisy is very useful during project
179
// development
180
private final class HelpfulLookup extends Lookup {
181         
182         private boolean verbose = Boolean.getBoolean("archiveproject.lookup.verbose");
183         
184         Lookup inner = Lookups.fixed(new Object JavaDoc[] {
185             new Info(),
186             helper.createAuxiliaryConfiguration(),
187             helper.createCacheDirectoryProvider(),
188             helper.createGlobFileBuiltQuery(eval, new String JavaDoc[] {"${src.dir}/*.java"},
189                     new String JavaDoc[] {"${build.classes.dir}/*.class"}),
190             helper.createSharabilityQuery(eval, new String JavaDoc[] {"${src.dir}"},
191                     new String JavaDoc[] {"${build.dir}","${dist.dir}", "${proxy.project.dir}"}),
192             new OpenCloseHook(),
193             new ProvidesAction(ArchiveProject.this),
194             new ProvidesLogicalView(ArchiveProject.this),
195             helper,
196             new ProvidesJ2eeModule(helper, ArchiveProject.this),
197             new J2eeModuleForAddModuleAction(J2eeModule.EAR),
198             new MyAntProvider(),
199             new ProvidesCustomizer(ArchiveProject.this,helper),
200             new RecommendedTemplatesImpl(),
201             new ArchiveProjectOperations(ArchiveProject.this),
202             ArchiveProject.this,
203             new MyOpenHook(),
204             new ProjectXmlSaved(),
205             
206         });
207         public Object JavaDoc lookup(Class JavaDoc clazz) {
208             Object JavaDoc ret = inner.lookup(clazz);
209             if (verbose && null == ret && ErrorManager.getDefault().isNotifiable(ErrorManager.EXCEPTION)) {
210                 StackTraceElement JavaDoc[] sTEs = Thread.currentThread().getStackTrace();
211                 ErrorManager.getDefault().log(ErrorManager.EXCEPTION,
212                         NbBundle.getMessage(ArchiveProject.class,"LOOKUP_MISS",clazz.getName(),sTEs[3],sTEs[4]));
213             }
214             return ret;
215         }
216         
217         public Lookup.Result lookup(Lookup.Template template) {
218             Lookup.Result ret = inner.lookup(template);
219             if (verbose && null == ret && ErrorManager.getDefault().isNotifiable(ErrorManager.EXCEPTION)) {
220                 StackTraceElement JavaDoc[] sTEs = Thread.currentThread().getStackTrace();
221                 ErrorManager.getDefault().log(ErrorManager.EXCEPTION,
222                         NbBundle.getMessage(ArchiveProject.class,"LOOKUP_MISS",template.toString(),sTEs[3],sTEs[4]));
223             }
224             return ret;
225         }
226         
227         
228     }
229     
230     private final class Info implements ProjectInformation {
231         
232         private PropertyChangeSupport JavaDoc pcs = new PropertyChangeSupport JavaDoc(this);
233         
234         public String JavaDoc getName() {
235             return ArchiveProject.this.getNamedProjectAttribute(NAME_LIT);
236         }
237         
238         public String JavaDoc getDisplayName() {
239             return ArchiveProject.this.getNamedProjectAttribute(NAME_LIT);
240         }
241         
242         public Icon JavaDoc getIcon() {
243             return ARCHIVE_PROJECT_ICON;
244         }
245         
246         public Project getProject() {
247             return ArchiveProject.this;
248         }
249         
250         public void addPropertyChangeListener(PropertyChangeListener JavaDoc listener) {
251             pcs.addPropertyChangeListener(listener);
252         }
253         
254         public void removePropertyChangeListener(PropertyChangeListener JavaDoc listener) {
255             pcs.removePropertyChangeListener(listener);
256         }
257     }
258     
259     private final class MyAntProvider implements AntArtifactProvider {
260         // TODO - Need to fix for ejb-jar/app-client/resource-adapter cases
261
public AntArtifact[] getBuildArtifacts() {
262             return new AntArtifact[] {
263                 helper.createSimpleAntArtifact(WebProjectConstants.ARTIFACT_TYPE_WAR_EAR_ARCHIVE,
264                         "dist.archive", helper.getStandardPropertyEvaluator(), "dist",
265                         "clean")
266             };
267         }
268     }
269     
270     class OpenCloseHook extends ProjectOpenedHook {
271         
272         List JavaDoc<ClassPath[]> paths = new ArrayList JavaDoc<ClassPath[]>();
273         
274         protected void projectOpened() {
275             ProjectManager.mutex().writeAccess(new Mutex.Action() {
276                 public Object JavaDoc run() {
277                     doRegeneration();
278                     FileObject dir = helper.getProjectDirectory();
279                     FileObject subDir = null;
280                     ArchiveProjectProperties app = getArchiveProjectProperties();
281                     
282                     String JavaDoc type = (String JavaDoc) app.get(ArchiveProjectProperties.ARCHIVE_TYPE);
283                     boolean isEar = ArchiveProjectProperties.PROJECT_TYPE_VALUE_EAR.equals(type);
284                     subDir = dir.getFileObject(ArchiveProjectProperties.TMP_PROJ_DIR_VALUE);
285                     if (subDir != null) {
286                         Project tmpproj = null;
287                         try {
288                             tmpproj = ProjectManager.getDefault().findProject(subDir);
289                         } catch (IllegalArgumentException JavaDoc ex) {
290                             ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL, "" + ex);
291                         } catch (IOException JavaDoc ex) {
292                             ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL, "" + ex);
293                         }
294                         ProvidesJ2eeModule tmp = (ProvidesJ2eeModule) ArchiveProject.this.getLookup().lookup(ProvidesJ2eeModule.class);
295                         if (null!=tmpproj) {
296                             List JavaDoc<FileObject> roots = new ArrayList JavaDoc<FileObject>();
297                             FileObject cpe = tmpproj.getProjectDirectory().getFileObject("src/java");
298                             if (null != cpe) {
299                                 roots.add(cpe);
300                             }
301                             cpe = tmpproj.getProjectDirectory().getFileObject("src/conf");
302                             if (null != cpe) {
303                                 roots.add(cpe);
304                             }
305                             cpe = tmpproj.getProjectDirectory().getFileObject("web/WEB-INF/classes");
306                             if (null != cpe) {
307                                 roots.add(cpe);
308                             }
309                             if (roots.size() > 0) {
310                                 ClassPath cp = ClassPathSupport.createClassPath(roots.toArray(new FileObject[roots.size()])); // creatClassPath(roots);
311
ClassPath[] aofcp = new ClassPath[] {cp};
312                                 GlobalPathRegistry.getDefault().register(ClassPath.SOURCE, aofcp);
313                                 GlobalPathRegistry.getDefault().register(ClassPath.COMPILE, aofcp);
314                                 paths.add(aofcp);
315                             }
316                             J2eeModuleProvider jmp = (J2eeModuleProvider) tmpproj.getLookup().lookup(J2eeModuleProvider.class);
317                             jmp.getConfigSupport().ensureConfigurationReady();
318                             tmp.setInner(jmp);
319                         } else {
320                             Object JavaDoc mt = isEar?J2eeModule.EAR:J2eeModule.CONN;
321                             tmp.setJ2eeModule(new J2eeModuleForAddModuleAction(mt));
322                             tmp.setServerInstanceID((String JavaDoc) app.get(ArchiveProjectProperties.J2EE_SERVER_INSTANCE));
323                             if (isEar) {
324                                 tmp.getConfigSupport().ensureConfigurationReady();
325                             }
326                         }
327                     }
328                     
329                     if (!isEar) {
330                         return null;
331                     }
332                     
333                     // This is an ear project
334
FileObject appXml = getProjectDirectory().getFileObject("nbproject").getFileObject("application.xml"); // NOI18N
335
if (null != appXml) {
336                         try {
337                             Application appDD = org.netbeans.modules.j2ee.dd.api.application.DDProvider.getDefault().getDDRoot(appXml);
338                             Module ms[] = appDD.getModule();
339                             for (Module m : ms) {
340                                 String JavaDoc archivePath = m.getEjb();
341                                 if (null != archivePath) {
342                                     openSubarchiveProject(archivePath);
343                                 } else {
344                                     archivePath = m.getJava();
345                                     if (null != archivePath) {
346                                         openSubarchiveProject(archivePath);
347                                     } else {
348                                         archivePath = m.getConnector();
349                                         if (null != archivePath) {
350                                             openSubarchiveProject(archivePath);
351                                         } else {
352                                             Web w = m.getWeb();
353                                             if (null != w) {
354                                                 archivePath = w.getWebUri();
355                                                 if (null != archivePath) {
356                                                     openSubarchiveProject(archivePath);
357                                                 }
358                                             }
359                                         }
360                                     }
361                                 }
362                                 
363                             }
364                         } catch (IOException JavaDoc ex) {
365                             ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL, "" + ex);
366                         }
367                     } else {
368                         ErrorManager.getDefault().log(ErrorManager.WARNING, NbBundle.getMessage(ArchiveProject.class,"WARN_EAR_ARCH_MISSING_APPLICATION_XML",getName()));
369                     }
370                     return null;
371                 }
372             });
373         }
374         
375         private void openSubarchiveProject( String JavaDoc pathInEar ) throws IOException JavaDoc {
376             FileObject root = getProjectDirectory();
377             FileObject subprojRoot = root.getFileObject("subarchives");
378             String JavaDoc subprojkey = Util.getKey(pathInEar);
379             try {
380                 FileObject projDest = subprojRoot.getFileObject(subprojkey);
381                 nameMap.put(subprojkey, pathInEar);
382                 FileObject fo = (FileObject) projDest.getFileObject(ArchiveProjectProperties.TMP_PROJ_DIR_VALUE);
383                 Project tmpproj = ProjectManager.getDefault().findProject(fo);
384                 Project subproj = ProjectManager.getDefault().findProject(projDest);
385                 MyOpenHook eh = (MyOpenHook) subproj.getLookup().lookup(MyOpenHook.class);
386                 eh.regenerateBuildFiles();
387                 ProvidesJ2eeModule tmp = (ProvidesJ2eeModule) subproj.getLookup().lookup(ProvidesJ2eeModule.class);
388                 if (null!=tmpproj) {
389                     J2eeModuleProvider jmp = (J2eeModuleProvider) tmpproj.getLookup().lookup(J2eeModuleProvider.class);
390                     List JavaDoc<FileObject> roots = new ArrayList JavaDoc<FileObject>();
391                     FileObject cpe = tmpproj.getProjectDirectory().getFileObject("src/java");
392                     if (null != cpe) {
393                         roots.add(cpe);
394                     }
395                     cpe = tmpproj.getProjectDirectory().getFileObject("src/conf");
396                     if (null != cpe) {
397                         roots.add(cpe);
398                     }
399                     cpe = tmpproj.getProjectDirectory().getFileObject("web/WEB-INF/classes");
400                     if (null != cpe) {
401                         roots.add(cpe);
402                     }
403                     if (roots.size() > 0) {
404                         ClassPath cp = ClassPathSupport.createClassPath(roots.toArray(new FileObject[roots.size()])); // creatClassPath(roots);
405
ClassPath[] aofcp = new ClassPath[] {cp};
406                         GlobalPathRegistry.getDefault().register(ClassPath.SOURCE, aofcp);
407                         GlobalPathRegistry.getDefault().register(ClassPath.COMPILE, aofcp);
408                         paths.add(aofcp);
409                     }
410                     try {
411                         jmp.getConfigSupport().ensureConfigurationReady();
412                     } catch (IllegalArgumentException JavaDoc iae) {
413                         // I saw an IAE come out of this method once. I want to
414
// find out this value if it happens again
415
FileObject tfo = tmpproj.getProjectDirectory();
416                         if (null != tfo) {
417                             ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL,
418                                     tmpproj.getProjectDirectory().toString());
419                         } else {
420                             ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL,
421                                     "null");
422                         }
423                         throw iae;
424                     }
425                     tmp.setInner(jmp);
426                 } else {
427                     Object JavaDoc mt = J2eeModule.CONN;
428                     tmp.setJ2eeModule(new J2eeModuleForAddModuleAction(mt));
429                     tmp.setServerInstanceID((String JavaDoc) getArchiveProjectProperties().get(ArchiveProjectProperties.J2EE_SERVER_INSTANCE));
430                 }
431             } catch (IOException JavaDoc ex) {
432                 ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL, "" + ex);
433             }
434         }
435         
436         protected void projectClosed() {
437             List JavaDoc<ClassPath[]> tmplist = new ArrayList JavaDoc<ClassPath[]>();
438             for (ClassPath[] aofcp : paths) {
439                 GlobalPathRegistry.getDefault().unregister(ClassPath.SOURCE, aofcp);
440                 GlobalPathRegistry.getDefault().unregister(ClassPath.COMPILE, aofcp);
441                 tmplist.add(aofcp);
442             }
443             for (ClassPath[] aofcp : tmplist) {
444                 paths.remove(aofcp);
445             }
446         }
447         
448     }
449     
450     // TODO - implement when there is a customizer for the project.
451
class ProjectXmlSaved extends org.netbeans.spi.project.support.ant.ProjectXmlSavedHook {
452         
453         protected void projectXmlSaved() throws IOException JavaDoc {
454             FileObject subDir = getProjectDirectory().getFileObject(ArchiveProjectProperties.TMP_PROJ_DIR_VALUE);
455             if (subDir != null) {
456                 Project tmpproj = null;
457                 try {
458                     tmpproj = ProjectManager.getDefault().findProject(subDir);
459                 } catch (IllegalArgumentException JavaDoc ex) {
460                     ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL, "" + ex);
461                 } catch (IOException JavaDoc ex) {
462                     ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL, "" + ex);
463                 }
464                 ProvidesJ2eeModule tmp = (ProvidesJ2eeModule) ArchiveProject.this.getLookup().lookup(ProvidesJ2eeModule.class);
465                 if (null!=tmpproj) {
466                     //J2eeModuleProvider jmp = (J2eeModuleProvider) tmpproj.getLookup().lookup(J2eeModuleProvider.class);
467
tmp.setServerInstanceID((String JavaDoc) getArchiveProjectProperties().get(ArchiveProjectProperties.J2EE_SERVER_INSTANCE));
468                 }
469             }
470         }
471     }
472     
473     
474     /** Return configured project name. */
475     public String JavaDoc getNamedProjectAttribute(final String JavaDoc attr) {
476         return (String JavaDoc) ProjectManager.mutex().readAccess(new Mutex.Action() {
477             public Object JavaDoc run() {
478                 Element JavaDoc data = helper.getPrimaryConfigurationData(true);
479                 // XXX replace by XMLUtil when that has findElement, findText, etc.
480
NodeList JavaDoc nl = data.getElementsByTagNameNS(ArchiveProjectType.PROJECT_CONFIGURATION_NS, attr);
481                 if (nl.getLength() == 1) {
482                     nl = nl.item(0).getChildNodes();
483                     if (nl.getLength() == 1 && nl.item(0).getNodeType() == Node.TEXT_NODE) {
484                         return ((Text JavaDoc) nl.item(0)).getNodeValue();
485                     }
486                 }
487                 return "???"; // NOI18N
488
}
489         });
490     }
491     
492     /** Store configured project name. */
493     public void setNamedProjectAttribute(final String JavaDoc attr, final String JavaDoc value) {
494         ProjectManager.mutex().writeAccess(new Mutex.Action() {
495             public Object JavaDoc run() {
496                 Element JavaDoc data = helper.getPrimaryConfigurationData(true);
497                 // XXX replace by XMLUtil when that has findElement, findText, etc.
498
NodeList JavaDoc nl = data.getElementsByTagNameNS(ArchiveProjectType.PROJECT_CONFIGURATION_NS, attr);
499                 Element JavaDoc nameEl;
500                 if (nl.getLength() == 1) {
501                     nameEl = (Element JavaDoc) nl.item(0);
502                     NodeList JavaDoc deadKids = nameEl.getChildNodes();
503                     while (deadKids.getLength() > 0) {
504                         nameEl.removeChild(deadKids.item(0));
505                     }
506                 } else {
507                     nameEl = data.getOwnerDocument().createElementNS(ArchiveProjectType.PROJECT_CONFIGURATION_NS, attr);
508                     data.insertBefore(nameEl, /* OK if null */data.getChildNodes().item(0));
509                 }
510                 nameEl.appendChild(data.getOwnerDocument().createTextNode(value));
511                 helper.putPrimaryConfigurationData(data, true);
512                 return null;
513             }
514         });
515     }
516     
517     private class J2eeModuleForAddModuleAction implements J2eeModule {
518         
519         private Object JavaDoc mt = null;
520         
521         J2eeModuleForAddModuleAction(Object JavaDoc mt) {
522             this.mt = mt;
523         }
524         
525         public String JavaDoc getModuleVersion() {
526             return J2eeModule.JAVA_EE_5; // throw new UnsupportedOperationException();
527
}
528         
529         public Object JavaDoc getModuleType() {
530             return mt;
531         }
532         
533         public String JavaDoc getUrl() {
534             //throw new UnsupportedOperationException();
535
return null;
536         }
537         
538         public void setUrl(String JavaDoc url) {
539             throw new UnsupportedOperationException JavaDoc();
540         }
541         
542         public FileObject getArchive() throws IOException JavaDoc {
543             FileObject distDir = getProjectDirectory().getFileObject("dist");
544             FileObject kids[] = distDir.getChildren();
545             FileObject retVal = null;
546             if (null != kids && kids.length == 1){
547                 retVal = kids[0];
548             } else if (null != kids && kids.length > 1) {
549                 for (FileObject kid : kids) {
550                     if (kid.isData() && kid.getNameExt().endsWith("ar")) {
551                         retVal = kid;
552                     }
553                 }
554             }
555             
556             return retVal;
557         }
558         
559         public Iterator JavaDoc getArchiveContents() throws IOException JavaDoc {
560             throw new UnsupportedOperationException JavaDoc();
561         }
562         
563         public FileObject getContentDirectory() throws IOException JavaDoc {
564             return null;
565         }
566         
567         public BaseBean getDeploymentDescriptor(String JavaDoc location) {
568             BaseBean retVal = null;
569             if ("META-INF/application.xml".equals(location)) {
570                 String JavaDoc dir = (String JavaDoc)getArchiveProjectProperties().get(ArchiveProjectProperties.PROXY_PROJECT_DIR);
571                 FileObject appFile = getProjectDirectory().getFileObject(dir).getFileObject("src").getFileObject("conf").getFileObject("application.xml");
572                 Application appBean;
573                 try {
574                     appBean = org.netbeans.modules.j2ee.dd.api.application.DDProvider.getDefault().getDDRoot(appFile);
575                     retVal = org.netbeans.modules.j2ee.dd.api.application.DDProvider.getDefault().getBaseBean(appBean);
576                 } catch (IOException JavaDoc ex) {
577                     ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL, "" + ex);
578                 }
579             } else if ("META-INF/ra.xml".equals(location)) {
580                 retVal = null;
581             } else {
582                 throw new UnsupportedOperationException JavaDoc(location);
583             }
584             return retVal;
585         }
586         
587         public void addVersionListener(J2eeModule.VersionListener listener) {
588             //throw new UnsupportedOperationException();
589
}
590         
591         public void removeVersionListener(J2eeModule.VersionListener listener) {
592             //throw new UnsupportedOperationException();
593
}
594     }
595     
596     
597     
598     private static final class RecommendedTemplatesImpl implements RecommendedTemplates, PrivilegedTemplates {
599         
600         RecommendedTemplatesImpl() {
601         }
602         
603         // List of primarily supported templates
604

605         private static final String JavaDoc[] APPLICATION_TYPES = new String JavaDoc[] {
606             "sunresource-types", // NOI18N
607
"XML", // NOI18N
608
"simple-files" // NOI18N
609
};
610         
611         private static final String JavaDoc[] PRIVILEGED_NAMES = new String JavaDoc[] {
612             "Templates/SunResources/JDBC_Connection_Pool", // NOI18N
613
"Templates/SunResources/JDBC_Resource", // NOI18N
614
"Templates/SunResources/JMS_Resource", // NOI18N
615
"Templates/SunResources/JavaMail_Resource", // NOI18N
616
"Templates/Persistence/Schema.dbschema", // NOI18N
617
};
618         
619         public String JavaDoc[] getRecommendedTypes() {
620             return APPLICATION_TYPES;
621         }
622         
623         public String JavaDoc[] getPrivilegedTemplates() {
624             return PRIVILEGED_NAMES;
625         }
626         
627     }
628     
629     class MyOpenHook {
630         
631         public void regenerateBuildFiles() {
632             doRegeneration();
633         }
634     }
635     
636     private void doRegeneration() {
637         
638         GeneratedFilesHelper gFH = new GeneratedFilesHelper(helper);
639         ArchiveProjectProperties app = getArchiveProjectProperties();
640         String JavaDoc sourceArchive = eval.evaluate((String JavaDoc)app.get(ArchiveProjectProperties.SOURCE_ARCHIVE));
641         try {
642             if (sourceArchive.endsWith("war")) //NOI18N
643
gFH.refreshBuildScript(GeneratedFilesHelper.BUILD_IMPL_XML_PATH,
644                         ArchiveProject.class.getResource("resources/build-impl-war.xsl"),
645                         true);
646             else
647                 // ejb-jar/connector/appclient
648
gFH.refreshBuildScript(GeneratedFilesHelper.BUILD_IMPL_XML_PATH,
649                         ArchiveProject.class.getResource("resources/build-impl.xsl"),
650                         true);
651         } catch (IllegalStateException JavaDoc ex) {
652             ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL, "IllegalStateException while opening project: " + ex);
653         } catch (IOException JavaDoc ex) {
654             ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL, "IOException while opening project: " + ex);
655         }
656         try {
657             gFH.refreshBuildScript(
658                     GeneratedFilesHelper.BUILD_XML_PATH,
659                     ArchiveProject.class.getResource("resources/build.xsl"),
660                     true);
661         } catch (IllegalStateException JavaDoc ex) {
662             ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL, "IllegalStateException while opening project: " + ex);
663         } catch (IOException JavaDoc ex) {
664             ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL, "IOException while opening project: " + ex);
665         }
666         
667         String JavaDoc servInstID = (String JavaDoc) app.get(ArchiveProjectProperties.J2EE_SERVER_INSTANCE);
668         J2eePlatform platform = Deployment.getDefault().getJ2eePlatform(servInstID);
669         if (platform != null) {
670             // updates j2ee.platform.cp & wscompile.cp & reg. j2ee platform listener
671
ArchiveProjectProperties.setServerInstance(ArchiveProject.this,
672                     ArchiveProject.this.helper, servInstID);
673         } else {
674             // if there is some server instance of the type which was used
675
// previously do not ask and use it
676
String JavaDoc serverType = (String JavaDoc) app.get(ArchiveProjectProperties.J2EE_SERVER_TYPE);
677             if (serverType != null) {
678                 String JavaDoc[] servInstIDs = Deployment.getDefault().getInstancesOfServer(serverType);
679                 if (servInstIDs.length > 0) {
680                     ArchiveProjectProperties.setServerInstance(ArchiveProject.this, ArchiveProject.this.helper, servInstIDs[0]);
681                     platform = Deployment.getDefault().getJ2eePlatform(servInstIDs[0]);
682                 }
683             }
684             if (platform == null) {
685                 BrokenServerSupport.showAlert();
686             }
687         }
688         
689         // Force the tmpproj and subarchive/tmpproj's to initialize
690

691         // create the setupdirectory if ther isn't one in the project.
692
FileObject dir = helper.getProjectDirectory();
693         try {
694             FileUtil.createFolder(dir,ArchiveProjectProperties.SETUP_DIR_VALUE);
695         } catch (IOException JavaDoc ex) {
696             ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL, "Error while opening project: " + ex);
697         }
698     }
699 }
700
701
702
Popular Tags