KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > earproject > ui > customizer > EarProjectProperties


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.earproject.ui.customizer;
21
22 import java.beans.PropertyChangeListener JavaDoc;
23 import java.beans.PropertyChangeSupport JavaDoc;
24 import java.io.File JavaDoc;
25 import java.io.IOException JavaDoc;
26 import java.net.URI JavaDoc;
27 import java.net.URL JavaDoc;
28 import java.text.Collator JavaDoc;
29 import java.util.ArrayList JavaDoc;
30 import java.util.Arrays JavaDoc;
31 import java.util.Collections JavaDoc;
32 import java.util.HashMap JavaDoc;
33 import java.util.HashSet JavaDoc;
34 import java.util.Iterator JavaDoc;
35 import java.util.LinkedHashMap JavaDoc;
36 import java.util.List JavaDoc;
37 import java.util.Map JavaDoc;
38 import java.util.Set JavaDoc;
39 import java.util.TreeSet JavaDoc;
40 import java.util.jar.JarEntry JavaDoc;
41 import java.util.jar.JarFile JavaDoc;
42 import javax.swing.JButton JavaDoc;
43 import org.netbeans.api.java.platform.JavaPlatform;
44 import org.netbeans.api.java.platform.JavaPlatformManager;
45 import org.netbeans.api.java.platform.Specification;
46 import org.netbeans.api.java.project.JavaProjectConstants;
47 import org.netbeans.api.project.Project;
48 import org.netbeans.api.project.ProjectManager;
49 import org.netbeans.api.project.ProjectUtils;
50 import org.netbeans.api.project.ant.AntArtifact;
51 import org.netbeans.api.project.ant.AntArtifactQuery;
52 import org.netbeans.api.project.libraries.Library;
53 import org.netbeans.api.project.libraries.LibraryManager;
54 import org.netbeans.api.queries.CollocationQuery;
55 import org.netbeans.modules.j2ee.api.ejbjar.EjbProjectConstants;
56 import org.netbeans.modules.j2ee.common.ui.BrokenServerSupport;
57 import org.netbeans.modules.j2ee.dd.api.application.Application;
58 import org.netbeans.modules.j2ee.dd.api.application.DDProvider;
59 import org.netbeans.modules.j2ee.dd.api.application.Module;
60 import org.netbeans.modules.j2ee.dd.api.application.Web;
61 import org.netbeans.modules.j2ee.deployment.devmodules.api.AntDeploymentHelper;
62 import org.netbeans.modules.j2ee.deployment.devmodules.api.Deployment;
63 import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule;
64 import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eePlatform;
65 import org.netbeans.modules.j2ee.deployment.devmodules.spi.J2eeModuleProvider;
66 import org.netbeans.modules.j2ee.deployment.plugins.api.InstanceProperties;
67 import org.netbeans.modules.j2ee.earproject.BrokenProjectSupport;
68 import org.netbeans.modules.j2ee.earproject.EarProject;
69 import org.netbeans.modules.j2ee.earproject.EarProjectGenerator;
70 import org.netbeans.modules.j2ee.earproject.UpdateHelper;
71 import org.netbeans.modules.web.api.webmodule.WebModule;
72 import org.netbeans.spi.project.SubprojectProvider;
73 import org.netbeans.spi.project.support.ant.AntBasedProjectType;
74 import org.netbeans.spi.project.support.ant.AntProjectEvent;
75 import org.netbeans.spi.project.support.ant.AntProjectHelper;
76 import org.netbeans.spi.project.support.ant.EditableProperties;
77 import org.netbeans.spi.project.support.ant.GeneratedFilesHelper;
78 import org.netbeans.spi.project.support.ant.PropertyUtils;
79 import org.netbeans.spi.project.support.ant.ReferenceHelper;
80 import org.openide.DialogDisplayer;
81 import org.openide.ErrorManager;
82 import org.openide.NotifyDescriptor;
83 import org.openide.filesystems.FileObject;
84 import org.openide.filesystems.FileUtil;
85 import org.openide.filesystems.URLMapper;
86 import org.openide.modules.SpecificationVersion;
87 import org.openide.util.Mutex;
88 import org.openide.util.MutexException;
89 import org.openide.util.NbBundle;
90 import org.w3c.dom.Document JavaDoc;
91 import org.w3c.dom.Element JavaDoc;
92 import org.w3c.dom.Node JavaDoc;
93 import org.w3c.dom.NodeList JavaDoc;
94 import org.w3c.dom.Text JavaDoc;
95
96 /**
97  * Helper class. Defines constants for properties. Knows the proper
98  * place where to store the properties.
99  *
100  * @author Petr Hrebejk
101  */

102 public final class EarProjectProperties {
103     
104     public static final String JavaDoc J2EE_SPEC_14_LABEL =
105             NbBundle.getMessage(EarProjectProperties.class, "J2EESpecLevel_14");
106     public static final String JavaDoc JAVA_EE_SPEC_50_LABEL =
107             NbBundle.getMessage(EarProjectProperties.class, "JavaEESpecLevel_50");
108     
109     // Special properties of the project
110
public static final String JavaDoc WEB_PROJECT_NAME = "web.project.name"; //NOI18N
111
public static final String JavaDoc JAVA_PLATFORM = "platform.active"; //NOI18N
112
public static final String JavaDoc J2EE_PLATFORM = "j2ee.platform"; //NOI18N
113

114     // Properties stored in the PROJECT.PROPERTIES
115
/** root of external web module sources (full path), ".." if the sources are within project folder */
116     public static final String JavaDoc SOURCE_ROOT = "source.root"; //NOI18N
117
public static final String JavaDoc BUILD_FILE = "buildfile"; //NOI18N
118
public static final String JavaDoc LIBRARIES_DIR = "lib.dir"; //NOI18N
119
public static final String JavaDoc DIST_DIR = "dist.dir"; //NOI18N
120
public static final String JavaDoc DIST_JAR = "dist.jar"; //NOI18N
121
public static final String JavaDoc JAVAC_CLASSPATH = "javac.classpath"; //NOI18N
122
public static final String JavaDoc DEBUG_CLASSPATH = "debug.classpath"; //NOI18N
123
public static final String JavaDoc RUN_CLASSPATH = "run.classpath"; // NOI18N
124
public static final String JavaDoc JAR_NAME = "jar.name"; //NOI18N
125
public static final String JavaDoc JAR_COMPRESS = "jar.compress"; //NOI18N
126
public static final String JavaDoc JAR_CONTENT_ADDITIONAL = "jar.content.additional"; //NOI18N
127

128     public static final String JavaDoc APPLICATION_CLIENT = "app.client"; // NOI18N
129
public static final String JavaDoc APPCLIENT_MAIN_CLASS = "main.class"; // NOI18N
130
public static final String JavaDoc APPCLIENT_ARGS = "application.args"; // NOI18N
131
public static final String JavaDoc APPCLIENT_JVM_OPTIONS = "j2ee.appclient.jvmoptions"; // NOI18N
132
public static final String JavaDoc APPCLIENT_MAINCLASS_ARGS = "j2ee.appclient.mainclass.args"; // NOI18N
133

134     public static final String JavaDoc LAUNCH_URL_RELATIVE = "client.urlPart"; //NOI18N
135
public static final String JavaDoc DISPLAY_BROWSER = "display.browser"; //NOI18N
136
public static final String JavaDoc CLIENT_MODULE_URI = "client.module.uri"; //NOI18N
137
public static final String JavaDoc J2EE_SERVER_INSTANCE = "j2ee.server.instance"; //NOI18N
138
public static final String JavaDoc J2EE_SERVER_TYPE = "j2ee.server.type"; //NOI18N
139
public static final String JavaDoc JAVAC_SOURCE = "javac.source"; //NOI18N
140
public static final String JavaDoc JAVAC_DEBUG = "javac.debug"; //NOI18N
141
public static final String JavaDoc JAVAC_DEPRECATION = "javac.deprecation"; //NOI18N
142
public static final String JavaDoc JAVAC_TARGET = "javac.target"; //NOI18N
143
public static final String JavaDoc META_INF = "meta.inf"; //NOI18N
144
public static final String JavaDoc RESOURCE_DIR = "resource.dir"; //NOI18N
145
public static final String JavaDoc WEB_DOCBASE_DIR = "web.docbase.dir"; //NOI18N
146
public static final String JavaDoc BUILD_DIR = "build.dir"; //NOI18N
147
public static final String JavaDoc BUILD_GENERATED_DIR = "build.generated.dir"; //NOI18N
148
public static final String JavaDoc BUILD_CLASSES_EXCLUDES = "build.classes.excludes"; //NOI18N
149
public static final String JavaDoc DIST_JAVADOC_DIR = "dist.javadoc.dir"; //NOI18N
150
public static final String JavaDoc NO_DEPENDENCIES="no.dependencies"; //NOI18N
151

152     public static final String JavaDoc JAVADOC_PRIVATE="javadoc.private"; //NOI18N
153
public static final String JavaDoc JAVADOC_NO_TREE="javadoc.notree"; //NOI18N
154
public static final String JavaDoc JAVADOC_USE="javadoc.use"; //NOI18N
155
public static final String JavaDoc JAVADOC_NO_NAVBAR="javadoc.nonavbar"; //NOI18N
156
public static final String JavaDoc JAVADOC_NO_INDEX="javadoc.noindex"; //NOI18N
157
public static final String JavaDoc JAVADOC_SPLIT_INDEX="javadoc.splitindex"; //NOI18N
158
public static final String JavaDoc JAVADOC_AUTHOR="javadoc.author"; //NOI18N
159
public static final String JavaDoc JAVADOC_VERSION="javadoc.version"; //NOI18N
160
public static final String JavaDoc JAVADOC_WINDOW_TITLE="javadoc.windowtitle"; //NOI18N
161
public static final String JavaDoc JAVADOC_ENCODING="javadoc.encoding"; //NOI18N
162

163     public static final String JavaDoc JAVADOC_PREVIEW="javadoc.preview"; //NOI18N
164

165     public static final String JavaDoc COMPILE_JSPS = "compile.jsps"; //NOI18N
166

167     public static final String JavaDoc CLIENT_NAME = "j2ee.clientName"; // NOI18N
168

169     // Properties stored in the PRIVATE.PROPERTIES
170

171     public static final String JavaDoc APPCLIENT_TOOL_RUNTIME = "j2ee.appclient.tool.runtime"; // NOI18N
172
public static final String JavaDoc APPCLIENT_TOOL_MAINCLASS = "j2ee.appclient.tool.mainclass"; // NOI18N
173
public static final String JavaDoc APPCLIENT_TOOL_JVMOPTS = "j2ee.appclient.tool.jvmoptions"; // NOI18N
174
public static final String JavaDoc APPCLIENT_TOOL_ARGS = "j2ee.appclient.tool.args"; // NOI18N
175

176     /**
177      * "API" contract between Application Client and Glassfish plugin's
178      * J2eePlatformImpl implementation.
179      */

180     private static final String JavaDoc J2EE_PLATFORM_APPCLIENT_ARGS = "j2ee.appclient.args"; // NOI18N
181

182     static final String JavaDoc APPCLIENT_WA_COPY_CLIENT_JAR_FROM = "wa.copy.client.jar.from"; // NOI18N
183

184     // Shortcuts
185
private static final String JavaDoc PROJECT = AntProjectHelper.PROJECT_PROPERTIES_PATH;
186     private static final String JavaDoc PRIVATE = AntProjectHelper.PRIVATE_PROPERTIES_PATH;
187     
188 // public static final String TAG_WEB_MODULE_LIBRARIES = "j2ee-module-libraries"; // NOI18N
189
// public static final String TAG_WEB_MODULE__ADDITIONAL_LIBRARIES = "j2ee-module-additional-libraries"; //NOI18N
190
public static final String JavaDoc TAG_WEB_MODULE_LIBRARIES = "web-module-libraries"; // NOI18N
191
public static final String JavaDoc TAG_WEB_MODULE__ADDITIONAL_LIBRARIES = "web-module-additional-libraries"; //NOI18N
192

193     public static final String JavaDoc DEPLOY_ANT_PROPS_FILE = "deploy.ant.properties.file"; // NOI18N
194

195     public static final String JavaDoc ANT_DEPLOY_BUILD_SCRIPT = "nbproject/ant-deploy.xml"; // NOI18N
196

197     private static final String JavaDoc ATTR_FILES = "files"; //NOI18N
198
private static final String JavaDoc ATTR_DIRS = "dirs"; //NOI18N
199

200     
201     static final PropertyParser STRING_PARSER = new StringParser();
202     private static final BooleanParser BOOLEAN_PARSER = new BooleanParser();
203     private static final InverseBooleanParser INVERSE_BOOLEAN_PARSER = new InverseBooleanParser();
204     private final PropertyParser PATH_PARSER = new PathParser();
205     private final PropertyParser JAVAC_CLASSPATH_PARSER = new PathParser(TAG_WEB_MODULE_LIBRARIES);
206     private final PropertyParser JAR_CONTENT_ADDITIONAL_PARSER =
207             new PathParser(TAG_WEB_MODULE__ADDITIONAL_LIBRARIES);
208     private static final PlatformParser PLATFORM_PARSER = new PlatformParser();
209     
210     // Info about the property destination
211
private final PropertyDescriptor PROPERTY_DESCRIPTORS[] = {
212         new PropertyDescriptor( WEB_PROJECT_NAME, null, STRING_PARSER ),
213         new PropertyDescriptor( J2EE_PLATFORM, PROJECT, STRING_PARSER ),
214                 
215         new PropertyDescriptor( SOURCE_ROOT, PROJECT, STRING_PARSER ),
216         new PropertyDescriptor( BUILD_FILE, PROJECT, STRING_PARSER ),
217         new PropertyDescriptor( LIBRARIES_DIR, PROJECT, STRING_PARSER ),
218         new PropertyDescriptor( DIST_DIR, PROJECT, STRING_PARSER ),
219         new PropertyDescriptor( DIST_JAR, PROJECT, STRING_PARSER ),
220         new PropertyDescriptor( JAVAC_CLASSPATH, PROJECT, JAVAC_CLASSPATH_PARSER ),
221         new PropertyDescriptor( COMPILE_JSPS, PROJECT, BOOLEAN_PARSER ),
222         //new PropertyDescriptor( JSP_COMPILER_CLASSPATH, PRIVATE, PATH_PARSER ),
223
new PropertyDescriptor( DEBUG_CLASSPATH, PROJECT, PATH_PARSER ),
224         new PropertyDescriptor( RUN_CLASSPATH, PROJECT, PATH_PARSER ),
225
226         new PropertyDescriptor( JAR_NAME, PROJECT, STRING_PARSER ),
227         new PropertyDescriptor( JAR_COMPRESS, PROJECT, BOOLEAN_PARSER ),
228         new PropertyDescriptor( JAR_CONTENT_ADDITIONAL, PROJECT, JAR_CONTENT_ADDITIONAL_PARSER ),
229         
230         new PropertyDescriptor( APPLICATION_CLIENT, PROJECT, STRING_PARSER ),
231         new PropertyDescriptor( APPCLIENT_MAIN_CLASS, PROJECT, STRING_PARSER ),
232         new PropertyDescriptor( APPCLIENT_JVM_OPTIONS, PROJECT, STRING_PARSER ),
233         new PropertyDescriptor( APPCLIENT_ARGS, PRIVATE, STRING_PARSER ),
234         
235         new PropertyDescriptor( LAUNCH_URL_RELATIVE, PROJECT, STRING_PARSER ),
236         new PropertyDescriptor( CLIENT_MODULE_URI, PROJECT, STRING_PARSER ),
237         new PropertyDescriptor( DISPLAY_BROWSER, PROJECT, BOOLEAN_PARSER ),
238         new PropertyDescriptor( J2EE_SERVER_TYPE, PROJECT, STRING_PARSER ),
239         new PropertyDescriptor( J2EE_SERVER_INSTANCE, PRIVATE, STRING_PARSER ),
240         new PropertyDescriptor( JAVAC_SOURCE, PROJECT, STRING_PARSER ),
241         new PropertyDescriptor( JAVAC_DEBUG, PROJECT, BOOLEAN_PARSER ),
242         new PropertyDescriptor( JAVAC_DEPRECATION, PROJECT, BOOLEAN_PARSER ),
243         new PropertyDescriptor( JAVAC_TARGET, PROJECT, STRING_PARSER ),
244         new PropertyDescriptor( RESOURCE_DIR, PROJECT, STRING_PARSER ),
245         new PropertyDescriptor( BUILD_DIR, PROJECT, STRING_PARSER ),
246         new PropertyDescriptor( BUILD_CLASSES_EXCLUDES, PROJECT, STRING_PARSER ),
247         new PropertyDescriptor( DIST_JAVADOC_DIR, PROJECT, STRING_PARSER ),
248         new PropertyDescriptor( WEB_DOCBASE_DIR, PROJECT, STRING_PARSER ),
249         new PropertyDescriptor( NO_DEPENDENCIES, PROJECT, INVERSE_BOOLEAN_PARSER ),
250         new PropertyDescriptor( JAVA_PLATFORM, PROJECT, PLATFORM_PARSER ),
251         new PropertyDescriptor( DEPLOY_ANT_PROPS_FILE, PRIVATE, STRING_PARSER ),
252         
253         new PropertyDescriptor( JAVADOC_PRIVATE, PROJECT, BOOLEAN_PARSER ),
254         new PropertyDescriptor( JAVADOC_NO_TREE, PROJECT, INVERSE_BOOLEAN_PARSER ),
255         new PropertyDescriptor( JAVADOC_USE, PROJECT, BOOLEAN_PARSER ),
256         new PropertyDescriptor( JAVADOC_NO_NAVBAR, PROJECT, INVERSE_BOOLEAN_PARSER ),
257         new PropertyDescriptor( JAVADOC_NO_INDEX, PROJECT, INVERSE_BOOLEAN_PARSER ),
258         new PropertyDescriptor( JAVADOC_SPLIT_INDEX, PROJECT, BOOLEAN_PARSER ),
259         new PropertyDescriptor( JAVADOC_AUTHOR, PROJECT, BOOLEAN_PARSER ),
260         new PropertyDescriptor( JAVADOC_VERSION, PROJECT, BOOLEAN_PARSER ),
261         new PropertyDescriptor( JAVADOC_WINDOW_TITLE, PROJECT, STRING_PARSER ),
262         new PropertyDescriptor( JAVADOC_ENCODING, PROJECT, STRING_PARSER ),
263         new PropertyDescriptor( JAVADOC_PREVIEW, PROJECT, BOOLEAN_PARSER ),
264     };
265     
266     // Private fields ----------------------------------------------------------
267

268     /** Maps ant property name to its info. */
269     private final Map JavaDoc<String JavaDoc, PropertyInfo> properties;
270     
271     private final AntProjectHelper antProjectHelper;
272     private final ReferenceHelper refHelper;
273     private final AntBasedProjectType abpt;
274     private final UpdateHelper updateHelper;
275     private final EarProject earProject;
276     private final GeneratedFilesHelper genFilesHelper;
277     
278     /** Utility field used by bound properties. */
279     private final PropertyChangeSupport JavaDoc propertyChangeSupport = new PropertyChangeSupport JavaDoc(this);
280
281     public EarProjectProperties(final EarProject project,
282             final ReferenceHelper refHelper, final AntBasedProjectType abpt) {
283         this.earProject = project;
284         this.properties = new HashMap JavaDoc<String JavaDoc, PropertyInfo>();
285         this.updateHelper = project.getUpdateHelper();
286         this.antProjectHelper = updateHelper.getAntProjectHelper();
287         this.refHelper = refHelper;
288         this.abpt = abpt;
289         this.genFilesHelper = project.getGeneratedFilesHelper();
290         read();
291     }
292     
293     /** <strong>Package private for unit test only</strong>. */
294     void updateContentDependency(Set JavaDoc<VisualClassPathItem> oldContent, Set JavaDoc<VisualClassPathItem> newContent) {
295         Application app = null;
296         try {
297             app = DDProvider.getDefault().getDDRoot(earProject.getAppModule().getDeploymentDescriptor());
298         } catch (IOException JavaDoc ioe) {
299             ErrorManager.getDefault().log(ioe.getLocalizedMessage());
300         }
301         
302         Set JavaDoc<VisualClassPathItem> deleted = new HashSet JavaDoc(oldContent);
303         deleted.removeAll(newContent);
304         Set JavaDoc<VisualClassPathItem> added = new HashSet JavaDoc(newContent);
305         added.removeAll(oldContent);
306         
307         //do not update the file if there is no change
308
boolean same = true;
309         if(deleted.size() == added.size()) {
310             Iterator JavaDoc<VisualClassPathItem> deletedIterator = deleted.iterator();
311             Iterator JavaDoc<VisualClassPathItem> addedIterator = added.iterator();
312             while (deletedIterator.hasNext() && addedIterator.hasNext()) {
313                 VisualClassPathItem del = deletedIterator.next();
314                 VisualClassPathItem add = addedIterator.next();
315                 //I suppose the vcpi-s should not be null?!?
316
if(del != null && add != null && !del.equals(add)) {
317                     same = false;
318                     break;
319                 }
320             }
321         } else {
322             same = false;
323         }
324         
325         boolean saveNeeded = false;
326         if (null != app && !same) {
327             // delete the old entries out of the application
328
for (VisualClassPathItem vcpi : deleted) {
329                 removeItemFromAppDD(app,vcpi);
330             }
331             // add the new stuff "back"
332
for (VisualClassPathItem vcpi : added) {
333                 addItemToAppDD(app,vcpi);
334             }
335             saveNeeded = true;
336         }
337         for (VisualClassPathItem vcpi : newContent) { // #76008
338
if (!vcpi.getPathInEAR().equals(vcpi.getOrigPathInEAR())) {
339                 removeItemFromAppDD(app, vcpi, vcpi.getCompletePathInArchive(true));
340                 addItemToAppDD(app, vcpi);
341                 saveNeeded = true;
342             }
343         }
344         if (saveNeeded) {
345             try {
346                 app.write(earProject.getAppModule().getDeploymentDescriptor());
347             } catch (IOException JavaDoc ioe) {
348                 ErrorManager.getDefault().log(ioe.getLocalizedMessage());
349             }
350         }
351     }
352     
353     private void removeItemFromAppDD(Application dd, VisualClassPathItem vcpi) {
354         removeItemFromAppDD(dd, vcpi, vcpi.getCompletePathInArchive());
355     }
356     
357     private void removeItemFromAppDD(final Application dd,
358             final VisualClassPathItem vcpi, final String JavaDoc pathInEAR) {
359         Module m = searchForModule(dd, pathInEAR);
360         if (null != m) {
361             dd.removeModule(m);
362             setClientModuleUri("");
363             Object JavaDoc obj = vcpi.getObject();
364             if (obj instanceof AntArtifact) {
365                 AntArtifact aa = (AntArtifact) obj;
366                 Project p = aa.getProject();
367                 J2eeModuleProvider jmp = (J2eeModuleProvider) p.getLookup().lookup(J2eeModuleProvider.class);
368                 if (null != jmp) {
369                     J2eeModule jm = jmp.getJ2eeModule();
370                     if (null != jm) {
371                         earProject.getAppModule().removeModuleProvider(jmp, pathInEAR);
372                     }
373                 }
374             }
375         }
376     }
377     
378     private Module searchForModule(Application dd, String JavaDoc path) {
379         Module mods[] = dd.getModule();
380         int len = 0;
381         if (null != mods) {
382             len = mods.length;
383         }
384         for (int i = 0; i < len; i++) {
385             String JavaDoc val = mods[i].getEjb();
386             if (null != val && val.equals(path)) {
387                 return mods[i];
388             }
389             val = mods[i].getConnector();
390             if (null != val && val.equals(path)) {
391                 return mods[i];
392             }
393             val = mods[i].getJava();
394             if (null != val && val.equals(path)) {
395                 return mods[i];
396             }
397             Web w = mods[i].getWeb();
398             val = null;
399             if ( null != w) {
400                 val = w.getWebUri();
401             }
402             if (null != val && val.equals(path)) {
403                 return mods[i];
404             }
405         }
406         return null;
407     }
408     
409     public void addItemToAppDD(Application dd, VisualClassPathItem vcpi) {
410         Object JavaDoc obj = vcpi.getObject();
411         String JavaDoc path = vcpi.getCompletePathInArchive(); // computePath(vcpi);
412
Module mod = null;
413         if (obj instanceof AntArtifact) {
414             mod = getModFromAntArtifact((AntArtifact) obj, dd, path);
415         } else if (obj instanceof File JavaDoc) {
416            mod = getModFromFile((File JavaDoc) obj, dd, path);
417         }
418         if (mod != null && mod.getWeb() != null) {
419             replaceEmptyClientModuleUri(path);
420         }
421         Module prevMod = searchForModule(dd, path);
422         if (null == prevMod && null != mod) {
423             dd.addModule(mod);
424         }
425     }
426     
427     
428     private Module getModFromAntArtifact(AntArtifact aa, Application dd, String JavaDoc path) {
429         Project p = aa.getProject();
430         Module mod = null;
431         try {
432             J2eeModuleProvider jmp = (J2eeModuleProvider) p.getLookup().lookup(J2eeModuleProvider.class);
433             if (null != jmp) {
434                 jmp.setServerInstanceID(earProject.getServerInstanceID());
435                 J2eeModule jm = jmp.getJ2eeModule();
436                 if (null != jm) {
437                     earProject.getAppModule().addModuleProvider(jmp,path);
438                 } else {
439                     return null;
440                 }
441                 mod = (Module) dd.createBean(Application.MODULE);
442                 if (jm.getModuleType() == J2eeModule.EJB) {
443                     mod.setEjb(path); // NOI18N
444
} else if (jm.getModuleType() == J2eeModule.WAR) {
445                     Web w = (Web) mod.newWeb(); // createBean("Web");
446
w.setWebUri(path);
447                     FileObject tmp = aa.getScriptFile();
448                     if (null != tmp) {
449                         tmp = tmp.getParent().getFileObject("web/WEB-INF/web.xml"); // NOI18N
450
}
451                     WebModule wm = null;
452                     if (null != tmp) {
453                         wm = (WebModule) WebModule.getWebModule(tmp);
454                     }
455                     String JavaDoc contextPath = null;
456                     if (null != wm) {
457                         contextPath = wm.getContextPath();
458                     }
459                     if (contextPath == null) {
460                         int endex = path.length() - 4;
461                         if (endex < 1) {
462                             endex = path.length();
463                         }
464                         contextPath = path.substring(0,endex);
465                     }
466                     w.setContextRoot(contextPath);
467                     mod.setWeb(w);
468                 } else if (jm.getModuleType() == J2eeModule.CONN) {
469                     mod.setConnector(path);
470                 } else if (jm.getModuleType() == J2eeModule.CLIENT) {
471                     mod.setJava(path);
472                 }
473             }
474         }
475         catch (ClassNotFoundException JavaDoc cnfe) {
476             ErrorManager.getDefault().notify(cnfe);
477         }
478         return mod;
479     }
480     
481     private void setClientModuleUri(String JavaDoc newVal) {
482         put(EarProjectProperties.CLIENT_MODULE_URI,newVal);
483     }
484     
485     private void replaceEmptyClientModuleUri(String JavaDoc path) {
486         // set the context path if it is not set...
487
Object JavaDoc current = get(EarProjectProperties.CLIENT_MODULE_URI);
488         if (null == current) {
489             setClientModuleUri(path);
490         }
491         if (current instanceof String JavaDoc && ((String JavaDoc) current).length() < 1) {
492             setClientModuleUri(path);
493         }
494     }
495     
496     private Module getModFromFile(File JavaDoc f, Application dd, String JavaDoc path) {
497             JarFile JavaDoc jar = null;
498             Module mod = null;
499             try {
500                 jar= new JarFile JavaDoc((File JavaDoc) f);
501                 JarEntry JavaDoc ddf = jar.getJarEntry("META-INF/ejb-jar.xml"); // NOI18N
502
if (null != ddf) {
503                     mod = (Module) dd.createBean(Application.MODULE);
504                     mod.setEjb(path);
505                 }
506                 ddf = jar.getJarEntry("META-INF/ra.xml"); // NOI18N
507
if (null != ddf && null == mod) {
508                     mod = (Module) dd.createBean(Application.MODULE);
509                     mod.setConnector(path);
510                 } else if (null != ddf && null != mod) {
511                     return null; // two timing jar file.
512
}
513                 ddf = jar.getJarEntry("META-INF/application-client.xml"); //NOI18N
514
if (null != ddf && null == mod) {
515                     mod = (Module) dd.createBean(Application.MODULE);
516                     mod.setJava(path);
517                 } else if (null != ddf && null != mod) {
518                     return null; // two timing jar file.
519
}
520                 ddf = jar.getJarEntry("WEB-INF/web.xml"); //NOI18N
521
if (null != ddf && null == mod) {
522                     mod = (Module) dd.createBean(Application.MODULE);
523                     Web w = (Web) mod.newWeb();
524                     w.setWebUri(path);
525                         int endex = path.length() - 4;
526                         if (endex < 1) {
527                             endex = path.length();
528                         }
529                         w.setContextRoot("/"+path.substring(0,endex)); // NOI18N
530
mod.setWeb(w);
531                 } else if (null != ddf && null != mod) {
532                     return null; // two timing jar file.
533
}
534                 ddf = jar.getJarEntry("META-INF/application.xml"); //NOI18N
535
if (null != ddf) {
536                     return null;
537                 }
538             } catch (ClassNotFoundException JavaDoc cnfe) {
539                 ErrorManager.getDefault().log(cnfe.getLocalizedMessage());
540             } catch (IOException JavaDoc ioe) {
541                 ErrorManager.getDefault().log(ioe.getLocalizedMessage());
542             } finally {
543                 try {
544                     if (null != jar) {
545                         jar.close();
546                     }
547                 } catch (IOException JavaDoc ioe) {
548                     // there is little that we can do about this.
549
}
550             }
551             return mod;
552         }
553     
554     /**
555      * Called when a change was made to a properties file that might be shared with Ant.
556      * <p class="nonnormative">
557      * Note: normally you would not use this event to detect property changes.
558      * Use the property change listener from {@link PropertyEvaluator} instead to find
559      * changes in the interpreted values of Ant properties, possibly coming from multiple
560      * properties files.
561      * </p>
562      * @param ev an event with details of the change
563      */

564     public void propertiesChanged(AntProjectEvent ev) {
565         
566     }
567
568     /**
569      * Adds a PropertyChangeListener to the listener list.
570      * @param l The listener to add.
571      */

572     public void addPropertyChangeListener(PropertyChangeListener JavaDoc l) {
573
574         propertyChangeSupport.addPropertyChangeListener (l);
575     }
576
577     /**
578      * Removes a PropertyChangeListener from the listener list.
579      * @param l The listener to remove.
580      */

581     public void removePropertyChangeListener(PropertyChangeListener JavaDoc l) {
582         propertyChangeSupport.removePropertyChangeListener (l);
583     }
584     
585     @SuppressWarnings JavaDoc("unchecked")
586     public List JavaDoc<VisualClassPathItem> getJarContentAdditional() {
587         List JavaDoc<VisualClassPathItem> vcpis = Collections.emptyList();
588         Object JavaDoc o = properties.get(JAR_CONTENT_ADDITIONAL);
589         if (o instanceof PropertyInfo) {
590             PropertyInfo pi = (PropertyInfo) o;
591             Object JavaDoc value = pi.getValue();
592             assert value instanceof List JavaDoc : JAR_CONTENT_ADDITIONAL + " is not a List: " + value.getClass();
593             vcpis = (List JavaDoc) value;
594         }
595         return vcpis;
596     }
597     
598     /**
599      * Acquires modules form the earproject's metadata (properties files).
600      */

601     public Map JavaDoc<String JavaDoc, J2eeModuleProvider> getModuleMap() {
602         Map JavaDoc<String JavaDoc, J2eeModuleProvider> mods = new HashMap JavaDoc<String JavaDoc, J2eeModuleProvider>();
603         for (VisualClassPathItem vcpi : getJarContentAdditional()) {
604             Object JavaDoc obj = vcpi.getObject();
605             Project p;
606             if (obj instanceof AntArtifact) {
607                 AntArtifact aa = (AntArtifact) obj;
608                 p = aa.getProject();
609             } else {
610                 continue;
611             }
612             J2eeModuleProvider jmp = (J2eeModuleProvider) p.getLookup().lookup(J2eeModuleProvider.class);
613             if (null != jmp) {
614                 J2eeModule jm = jmp.getJ2eeModule();
615                 if (null != jm) {
616                     String JavaDoc path = vcpi.getCompletePathInArchive(); // computePath(vcpi);
617
mods.put(path, jmp);
618                 }
619             }
620         }
621         return mods; // earProject.getAppModule().setModules(mods);
622
}
623
624
625     public void addJ2eeSubprojects(Project[] moduleProjects) {
626         List JavaDoc<AntArtifact> artifactList = new ArrayList JavaDoc<AntArtifact>();
627         for (int i = 0; i < moduleProjects.length; i++) {
628             AntArtifact artifacts[] = AntArtifactQuery.findArtifactsByType(
629                     moduleProjects[i],
630                     EjbProjectConstants.ARTIFACT_TYPE_J2EE_MODULE_IN_EAR_ARCHIVE); //the artifact type is the some for both ejb and war projects
631
if (null != artifacts) {
632                 artifactList.addAll(Arrays.asList(artifacts));
633             }
634         }
635         // create the vcpis
636
List JavaDoc<VisualClassPathItem> newVCPIs = new ArrayList JavaDoc<VisualClassPathItem>();
637         BrokenProjectSupport bps = (BrokenProjectSupport) earProject.getLookup().lookup(BrokenProjectSupport.class);
638         for (AntArtifact art : artifactList) {
639             VisualClassPathItem vcpi = VisualClassPathItem.createArtifact(art);
640             vcpi.setRaw(EarProjectProperties.JAR_CONTENT_ADDITIONAL);
641             newVCPIs.add(vcpi);
642             bps.watchAntArtifact(art);
643         }
644         List JavaDoc<VisualClassPathItem> vcpis = getJarContentAdditional();
645         newVCPIs.addAll(vcpis);
646         put(EarProjectProperties.JAR_CONTENT_ADDITIONAL, newVCPIs);
647         store();
648     }
649
650     /**
651      * Acquires modules form the earproject's deployment descriptor.
652      */

653     Module[] getApplicationModules() {
654         Module mods[] = null;
655         try {
656             Application app = DDProvider.getDefault().getDDRoot(
657                     earProject.getAppModule().getDeploymentDescriptor());
658             mods = app.getModule();
659         } catch (IOException JavaDoc ioe) {
660             ErrorManager.getDefault().log(ioe.getLocalizedMessage());
661         }
662         if (mods == null) {
663             mods = new Module[0];
664         }
665         return mods;
666     }
667     
668     public String JavaDoc[] getWebUris() {
669         Module mods[] = getApplicationModules();
670         Set JavaDoc<String JavaDoc> result = new TreeSet JavaDoc<String JavaDoc>();
671         for (int i = 0; i < mods.length; i++) {
672             Web w = mods[i].getWeb();
673             if (w != null) {
674                 result.add(w.getWebUri());
675             }
676         }
677         return result.toArray(new String JavaDoc[result.size()]);
678     }
679     
680     public String JavaDoc[] getAppClientUris() {
681         Module mods[] = getApplicationModules();
682         Set JavaDoc<String JavaDoc> result = new TreeSet JavaDoc<String JavaDoc>();
683         for (int i = 0; i < mods.length; i++) {
684             if (mods[i].getJava() != null) {
685                 String JavaDoc jarName = mods[i].getJava();
686                 String JavaDoc name = jarName.endsWith(".jar") // NOI18N
687
? jarName.substring(0, jarName.length() - 4) : jarName;
688                 // application client module
689
result.add(name);
690             }
691         }
692         return result.toArray(new String JavaDoc[result.size()]);
693     }
694     
695     boolean isWebUri(String JavaDoc uri) {
696         return uri != null && Arrays.binarySearch(getWebUris(), uri) >= 0;
697     }
698     
699     boolean isAppClientUri(String JavaDoc uri) {
700         return Arrays.binarySearch(getAppClientUris(), uri) >= 0;
701     }
702     
703      /** XXX to be deleted when introduced in AntPropertyHeleper API
704      */

705     static String JavaDoc getAntPropertyName( String JavaDoc property ) {
706         if ( property != null &&
707              property.startsWith( "${" ) && // NOI18N
708
property.endsWith( "}" ) ) { // NOI18N
709
return property.substring( 2, property.length() - 1 );
710         }
711         else {
712             return property;
713         }
714     }
715     
716      static boolean isAntProperty (String JavaDoc string) {
717         return string != null && string.startsWith( "${" ) && string.endsWith( "}" ); //NOI18N
718
}
719     
720    public void put( String JavaDoc propertyName, Object JavaDoc value ) {
721         assert propertyName != null : "Unknown property " + propertyName; // NOI18N
722
PropertyInfo pi = (PropertyInfo)properties.get( propertyName );
723         pi.setValue( value );
724         if (J2EE_SERVER_INSTANCE.equals (propertyName)) {
725             put (J2EE_SERVER_TYPE, Deployment.getDefault ().getServerID ((String JavaDoc) value));
726         }
727     }
728     
729     public Object JavaDoc get(String JavaDoc propertyName) {
730         assert propertyName != null : "Unknown property " + propertyName; // NOI18N
731
PropertyInfo pi = (PropertyInfo) properties.get(propertyName);
732         return pi == null ? null : pi.getValue();
733     }
734     
735     public boolean isModified( String JavaDoc propertyName ) {
736         PropertyInfo pi = (PropertyInfo)properties.get( propertyName );
737         assert propertyName != null : "Unknown property " + propertyName; // NOI18N
738
return pi.isModified();
739     }
740     
741     public List JavaDoc getSortedSubprojectsList() {
742         List JavaDoc<Project> subprojects = new ArrayList JavaDoc<Project>();
743         addSubprojects( earProject, subprojects ); // Find the projects recursively
744
String JavaDoc[] displayNames = new String JavaDoc[subprojects.size()];
745          
746         // Replace projects in the list with formated names
747
for ( int i = 0; i < subprojects.size(); i++ ) {
748             displayNames[i] = ProjectUtils.getInformation(subprojects.get(i)).getDisplayName();
749         }
750
751         Arrays.sort(displayNames, Collator.getInstance());
752         return Arrays.asList(displayNames);
753     }
754     
755     public EarProject getProject() {
756         return earProject;
757     }
758     
759     /** Gets all subprojects recursively
760      */

761     private void addSubprojects( Project project, List JavaDoc<Project> result ) {
762         SubprojectProvider spp = (SubprojectProvider)project.getLookup().lookup( SubprojectProvider.class );
763         
764         if ( spp == null ) {
765             return;
766         }
767         
768         for( Iterator JavaDoc/*<Project>*/ it = spp.getSubprojects().iterator(); it.hasNext(); ) {
769             Project sp = (Project) it.next();
770             if (ProjectUtils.hasSubprojectCycles(project, sp)) {
771                 ErrorManager.getDefault().log(ErrorManager.WARNING, "There would be cyclic " +
772                         "dependencies if the " + sp + " would be added. Skipping..."); // NOI18N
773
continue;
774             }
775             if ( !result.contains( sp ) ) {
776                 result.add( sp );
777             }
778             addSubprojects( sp, result );
779         }
780     }
781
782     /** Reads all the properties of the project and converts them to objects
783      * suitable for usage in the GUI controls.
784      */

785     private void read() {
786         // Read the properties from the project
787
Map JavaDoc<String JavaDoc, EditableProperties> eProps = new HashMap JavaDoc<String JavaDoc, EditableProperties>(2);
788         eProps.put( PROJECT, updateHelper.getProperties( PROJECT ) );
789         eProps.put( PRIVATE, updateHelper.getProperties( PRIVATE ) );
790    
791         // Initialize the property map with objects
792
for ( int i = 0; i < PROPERTY_DESCRIPTORS.length; i++ ) {
793             PropertyDescriptor pd = PROPERTY_DESCRIPTORS[i];
794             final String JavaDoc propertyName = pd.name;
795             if ( pd.dest == null ) {
796                 // Specially handled properties
797
if ( WEB_PROJECT_NAME.equals( propertyName ) ) {
798                     String JavaDoc projectName = ProjectUtils.getInformation(earProject).getDisplayName();
799                     PropertyInfo pi = (PropertyInfo) properties.get(propertyName);
800                     if (null == pi) {
801                         properties.put(propertyName, new PropertyInfo(pd, projectName, projectName));
802                     } else {
803                         pi.update(pd, projectName, projectName);
804                     }
805                 }
806             } else {
807                 // Standard properties
808
String JavaDoc raw = eProps.get( pd.dest ).getProperty( propertyName );
809                 String JavaDoc eval = antProjectHelper.getStandardPropertyEvaluator ().getProperty ( propertyName );
810                 PropertyInfo pi = (PropertyInfo) properties.get(propertyName);
811                 if (null == pi) {
812                     PropertyInfo propertyInfo = new PropertyInfo(pd, raw, eval);
813                     properties.put(propertyName, propertyInfo);
814                 } else {
815                     pi.update(pd, raw, eval);
816                 }
817             }
818         }
819     }
820
821     void initProperty(final String JavaDoc propertyName, final PropertyInfo propertyInfo) {
822         properties.put(propertyName, propertyInfo);
823     }
824     
825     /**
826      * Transforms all the Objects from GUI controls into String Ant properties
827      * and stores them in the project.
828      */

829     public void store() {
830         try {
831             // Store properties
832
Boolean JavaDoc result = (Boolean JavaDoc) ProjectManager.mutex().writeAccess(new Mutex.ExceptionAction() {
833                 public Object JavaDoc run() throws IOException JavaDoc {
834                     URL JavaDoc buildImplXSL = EarProject.class.getResource("resources/build-impl.xsl");
835                     int state = genFilesHelper.getBuildScriptState(
836                             GeneratedFilesHelper.BUILD_IMPL_XML_PATH, buildImplXSL);
837                     if ((state & GeneratedFilesHelper.FLAG_MODIFIED) == GeneratedFilesHelper.FLAG_MODIFIED) {
838                         if (showModifiedMessage(NbBundle.getMessage(EarProjectProperties.class,"TXT_ModifiedTitle"))) {
839                             //Delete user modified build-impl.xml
840
FileObject fo = updateHelper.getAntProjectHelper().getProjectDirectory().
841                                     getFileObject(GeneratedFilesHelper.BUILD_IMPL_XML_PATH);
842                             if (fo != null) {
843                                 fo.delete();
844                                 genFilesHelper.refreshBuildScript(
845                                         GeneratedFilesHelper.BUILD_IMPL_XML_PATH,
846                                         buildImplXSL,
847                                         false);
848                             }
849                         } else {
850                             return false;
851                         }
852                     }
853                     storeProperties();
854                     return true;
855                 }
856             });
857             // and save the project
858
if (result) {
859                 ProjectManager.getDefault().saveProject(earProject);
860             }
861         } catch (MutexException e) {
862             ErrorManager.getDefault().notify((IOException JavaDoc)e.getException());
863         } catch ( IOException JavaDoc ex ) {
864             ErrorManager.getDefault().notify( ex );
865         }
866     }
867     
868     private void storeProperties() {
869         resolveProjectDependencies();
870         Boolean JavaDoc defaultPlatform = null;
871         
872         // Some properties need special handling e.g. if the
873
// property changes the project.xml files
874
for (Iterator JavaDoc it = properties.values().iterator(); it.hasNext();) {
875             PropertyInfo pi = (PropertyInfo) it.next();
876             PropertyDescriptor pd = pi.getPropertyDescriptor();
877             pi.encode();
878             String JavaDoc newValueEncoded = pi.getNewValueEncoded();
879             if(pd.saver != null) {
880                 pd.saver.save(pi);
881             }
882             if (pd.dest == null && newValueEncoded != null && WEB_PROJECT_NAME.equals(pd.name)) {
883                 assert false : "No support yet for changing name of J2SEProject; cf. J2SEProject.setName"; //NOI18N
884
}
885             
886             if (JAVA_PLATFORM.equals(pd.name) && newValueEncoded != null) {
887                 defaultPlatform =
888                         Boolean.valueOf(pi.getNewValueEncoded().equals(JavaPlatformManager.getDefault()
889                         .getDefaultPlatform()
890                         .getProperties()
891                         .get("platform.ant.name"))); // NOI18N
892
setPlatform(defaultPlatform.booleanValue(), pi.getNewValueEncoded());
893             }
894         }
895         
896         // Reread the properties. It may have changed when
897
// e.g. when setting references to another projects
898
Map JavaDoc<String JavaDoc, EditableProperties> eProps = new HashMap JavaDoc<String JavaDoc, EditableProperties>(2);
899         eProps.put(PROJECT, updateHelper.getProperties(PROJECT));
900         eProps.put(PRIVATE, updateHelper.getProperties(PRIVATE));
901         
902         //generate library content references into private.properties
903
for (Iterator JavaDoc it = properties.values().iterator(); it.hasNext();) {
904             PropertyInfo pi = (PropertyInfo) it.next();
905             PropertyDescriptor pd = pi.getPropertyDescriptor();
906             if(JAR_CONTENT_ADDITIONAL.equals(pd.name)) {
907                 //FIX of #58079 - newValue is null when the store() is called from resolve references dialog
908
Object JavaDoc piValue = (pi.newValue != null ? pi.newValue : pd.parser.decode(pi.evaluatedValue, antProjectHelper, refHelper ));
909                 if(piValue != null) {
910                     //add an entry into private properties
911
@SuppressWarnings JavaDoc("unchecked")
912                     Iterator JavaDoc<VisualClassPathItem> newItems = ((List JavaDoc)piValue).iterator();
913                     @SuppressWarnings JavaDoc("unchecked")
914                     Iterator JavaDoc<VisualClassPathItem> oldItems = ((List JavaDoc)pi.value).iterator();
915                     storeLibrariesLocations(newItems, oldItems, eProps.get(PRIVATE));
916                     break;
917                 }
918             }
919         }
920         
921         // Set the changed properties
922
for (Iterator JavaDoc it = properties.values().iterator(); it.hasNext();) {
923             PropertyInfo pi = (PropertyInfo) it.next();
924             PropertyDescriptor pd = pi.getPropertyDescriptor();
925             String JavaDoc newValueEncoded = pi.getNewValueEncoded();
926             if (newValueEncoded != null && pd.dest != null) {
927                 // Standard properties
928
EditableProperties ep = eProps.get(pd.dest);
929                 // if (PATH_PARSER.equals(pd.parser)) {
930
if (pd.parser instanceof PathParser) {
931                     // XXX: perhaps PATH_PARSER could return List of paths so that
932
// tokenizing could be omitted here:
933
String JavaDoc[] items = PropertyUtils.tokenizePath(newValueEncoded);
934                     for (int i = 0; i < items.length - 1; i++) {
935                         items[i] += File.pathSeparatorChar;
936                     }
937                     ep.setProperty(pd.name, items);
938                 } else if (NO_DEPENDENCIES.equals(pd.name) && newValueEncoded.equals("false")) { // NOI18N
939
ep.remove(pd.name);
940                 } else if (CLIENT_MODULE_URI.equals(pd.name)) {
941                     if (isWebUri(newValueEncoded)) {
942                         // web module selected
943
ep.setProperty(CLIENT_MODULE_URI, newValueEncoded);
944                         ep.remove(APPLICATION_CLIENT);
945                     } else if (isAppClientUri(newValueEncoded)) {
946                         // application module selected
947
ep.setProperty(APPLICATION_CLIENT, newValueEncoded);
948                         ep.setProperty(CLIENT_MODULE_URI, getClientModuleUriForAppClient());
949                     } else {
950                         // may happen if e.g. currently set module is removed
951
ep.remove(APPLICATION_CLIENT);
952                         ep.remove(CLIENT_MODULE_URI);
953                     }
954                 } else {
955                     if (JAVA_PLATFORM.equals(pd.name)) { // update javac.source and javac.target
956
assert defaultPlatform != null;
957                         updateSourceLevel(defaultPlatform.booleanValue(), newValueEncoded, ep);
958                     } else if (JAVAC_CLASSPATH.equals(pd.name)) {
959                         writeWebLibraries(refHelper, (List JavaDoc) pi.getValue(),
960                                 TAG_WEB_MODULE_LIBRARIES);
961                     } else if (JAR_CONTENT_ADDITIONAL.equals(pd.name)) {
962                         writeWebLibraries(refHelper, (List JavaDoc) pi.getValue(),
963                                 TAG_WEB_MODULE__ADDITIONAL_LIBRARIES);
964                     } else if (J2EE_SERVER_INSTANCE.equals(pd.name)) {
965                         String JavaDoc serverInstanceID = (String JavaDoc) pi.getValue();
966                         
967                         // ant deployment support
968
File JavaDoc projectFolder = FileUtil.toFile(earProject.getProjectDirectory());
969                         try {
970                             AntDeploymentHelper.writeDeploymentScript(new File JavaDoc(projectFolder, ANT_DEPLOY_BUILD_SCRIPT), J2eeModule.EAR, serverInstanceID);
971                         } catch (IOException JavaDoc ioe) {
972                             ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ioe);
973                         }
974                         File JavaDoc deployAntPropsFile = AntDeploymentHelper.getDeploymentPropertiesFile(serverInstanceID);
975                         if (deployAntPropsFile == null) {
976                             ep.remove(DEPLOY_ANT_PROPS_FILE);
977                         } else {
978                             ep.setProperty(DEPLOY_ANT_PROPS_FILE, deployAntPropsFile.getAbsolutePath());
979                         }
980                         
981                         J2eePlatform j2eePlatform = Deployment.getDefault().getJ2eePlatform(serverInstanceID);
982                         EarProjectProperties.setACProperties(j2eePlatform, eProps.get(PROJECT));
983                         EarProjectProperties.setACPrivateProperties(j2eePlatform, serverInstanceID, eProps.get(PRIVATE));
984                     }
985                     ep.setProperty(pd.name, newValueEncoded);
986                 }
987             }
988         }
989         
990         // Store the property changes into the project
991
updateHelper.putProperties(PROJECT, eProps.get(PROJECT));
992         updateHelper.putProperties(PRIVATE, eProps.get(PRIVATE));
993     }
994     
995     String JavaDoc getClientModuleUriForAppClient() {
996         PropertyInfo earNamePI = (PropertyInfo) properties.get(JAR_NAME);
997         assert earNamePI != null;
998         String JavaDoc earName = (String JavaDoc) earNamePI.getValue();
999         assert earName != null;
1000        if (earName.endsWith(".ear")) { // NOI18N
1001
earName = earName.substring(0, earName.length() - 4);
1002        }
1003        return earName + "/${" + APPLICATION_CLIENT + '}'; // NOI18N
1004
}
1005
1006    public static void setACProperties(final J2eePlatform j2eePlatform, final EditableProperties ep) {
1007        String JavaDoc mainClassArgs = j2eePlatform.getToolProperty(J2eePlatform.TOOL_APP_CLIENT_RUNTIME, J2eePlatform.TOOL_PROP_MAIN_CLASS_ARGS);
1008        if (mainClassArgs != null && !mainClassArgs.equals("")) {
1009            ep.put(APPCLIENT_MAINCLASS_ARGS, mainClassArgs);
1010            ep.remove(CLIENT_NAME);
1011        } else if ((mainClassArgs = j2eePlatform.getToolProperty(J2eePlatform.TOOL_APP_CLIENT_RUNTIME, CLIENT_NAME)) != null) {
1012            ep.put(CLIENT_NAME, mainClassArgs);
1013            ep.remove(APPCLIENT_MAINCLASS_ARGS);
1014        } else {
1015            ep.remove(APPCLIENT_MAINCLASS_ARGS);
1016            ep.remove(CLIENT_NAME);
1017        }
1018    }
1019    
1020    private void setAndSaveACPrivateProperties(final String JavaDoc servInstIDs, final J2eePlatform platform) {
1021        ProjectManager.mutex().writeAccess(new Runnable JavaDoc() {
1022            public void run() {
1023                try {
1024                    EditableProperties priv = updateHelper.getProperties(PRIVATE);
1025                    setACPrivateProperties(platform, servInstIDs, priv);
1026                    updateHelper.putProperties(PRIVATE, priv);
1027                    ProjectManager.getDefault().saveProject(earProject);
1028                } catch (IOException JavaDoc e) {
1029                    ErrorManager.getDefault().notify(e);
1030                }
1031            }
1032        });
1033    }
1034    
1035    public static void setACPrivateProperties(final J2eePlatform j2eePlatform,
1036            final String JavaDoc serverInstanceID, final EditableProperties ep) {
1037        // XXX rather hotfix for #75518. Get rid of it with fixing or #75574
1038
if (!j2eePlatform.getSupportedModuleTypes().contains(J2eeModule.CLIENT)) {
1039            return;
1040        }
1041        File JavaDoc[] accrt = j2eePlatform.getToolClasspathEntries(J2eePlatform.TOOL_APP_CLIENT_RUNTIME);
1042        ep.setProperty(APPCLIENT_TOOL_RUNTIME, EarProjectGenerator.toClasspathString(accrt));
1043        
1044        String JavaDoc mainClass = j2eePlatform.getToolProperty(J2eePlatform.TOOL_APP_CLIENT_RUNTIME, J2eePlatform.TOOL_PROP_MAIN_CLASS);
1045        if (mainClass != null) {
1046            ep.setProperty(APPCLIENT_TOOL_MAINCLASS, mainClass);
1047        }
1048        
1049        String JavaDoc jvmOpts = j2eePlatform.getToolProperty(J2eePlatform.TOOL_APP_CLIENT_RUNTIME, J2eePlatform.TOOL_PROP_JVM_OPTS);
1050        if (jvmOpts != null) {
1051            ep.setProperty(APPCLIENT_TOOL_JVMOPTS, jvmOpts);
1052        }
1053        
1054        String JavaDoc args = j2eePlatform.getToolProperty(J2eePlatform.TOOL_APP_CLIENT_RUNTIME, J2EE_PLATFORM_APPCLIENT_ARGS);
1055        if (args != null) {
1056            ep.setProperty(APPCLIENT_TOOL_ARGS, args);
1057        }
1058        
1059        // set j2ee.platform.classpath
1060
String JavaDoc classpath = EarProjectGenerator.toClasspathString(j2eePlatform.getClasspathEntries());
1061        ep.setProperty("j2ee.platform.classpath", classpath); // NOI18N
1062

1063        //WORKAROUND for --retrieve option in asadmin deploy command
1064
//works only for local domains
1065
//see also http://www.netbeans.org/issues/show_bug.cgi?id=82929
1066
File JavaDoc asRoot = j2eePlatform.getPlatformRoots()[0];
1067        InstanceProperties ip = InstanceProperties.getInstanceProperties(serverInstanceID);
1068        //check if we have AS
1069
if (ip != null && new File JavaDoc(asRoot, "lib/admin-cli.jar").exists()) { // NOI18N
1070
File JavaDoc exFile = new File JavaDoc(asRoot, "lib/javaee.jar"); // NOI18N
1071
if (exFile.exists()) {
1072                ep.setProperty(APPCLIENT_WA_COPY_CLIENT_JAR_FROM,
1073                        new File JavaDoc(ip.getProperty("LOCATION"), ip.getProperty("DOMAIN") + "/generated/xml/j2ee-apps").getAbsolutePath()); // NOI18N
1074
} else {
1075                ep.setProperty(APPCLIENT_WA_COPY_CLIENT_JAR_FROM,
1076                        new File JavaDoc(ip.getProperty("LOCATION"), ip.getProperty("DOMAIN") + "/applications/j2ee-apps").getAbsolutePath()); // NOI18N
1077
}
1078        } else {
1079            ep.remove(APPCLIENT_WA_COPY_CLIENT_JAR_FROM);
1080        }
1081        
1082    }
1083    
1084    private void updateSourceLevel(boolean defaultPlatform, String JavaDoc platform, EditableProperties ep) {
1085        if (defaultPlatform) {
1086            ep.setProperty(JAVAC_SOURCE, "${default.javac.source}"); //NOI18N
1087
ep.setProperty(JAVAC_TARGET, "${default.javac.target}"); //NOI18N
1088
} else {
1089            JavaPlatform[] platforms = JavaPlatformManager.getDefault().getInstalledPlatforms();
1090            for( int i = 0; i < platforms.length; i++ ) {
1091                Specification spec = platforms[i].getSpecification();
1092                if (!("j2se".equalsIgnoreCase(spec.getName()))) { // NOI18N
1093
continue;
1094                }
1095                if (platform.equals(platforms[i].getProperties().get("platform.ant.name"))) { //NOI18N
1096
String JavaDoc ver = platforms[i].getSpecification().getVersion().toString();
1097                    ep.setProperty(JAVAC_SOURCE, ver);
1098                    ep.setProperty(JAVAC_TARGET, ver);
1099                    return;
1100                }
1101            }
1102            // The platform does not exist. Perhaps this is project with broken references?
1103
// Do not update target and source because nothing is known about the platform.
1104
}
1105    }
1106    
1107    private final SpecificationVersion JDKSpec13 = new SpecificationVersion("1.3"); // NOI18N
1108

1109    private void setPlatform(boolean isDefault, String JavaDoc platformAntID) {
1110        Element JavaDoc pcd = updateHelper.getPrimaryConfigurationData( true );
1111        NodeList JavaDoc sps = pcd.getElementsByTagName( "explicit-platform" ); // NOI18N
1112
if (isDefault && sps.getLength() > 0) {
1113            pcd.removeChild(sps.item(0));
1114        } else if (!isDefault) {
1115            Element JavaDoc el;
1116            if (sps.getLength() == 0) {
1117                el = pcd.getOwnerDocument().createElement("explicit-platform"); // NOI18N
1118
pcd.appendChild(el);
1119            } else {
1120                el = (Element JavaDoc)sps.item(0);
1121            }
1122            boolean explicitSource = true;
1123            JavaPlatform platform = findPlatform(platformAntID);
1124            if ((platform != null && platform.getSpecification().getVersion().compareTo(JDKSpec13) <= 0) || platform == null) {
1125                explicitSource = false;
1126            }
1127            el.setAttribute("explicit-source-supported", explicitSource ? "true" : "false"); // NOI18N
1128
}
1129        updateHelper.putPrimaryConfigurationData(pcd, true);
1130    }
1131    
1132    public void ensurePlatformIsSet(final boolean showAlert) throws IOException JavaDoc {
1133        final String JavaDoc servInstID = (String JavaDoc) get(EarProjectProperties.J2EE_SERVER_INSTANCE);
1134        J2eePlatform platform = Deployment.getDefault().getJ2eePlatform(servInstID);
1135        if (platform == null) {
1136            // if there is some server instance of the type which was used
1137
// previously do not ask and use it
1138
String JavaDoc serverType = (String JavaDoc) get(EarProjectProperties.J2EE_SERVER_TYPE);
1139            if (serverType != null) {
1140                String JavaDoc[] servInstIDs = Deployment.getDefault().getInstancesOfServer(serverType);
1141                if (servInstIDs.length > 0) {
1142                    EarProjectProperties.setServerInstance(earProject, earProject.getUpdateHelper(), servInstIDs[0]);
1143                    platform = Deployment.getDefault().getJ2eePlatform(servInstIDs[0]);
1144                    if (platform != null) {
1145                        setAndSaveACPrivateProperties(servInstIDs[0], platform);
1146                    }
1147                }
1148            }
1149            if (showAlert && platform == null) {
1150                BrokenServerSupport.showAlert();
1151            }
1152        } else {
1153            // if the project server instance exists, make sure that the Ant deployment
1154
// support is present, #85749
1155
ProjectManager.mutex().writeAccess(new Runnable JavaDoc() {
1156                public void run() {
1157                    EditableProperties privateProps = updateHelper.getProperties(PRIVATE);
1158                    boolean changed = generateAntDeploymentSupport(privateProps, earProject.getProjectDirectory(), servInstID, false);
1159                    if (changed) {
1160                        updateHelper.putProperties(PRIVATE, privateProps);
1161                        try {
1162                            ProjectManager.getDefault().saveProject(earProject);
1163                        } catch (IOException JavaDoc e) {
1164                            ErrorManager.getDefault().notify(e);
1165                        }
1166                    }
1167                }
1168            });
1169        }
1170    }
1171    
1172    /**
1173     * Generates the Ant deployment script and sets the respective properties
1174     *
1175     * @param privateProps private properties
1176     * @param projectDirectory the project directory
1177     * @param serverInstanceID the server instance ID
1178     * @param force if true the Ant deployment script is always (re)generated,
1179     * otherwise only if it does not exist
1180     *
1181     * @return true if the private properties changed and should be saved, false
1182     * otherwise.
1183     */

1184    private static boolean generateAntDeploymentSupport(EditableProperties privateProps,
1185            FileObject projectDirectory, String JavaDoc serverInstanceID, boolean force) {
1186        
1187        // check the Ant deployment script
1188
try {
1189            File JavaDoc projectDir = FileUtil.toFile(projectDirectory);
1190            File JavaDoc antDeploymentScript = new File JavaDoc(projectDir, ANT_DEPLOY_BUILD_SCRIPT);
1191            if (force || !antDeploymentScript.exists()) {
1192                AntDeploymentHelper.writeDeploymentScript(antDeploymentScript, J2eeModule.EAR, serverInstanceID);
1193            }
1194        } catch (IOException JavaDoc ioe) {
1195            ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ioe);
1196        }
1197        
1198        // check the Ant deployment properties
1199
File JavaDoc deployAntPropsFile = AntDeploymentHelper.getDeploymentPropertiesFile(serverInstanceID);
1200        
1201        String JavaDoc newDeployAntPropsFilePath = (deployAntPropsFile == null) ? null : deployAntPropsFile.getAbsolutePath();
1202        String JavaDoc oldDeployAntPropsFilePath = privateProps.getProperty(DEPLOY_ANT_PROPS_FILE);
1203        
1204        if (oldDeployAntPropsFilePath != null && newDeployAntPropsFilePath == null) {
1205            privateProps.remove(DEPLOY_ANT_PROPS_FILE);
1206        } else if (newDeployAntPropsFilePath != null && !newDeployAntPropsFilePath.equals(oldDeployAntPropsFilePath)) {
1207            privateProps.setProperty(DEPLOY_ANT_PROPS_FILE, newDeployAntPropsFilePath);
1208        } else {
1209            // private properties did not change
1210
return false;
1211        }
1212        // private properties changed
1213
return true;
1214    }
1215    
1216    public static void setServerInstance(final Project project, final UpdateHelper helper, final String JavaDoc serverInstanceID) {
1217        ProjectManager.mutex().writeAccess(new Runnable JavaDoc() {
1218            public void run() {
1219                try {
1220                    EditableProperties projectProps = helper.getProperties(PROJECT);
1221                    EditableProperties privateProps = helper.getProperties(PRIVATE);
1222                    
1223                    // update j2ee.server.type & j2ee.server.instance
1224
projectProps.setProperty(J2EE_SERVER_TYPE, Deployment.getDefault().getServerID(serverInstanceID));
1225                    privateProps.setProperty(J2EE_SERVER_INSTANCE, serverInstanceID);
1226
1227                    // ant deployment support
1228
generateAntDeploymentSupport(privateProps, project.getProjectDirectory(), serverInstanceID, true);
1229
1230                    helper.putProperties(PROJECT, projectProps);
1231                    helper.putProperties(PRIVATE, privateProps);
1232                    ProjectManager.getDefault().saveProject(project);
1233                }
1234                catch (IOException JavaDoc e) {
1235                    ErrorManager.getDefault().notify(e);
1236                }
1237            }
1238        });
1239    }
1240    
1241    /** Finds out what are new and removed project dependencies and
1242     * applies the info to the project
1243     */

1244    private void resolveProjectDependencies() {
1245    
1246        String JavaDoc allPaths[] = { JAVAC_CLASSPATH, JAR_CONTENT_ADDITIONAL, RUN_CLASSPATH };
1247        
1248        // Create a set of old and new artifacts.
1249
Set JavaDoc<VisualClassPathItem> oldArtifacts = new HashSet JavaDoc<VisualClassPathItem>();
1250        Set JavaDoc<VisualClassPathItem> newArtifacts = new HashSet JavaDoc<VisualClassPathItem>();
1251        for ( int i = 0; i < allPaths.length; i++ ) {
1252            PropertyInfo pi = (PropertyInfo)properties.get( allPaths[i] );
1253
1254            // Get original artifacts
1255
@SuppressWarnings JavaDoc("unchecked")
1256            List JavaDoc<VisualClassPathItem> oldList = (List JavaDoc)pi.getOldValue();
1257            if ( oldList != null ) {
1258                oldArtifacts.addAll(oldList);
1259            }
1260            
1261            // Get artifacts after the edit
1262
@SuppressWarnings JavaDoc("unchecked")
1263            List JavaDoc<VisualClassPathItem> newList = (List JavaDoc) pi.getValue();
1264            if ( newList != null ) {
1265                newArtifacts.addAll(newList);
1266            }
1267                        
1268        }
1269
1270        // Create set of removed artifacts and remove them
1271
Set JavaDoc<VisualClassPathItem> removed = new HashSet JavaDoc<VisualClassPathItem>(oldArtifacts);
1272        removed.removeAll( newArtifacts );
1273        Set JavaDoc<VisualClassPathItem> added = new HashSet JavaDoc<VisualClassPathItem>(newArtifacts);
1274        added.removeAll(oldArtifacts);
1275        
1276        @SuppressWarnings JavaDoc("unchecked")
1277        Set JavaDoc<VisualClassPathItem> oldContent = new HashSet JavaDoc<VisualClassPathItem>(
1278                (List JavaDoc)((PropertyInfo) properties.get(JAR_CONTENT_ADDITIONAL)).getOldValue());
1279        @SuppressWarnings JavaDoc("unchecked")
1280        Set JavaDoc<VisualClassPathItem> newContent = new HashSet JavaDoc<VisualClassPathItem>(
1281                (List JavaDoc) ((PropertyInfo) properties.get(JAR_CONTENT_ADDITIONAL)).getValue());
1282        
1283        updateContentDependency(oldContent, newContent);
1284        
1285        // 1. first remove all project references. The method will modify
1286
// project property files, so it must be done separately
1287
for (VisualClassPathItem vcpi : removed) {
1288            if ( vcpi.getType() == VisualClassPathItem.Type.ARTIFACT ||
1289                    vcpi.getType() == VisualClassPathItem.Type.JAR ) {
1290                boolean used = false; // now check if the file reference isn't used anymore
1291
for (int i=0; i < allPaths.length; i++) {
1292                    PropertyInfo pi = (PropertyInfo)properties.get( allPaths[i] );
1293                    @SuppressWarnings JavaDoc("unchecked")
1294                    List JavaDoc<VisualClassPathItem> values = (List JavaDoc) pi.getOldValue();
1295                    if (values == null) {
1296                        break;
1297                    }
1298                    for (VisualClassPathItem valcpi : values) {
1299                        if (valcpi.getRaw().indexOf(vcpi.getRaw()) > -1) {
1300                            used = true;
1301                            break;
1302                        }
1303                    }
1304                }
1305                if (!used) {
1306                    refHelper.destroyReference(vcpi.getRaw());
1307                }
1308                
1309            }
1310        }
1311        
1312        // 2. now read project.properties and modify rest
1313
EditableProperties ep = updateHelper.getProperties( PROJECT );
1314        boolean changed = false;
1315
1316        for (VisualClassPathItem vcpi : removed) {
1317            if (vcpi.getType() == VisualClassPathItem.Type.LIBRARY) {
1318                // remove helper property pointing to library jar if there is any
1319
String JavaDoc prop = vcpi.getRaw();
1320                prop = prop.substring(2, prop.length()-1);
1321                ep.remove(prop);
1322                changed = true;
1323            }
1324        }
1325        File JavaDoc projDir = FileUtil.toFile(antProjectHelper.getProjectDirectory());
1326        for (VisualClassPathItem vcpi : added) {
1327            if (vcpi.getType() == VisualClassPathItem.Type.LIBRARY) {
1328                // add property to project.properties pointing to relativized
1329
// library jar(s) if possible
1330
String JavaDoc prop = vcpi.getRaw();
1331                prop = prop.substring(2, prop.length()-1);
1332                String JavaDoc value = relativizeLibraryClasspath(prop, projDir);
1333                if (value != null) {
1334                    ep.setProperty(prop, value);
1335                    ep.setComment(prop, new String JavaDoc[]{
1336                        "# Property "+prop+" is set here just to make sharing of project simpler.", // NOI18N
1337
"# The library definition has always preference over this property."}, false); // NOI18N
1338
changed = true;
1339                }
1340            }
1341        }
1342        if (changed) {
1343            updateHelper.putProperties(PROJECT, ep);
1344        }
1345    }
1346        
1347      /**
1348     * Tokenize library classpath and try to relativize all the jars.
1349     * @param property library property name ala "libs.someLib.classpath"
1350     * @param projectDir project dir for relativization
1351     * @return relativized library classpath or null if some jar is not collocated
1352     */

1353    private String JavaDoc relativizeLibraryClasspath(String JavaDoc property, File JavaDoc projectDir) {
1354        String JavaDoc value = PropertyUtils.getGlobalProperties().getProperty(property);
1355        // bugfix #42852, check if the classpath property is set, otherwise return null
1356
if (value == null) {
1357            return null;
1358        }
1359        String JavaDoc[] paths = PropertyUtils.tokenizePath(value);
1360        StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
1361        for (int i=0; i<paths.length; i++) {
1362            File JavaDoc f = antProjectHelper.resolveFile(paths[i]);
1363            if (CollocationQuery.areCollocated(f, projectDir)) {
1364                sb.append(PropertyUtils.relativizeFile(projectDir, f));
1365            } else {
1366                return null;
1367            }
1368            if (i+1<paths.length) {
1369                sb.append(File.pathSeparatorChar);
1370            }
1371        }
1372        if (sb.length() == 0) {
1373            return null;
1374        } else {
1375            return sb.toString();
1376        }
1377    }
1378    
1379    private class PropertyInfo {
1380        
1381        private PropertyDescriptor propertyDesciptor;
1382        private Object JavaDoc value;
1383        private String JavaDoc evaluatedValue;
1384        private Object JavaDoc newValue;
1385        private String JavaDoc newValueEncoded;
1386        
1387        public PropertyInfo( PropertyDescriptor propertyDescriptor, String JavaDoc rawValue, String JavaDoc evaluatedValue) {
1388            update(propertyDescriptor, rawValue, evaluatedValue);
1389        }
1390        
1391        final void update(PropertyDescriptor propertyDescriptor, String JavaDoc rawValue, String JavaDoc evaluatedValue) {
1392            this.propertyDesciptor = propertyDescriptor;
1393            this.evaluatedValue = evaluatedValue;
1394            this.value = propertyDesciptor.parser.decode( rawValue, antProjectHelper, refHelper );
1395        }
1396        
1397        public PropertyDescriptor getPropertyDescriptor() {
1398            return propertyDesciptor;
1399        }
1400        
1401        public void encode() {
1402            if ( isModified() ) {
1403                newValueEncoded = propertyDesciptor.parser.encode( newValue, antProjectHelper, refHelper);
1404            }
1405            else {
1406                newValueEncoded = null;
1407            }
1408        }
1409        
1410        public Object JavaDoc getValue() {
1411            return isModified() ? newValue : value;
1412        }
1413        
1414        public void setValue( Object JavaDoc value ) {
1415            newValue = value;
1416        }
1417        
1418        public String JavaDoc getNewValueEncoded() {
1419            return newValueEncoded;
1420        }
1421        
1422        public boolean isModified() {
1423            return newValue != null;
1424        }
1425        
1426        public Object JavaDoc getOldValue() {
1427            return value;
1428        }
1429    }
1430    
1431    static class PropertyDescriptor {
1432        
1433        interface Saver {
1434            void save(PropertyInfo propertyInfo);
1435        }
1436        
1437        final PropertyParser parser;
1438        final String JavaDoc name;
1439        final String JavaDoc dest;
1440        final Saver saver;
1441
1442        /**
1443         * @param name name of the property
1444         * @param dest either {@link AntProjectHelper#PROJECT_PROPERTIES_PATH}
1445         * or {@link AntProjectHelper#PRIVATE_PROPERTIES_PATH}.
1446         */

1447        PropertyDescriptor(String JavaDoc name, String JavaDoc dest, PropertyParser parser, Saver saver) {
1448            this.name = name;
1449            this.dest = dest;
1450            this.saver = saver;
1451            this.parser = parser;
1452        }
1453        
1454        /**
1455         * Delegates to {@link PropertyDescriptor(String, String, PropertyParser, Saver)}
1456         * with <code>null</code> for <code>saver parameter</code>.
1457         */

1458        PropertyDescriptor( String JavaDoc name, String JavaDoc dest, PropertyParser parser ) {
1459            this(name, dest, parser, null);
1460        }
1461        
1462    }
1463    
1464    private static abstract class PropertyParser {
1465        
1466        public abstract Object JavaDoc decode( String JavaDoc raw, AntProjectHelper antProjectHelper, ReferenceHelper refHelper );
1467        
1468        public abstract String JavaDoc encode( Object JavaDoc value, AntProjectHelper antProjectHelper, ReferenceHelper refHelper );
1469        
1470    }
1471    
1472    private static class StringParser extends PropertyParser {
1473        
1474        public Object JavaDoc decode(String JavaDoc raw, AntProjectHelper antProjectHelper, ReferenceHelper refHelper ) {
1475            return raw;
1476        }
1477        
1478        public String JavaDoc encode(Object JavaDoc value, AntProjectHelper antProjectHelper, ReferenceHelper refHelper ) {
1479            return (String JavaDoc)value;
1480        }
1481        
1482    }
1483    
1484    private static class BooleanParser extends PropertyParser {
1485        
1486        public Object JavaDoc decode(String JavaDoc raw, AntProjectHelper antProjectHelper, ReferenceHelper refHelper ) {
1487            
1488            if ( raw != null ) {
1489                String JavaDoc lowecaseRaw = raw.toLowerCase();
1490                
1491                if ( lowecaseRaw.equals( "true") || // NOI18N
1492
lowecaseRaw.equals( "yes") || // NOI18N
1493
lowecaseRaw.equals( "enabled") ) { // NOI18N
1494
return Boolean.TRUE;
1495                }
1496            }
1497            
1498            return Boolean.FALSE;
1499        }
1500        
1501        public String JavaDoc encode(Object JavaDoc value, AntProjectHelper antProjectHelper, ReferenceHelper refHelper ) {
1502            return ((Boolean JavaDoc)value).booleanValue() ? "true" : "false"; // NOI18N
1503
}
1504        
1505    }
1506    
1507    private static class InverseBooleanParser extends BooleanParser {
1508        
1509        public Object JavaDoc decode(String JavaDoc raw, AntProjectHelper antProjectHelper, ReferenceHelper refHelper ) {
1510            return ((Boolean JavaDoc)super.decode( raw, antProjectHelper, refHelper )).booleanValue() ? Boolean.FALSE : Boolean.TRUE;
1511        }
1512        
1513        public String JavaDoc encode(Object JavaDoc value, AntProjectHelper antProjectHelper, ReferenceHelper refHelper ) {
1514            return super.encode( ((Boolean JavaDoc)value).booleanValue() ? Boolean.FALSE : Boolean.TRUE, antProjectHelper, refHelper );
1515        }
1516        
1517    }
1518    
1519    // XXX Define in the LibraryManager
1520
private static final String JavaDoc LIBRARY_PREFIX = "${libs."; // NOI18N
1521
private static final String JavaDoc ANT_ARTIFACT_PREFIX = "${reference."; // NOI18N
1522

1523    // Contains well known paths in the J2SEProject
1524
private static final String JavaDoc[][] WELL_KNOWN_PATHS = new String JavaDoc[][] {
1525        { JAVAC_CLASSPATH, NbBundle.getMessage( EarProjectProperties.class, "LBL_JavacClasspath_DisplayName" ) } //NOI18N
1526
};
1527    
1528    private class PathParser extends PropertyParser {
1529        private final String JavaDoc webLibraryElementName;
1530        private static final String JavaDoc TAG_PATH_IN_EAR = "path-in-war"; //NOI18N
1531
private static final String JavaDoc TAG_FILE = "file"; //NOI18N
1532
private static final String JavaDoc TAG_LIBRARY = "library"; //NOI18N
1533

1534        public PathParser() {
1535            this(null);
1536        }
1537
1538        public PathParser(String JavaDoc webLibraryElementName) {
1539            this.webLibraryElementName = webLibraryElementName;
1540        }
1541
1542        public Object JavaDoc decode(String JavaDoc raw, AntProjectHelper antProjectHelper, ReferenceHelper refHelper ) {
1543            Map JavaDoc<String JavaDoc, String JavaDoc> earIncludesMap = createEarIncludesMap();
1544            if (raw != null) {
1545                String JavaDoc pe[] = PropertyUtils.tokenizePath( raw );
1546                for( int i = 0; i < pe.length; i++ ) {
1547                    final String JavaDoc pathItem = pe[i];
1548                    if (!earIncludesMap.containsKey(pathItem)) {
1549                        earIncludesMap.put(pathItem, VisualClassPathItem.PATH_IN_EAR); // NONE);
1550
}
1551                }
1552            }
1553            List JavaDoc<VisualClassPathItem> cpItems = new ArrayList JavaDoc<VisualClassPathItem>(earIncludesMap.size() );
1554            for (Map.Entry JavaDoc<String JavaDoc, String JavaDoc> entry : earIncludesMap.entrySet()) {
1555                cpItems.add(createVisualClassPathItem(antProjectHelper, refHelper,
1556                        entry.getKey(), entry.getValue()));
1557            }
1558            return cpItems;
1559        }
1560
1561        public String JavaDoc encode( Object JavaDoc value, AntProjectHelper antProjectHelper, ReferenceHelper refHelper ) {
1562            Element JavaDoc data = null;
1563            Element JavaDoc webModuleLibs = null;
1564            Document JavaDoc doc = null;
1565            if(webLibraryElementName != null) {
1566                final String JavaDoc ns = abpt.getPrimaryConfigurationDataElementNamespace(true);
1567                data = updateHelper.getPrimaryConfigurationData(true);
1568                doc = data.getOwnerDocument();
1569                webModuleLibs = (Element JavaDoc) data.getElementsByTagNameNS(ns,
1570                                    webLibraryElementName).item(0);
1571                //prevent NPE thrown from older projects
1572
if (webModuleLibs == null) {
1573                    webModuleLibs = doc.createElementNS(ns, webLibraryElementName); //NOI18N
1574
data.appendChild(webModuleLibs);
1575                }
1576                while (webModuleLibs.hasChildNodes()) {
1577                    webModuleLibs.removeChild(webModuleLibs.getChildNodes().item(0));
1578                }
1579            }
1580            StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
1581            for ( Iterator JavaDoc it = ((List JavaDoc)value).iterator(); it.hasNext(); ) {
1582                VisualClassPathItem visualClassPathItem = (VisualClassPathItem)it.next();
1583                String JavaDoc pathItem = getPathItem(visualClassPathItem, refHelper);
1584                if(webLibraryElementName != null) {
1585                    webModuleLibs.appendChild(createLibraryElement(doc, pathItem, visualClassPathItem));
1586                }
1587                sb.append(pathItem);
1588                if ( it.hasNext() ) {
1589                    sb.append( File.pathSeparatorChar );
1590                }
1591            }
1592            if(webLibraryElementName != null) {
1593                updateHelper.putPrimaryConfigurationData(data, true);
1594            }
1595            return sb.toString();
1596        }
1597
1598        private Element JavaDoc createLibraryElement(Document JavaDoc doc, String JavaDoc pathItem,
1599                VisualClassPathItem visualClassPathItem) {
1600            final String JavaDoc ns = abpt.getPrimaryConfigurationDataElementNamespace(true);
1601            Element JavaDoc libraryElement = doc.createElementNS(ns,
1602                    TAG_LIBRARY);
1603            
1604            List JavaDoc<File JavaDoc> files = new ArrayList JavaDoc<File JavaDoc>();
1605            List JavaDoc<File JavaDoc> dirs = new ArrayList JavaDoc<File JavaDoc>();
1606            getFilesForItem(visualClassPathItem, files, dirs);
1607            if (files.size() > 0) {
1608                libraryElement.setAttribute(ATTR_FILES, "" + files.size());
1609            }
1610            if (dirs.size() > 0) {
1611                libraryElement.setAttribute(ATTR_DIRS, "" + dirs.size());
1612            }
1613            
1614            Element JavaDoc webFile = doc.createElementNS(ns, TAG_FILE);
1615            libraryElement.appendChild(webFile);
1616            webFile.appendChild(doc.createTextNode(pathItem));
1617            if (visualClassPathItem.getPathInEAR() != VisualClassPathItem.PATH_IN_EAR_NONE) {
1618                Element JavaDoc pathInEar = doc.createElementNS(ns,
1619                        TAG_PATH_IN_EAR);
1620                pathInEar.appendChild(doc.createTextNode(visualClassPathItem.getPathInEAR()));
1621                libraryElement.appendChild(pathInEar);
1622            }
1623            return libraryElement;
1624        }
1625
1626        private Map JavaDoc<String JavaDoc, String JavaDoc> createEarIncludesMap() {
1627            Map JavaDoc<String JavaDoc, String JavaDoc> earIncludesMap = new LinkedHashMap JavaDoc<String JavaDoc, String JavaDoc>();
1628            if (webLibraryElementName != null) {
1629                Element JavaDoc data = updateHelper.getPrimaryConfigurationData(true);
1630                final String JavaDoc ns = abpt.getPrimaryConfigurationDataElementNamespace(true);
1631// final String ns = WebProjectType.PROJECT_CONFIGURATION_NAMESPACE;
1632
Element JavaDoc webModuleLibs = (Element JavaDoc) data.getElementsByTagNameNS(ns, webLibraryElementName).item(0);
1633                if(webModuleLibs != null) {
1634                    NodeList JavaDoc ch = webModuleLibs.getChildNodes();
1635                    for (int i = 0; i < ch.getLength(); i++) {
1636                        if (ch.item(i).getNodeType() == Node.ELEMENT_NODE) {
1637                            Element JavaDoc library = (Element JavaDoc) ch.item(i);
1638                            Node JavaDoc webFile = library.getElementsByTagNameNS(ns, TAG_FILE).item(0);
1639                            NodeList JavaDoc pathInEarElements = library.getElementsByTagNameNS(ns, TAG_PATH_IN_EAR);
1640                            earIncludesMap.put(findText(webFile), pathInEarElements.getLength() > 0 ?
1641                                findText(pathInEarElements.item(0)) : VisualClassPathItem.PATH_IN_EAR_NONE);
1642                        }
1643                    }
1644                }
1645            }
1646            return earIncludesMap;
1647        }
1648
1649        private VisualClassPathItem createVisualClassPathItem(AntProjectHelper antProjectHelper,
1650                ReferenceHelper refHelper, String JavaDoc raw, String JavaDoc pathInEAR) {
1651            // First try to find out whether the item is well known classpath
1652
// in the J2SE project type
1653
for (int j = 0; j < WELL_KNOWN_PATHS.length; j++) {
1654                final String JavaDoc[] wellKnownPath = WELL_KNOWN_PATHS[j];
1655                if (wellKnownPath[0].equals(getAntPropertyName(raw))) {
1656                    return new VisualClassPathItem(raw, VisualClassPathItem.Type.CLASSPATH, raw,
1657                            wellKnownPath[1], pathInEAR);
1658                }
1659            }
1660            if (raw.startsWith(LIBRARY_PREFIX)) {
1661                // Library from library manager
1662
// String eval = antProjectHelper.evaluate(getAntPropertyName(pathItem));
1663
String JavaDoc eval = raw.substring(LIBRARY_PREFIX.length(), raw.lastIndexOf('.')); //NOI18N
1664
Library lib = LibraryManager.getDefault().getLibrary(eval);
1665                if (lib != null) {
1666                    return new VisualClassPathItem(lib, VisualClassPathItem.Type.LIBRARY, raw, eval, pathInEAR);
1667                } else {
1668                    return new VisualClassPathItem(null, VisualClassPathItem.Type.LIBRARY, raw, null, pathInEAR);
1669                }
1670            } else if (raw.startsWith(ANT_ARTIFACT_PREFIX)) {
1671                AntArtifact artifact = (AntArtifact) refHelper.findArtifactAndLocation(raw)[0];
1672                if (artifact != null) {
1673                    // Sub project artifact
1674
return VisualClassPathItem.createArtifact(artifact, raw, pathInEAR);
1675                } else {
1676                    return VisualClassPathItem.createArtifact(null, raw, null, pathInEAR);
1677                }
1678            } else {
1679                // Standalone jar or property
1680
String JavaDoc eval;
1681                if (isAntProperty(raw)) {
1682                    eval = antProjectHelper.getStandardPropertyEvaluator().getProperty(getAntPropertyName(raw));
1683                } else {
1684                    eval = raw;
1685                }
1686                File JavaDoc f = (eval == null) ? null : antProjectHelper.resolveFile(eval);
1687                return VisualClassPathItem.createJAR(f, raw, pathInEAR, eval);
1688            }
1689        }
1690
1691        private String JavaDoc getPathItem(VisualClassPathItem vcpi, ReferenceHelper refHelper) {
1692            switch (vcpi.getType()) {
1693                case JAR:
1694                    String JavaDoc pathItem = vcpi.getRaw();
1695                    if (pathItem == null) {
1696                        // New file
1697
return refHelper.createForeignFileReference((File JavaDoc) vcpi.getObject(),
1698                                JavaProjectConstants.ARTIFACT_TYPE_JAR);
1699                    } else {
1700                        return pathItem;
1701                    }
1702                case ARTIFACT:
1703                    if (vcpi.getObject() != null) {
1704                        AntArtifact aa = (AntArtifact) vcpi.getObject();
1705                        return (String JavaDoc) refHelper.addReference(aa, aa.getArtifactLocations()[0]);
1706                    } else {
1707                        return vcpi.getRaw();
1708                    }
1709                case LIBRARY:
1710                case CLASSPATH:
1711                    return vcpi.getRaw();
1712                default:
1713                    assert false : "Unknown VisualClassPathItem type: " + vcpi.getType();
1714                    return null;
1715            }
1716        }
1717    }
1718    
1719    /**
1720     * Extract nested text from a node.
1721     * Currently does not handle coalescing text nodes, CDATA sections, etc.
1722     * @param parent a parent node
1723     * @return the nested text, or null if none was found
1724     */

1725    private static String JavaDoc findText(Node JavaDoc parent) {
1726        NodeList JavaDoc l = parent.getChildNodes();
1727        for (int i = 0; i < l.getLength(); i++) {
1728            if (l.item(i).getNodeType() == Node.TEXT_NODE) {
1729                Text JavaDoc text = (Text JavaDoc)l.item(i);
1730                return text.getNodeValue();
1731            }
1732        }
1733        return null;
1734    }
1735
1736    
1737    private static JavaPlatform findPlatform(String JavaDoc platformAntID) {
1738        JavaPlatform[] platforms = JavaPlatformManager.getDefault().getInstalledPlatforms();
1739        for(int i = 0; i < platforms.length; i++) {
1740            String JavaDoc normalizedName = (String JavaDoc)platforms[i].getProperties().get("platform.ant.name"); // NOI18N
1741
if (normalizedName != null && normalizedName.equals(platformAntID)) {
1742                return platforms[i];
1743            }
1744        }
1745        return null;
1746    }
1747    
1748    private static class PlatformParser extends PropertyParser {
1749        
1750        public Object JavaDoc decode(String JavaDoc raw, AntProjectHelper antProjectHelper, ReferenceHelper refHelper) {
1751            JavaPlatform platform = findPlatform(raw);
1752            if (platform != null) {
1753                return platform.getDisplayName();
1754            }
1755            // if platform does not exist then return raw reference.
1756
return raw;
1757        }
1758        
1759        public String JavaDoc encode(Object JavaDoc value, AntProjectHelper antProjectHelper, ReferenceHelper refHelper) {
1760            JavaPlatform[] platforms = JavaPlatformManager.getDefault().getPlatforms ((String JavaDoc)value,
1761                    new Specification ("j2se",null)); // NOI18N
1762
if (platforms.length == 0) {
1763                // platform for this project does not exist. broken reference? its displayname should
1764
// correspond to platform ID. so just return it:
1765
return (String JavaDoc)value;
1766            } else {
1767                return (String JavaDoc) platforms[0].getProperties().get("platform.ant.name"); //NOI18N
1768
}
1769        }
1770    }
1771
1772    private void writeWebLibraries(ReferenceHelper refHelper, List JavaDoc value,
1773            final String JavaDoc elementName) {
1774        Element JavaDoc data = updateHelper.getPrimaryConfigurationData(true);
1775        Document JavaDoc doc = data.getOwnerDocument();
1776        Element JavaDoc webModuleLibs = (Element JavaDoc) data.getElementsByTagNameNS(abpt.getPrimaryConfigurationDataElementNamespace(true),
1777                elementName).item(0); //NOI18N
1778

1779        //prevent NPE thrown from older projects
1780
if (webModuleLibs == null) {
1781            webModuleLibs = doc.createElementNS(abpt.getPrimaryConfigurationDataElementNamespace(true), elementName); //NOI18N
1782
data.appendChild(webModuleLibs);
1783        }
1784
1785        while (webModuleLibs.hasChildNodes()) {
1786            webModuleLibs.removeChild(webModuleLibs.getChildNodes().item(0));
1787        }
1788
1789        for (Iterator JavaDoc it = value.iterator(); it.hasNext();) {
1790            VisualClassPathItem vcpi = (VisualClassPathItem) it.next();
1791            String JavaDoc library_tag_value = "";
1792            
1793            //TODO: prevent NPE from CustomizerCompile - need to investigate
1794
if (vcpi == null) {
1795                return;
1796            }
1797
1798            switch (vcpi.getType()) {
1799                case JAR:
1800                    String JavaDoc raw = vcpi.getRaw();
1801
1802                    if (raw == null) {
1803                        // New file
1804
File JavaDoc file = (File JavaDoc) vcpi.getObject();
1805                        String JavaDoc reference = refHelper.createForeignFileReference(file,
1806                                JavaProjectConstants.ARTIFACT_TYPE_JAR);
1807                        library_tag_value = reference;
1808                    } else {
1809                        // Existing property
1810
library_tag_value = raw;
1811                    }
1812
1813                    break;
1814                case LIBRARY:
1815                    library_tag_value = vcpi.getRaw();
1816                    break;
1817                case ARTIFACT:
1818                    AntArtifact aa = (AntArtifact) vcpi.getObject();
1819                    String JavaDoc reference = (String JavaDoc) refHelper.addReference(aa, aa.getArtifactLocations()[0]);
1820                    library_tag_value = reference;
1821                    break;
1822                case CLASSPATH:
1823                    library_tag_value = vcpi.getRaw();
1824                    break;
1825                default:
1826                    assert false : "Unknown VisualClassPathItem type: " + vcpi.getType();
1827            }
1828
1829            Element JavaDoc library = doc.createElementNS(abpt.getPrimaryConfigurationDataElementNamespace(true), "library"); //NOI18N
1830
webModuleLibs.appendChild(library);
1831            Element JavaDoc webFile = doc.createElementNS(abpt.getPrimaryConfigurationDataElementNamespace(true), "file"); //NOI18N
1832
library.appendChild(webFile);
1833            webFile.appendChild(doc.createTextNode(library_tag_value));
1834            String JavaDoc piw = vcpi.getPathInEAR();
1835            if (piw != VisualClassPathItem.PATH_IN_EAR_NONE) {
1836                Element JavaDoc pathInEar = doc.createElementNS(abpt.getPrimaryConfigurationDataElementNamespace(true), "path-in-war"); //NOI18N
1837
pathInEar.appendChild(doc.createTextNode(vcpi.getPathInEAR()));
1838                library.appendChild(pathInEar);
1839            }
1840        }
1841        updateHelper.putPrimaryConfigurationData(data, true);
1842    }
1843    
1844    /** Store locations of libraries in the classpath param that have more the one
1845     * file into the properties in the following format:
1846     *
1847     * <ul>
1848     * <li>libs.foo.classpath.libdir.1=C:/foo
1849     * <li>libs.foo.classpath.libdirs=1
1850     * <li>libs.foo.classpath.libfile.1=C:/bar/a.jar
1851     * <li>libs.foo.classpath.libfile.2=C:/bar/b.jar
1852     * <li>libs.foo.classpath.libfiles=2
1853     * </ul>
1854     * This is needed for the Ant copy task as it cannot copy more the one file
1855     * and it needs different handling for files and directories.
1856     * <br>
1857     * It removes all properties that match this format that were in the {@link #properties}
1858     * but are not in the {@link #classpath}.
1859     */

1860    public static void storeLibrariesLocations (Iterator JavaDoc<VisualClassPathItem> classpath,
1861            Iterator JavaDoc<VisualClassPathItem> oldClasspath, EditableProperties privateProps) {
1862        List JavaDoc<String JavaDoc> exLibs = new ArrayList JavaDoc<String JavaDoc>();
1863        Iterator JavaDoc propKeys = privateProps.keySet().iterator();
1864        while (propKeys.hasNext()) {
1865            String JavaDoc key = (String JavaDoc) propKeys.next();
1866            if (key.endsWith(".libdirs") || key.endsWith(".libfiles") || //NOI18N
1867
(key.indexOf(".libdir.") > 0) || (key.indexOf(".libfile.") > 0)) { //NOI18N
1868
exLibs.add(key);
1869            }
1870        }
1871        while (classpath.hasNext()) {
1872            VisualClassPathItem item = classpath.next();
1873            //do not update anything if the classpath element is null
1874
//this may happen when the library is broken or removed
1875
if(item.getObject() == null) {
1876                continue;
1877            }
1878            
1879            List JavaDoc<File JavaDoc> files = new ArrayList JavaDoc<File JavaDoc>();
1880            List JavaDoc<File JavaDoc> dirs = new ArrayList JavaDoc<File JavaDoc>();
1881            getFilesForItem (item, files, dirs);
1882            String JavaDoc key;
1883            String JavaDoc ref = item.getRaw();
1884            if (files.size() > 1 || (files.size()>0 && dirs.size()>0)) {
1885                for (int i = 0; i < files.size(); i++) {
1886                    File JavaDoc f = files.get(i);
1887                    key = getAntPropertyName(ref)+".libfile." + (i+1); //NOI18N
1888
privateProps.setProperty (key, "" + f.getAbsolutePath()); //NOI18N
1889
exLibs.remove(key);
1890                }
1891            }
1892            if (dirs.size() > 1 || (files.size()>0 && dirs.size()>0)) {
1893                for (int i = 0; i < dirs.size(); i++) {
1894                    File JavaDoc f = dirs.get(i);
1895                    key = getAntPropertyName(ref)+".libdir." + (i+1); //NOI18N
1896
privateProps.setProperty (key, "" + f.getAbsolutePath()); //NOI18N
1897
exLibs.remove(key);
1898                }
1899            }
1900        }
1901        Iterator JavaDoc unused = exLibs.iterator();
1902        while (unused.hasNext()) {
1903            privateProps.remove(unused.next());
1904        }
1905    }
1906    
1907    public static final void getFilesForItem (VisualClassPathItem item, List JavaDoc<File JavaDoc> files, List JavaDoc<File JavaDoc> dirs) {
1908        if (item.getType() == VisualClassPathItem.Type.LIBRARY) {
1909            @SuppressWarnings JavaDoc("unchecked")
1910            List JavaDoc<URL JavaDoc> roots = ((Library)item.getObject()).getContent("classpath"); //NOI18N
1911
for (URL JavaDoc rootUrl : roots) {
1912                FileObject root = URLMapper.findFileObject (rootUrl);
1913                if ("jar".equals(rootUrl.getProtocol())) { //NOI18N
1914
root = FileUtil.getArchiveFile (root);
1915                }
1916                File JavaDoc f = FileUtil.toFile(root);
1917                if (f != null) {
1918                    if (f.isFile()) {
1919                        files.add(f);
1920                    } else {
1921                        dirs.add(f);
1922                    }
1923                }
1924            }
1925        }
1926        if (item.getType() == VisualClassPathItem.Type.JAR) {
1927            File JavaDoc root = (File JavaDoc)item.getObject();
1928            if (root != null) {
1929                if (root.isFile()) {
1930                    files.add(root);
1931                } else {
1932                    dirs.add(root);
1933                }
1934            }
1935        }
1936        if (item.getType() == VisualClassPathItem.Type.ARTIFACT) {
1937            AntArtifact artifact = (AntArtifact)item.getObject();
1938            if (artifact != null) {
1939                String JavaDoc artifactFolder = artifact.getScriptLocation().getParent();
1940                URI JavaDoc roots[] = artifact.getArtifactLocations();
1941                for (int i = 0; i < roots.length; i++) {
1942                    String JavaDoc root = artifactFolder + File.separator + roots [i];
1943                    if (root.endsWith(File.separator)) {
1944                        dirs.add(new File JavaDoc(root));
1945                    } else {
1946                        files.add(new File JavaDoc(root));
1947                    }
1948                }
1949            }
1950        }
1951    }
1952    
1953    private static boolean showModifiedMessage(final String JavaDoc title) {
1954        String JavaDoc message = NbBundle.getMessage(EarProjectProperties.class,"TXT_Regenerate");
1955        JButton JavaDoc regenerateButton = new JButton JavaDoc(NbBundle.getMessage(EarProjectProperties.class,"CTL_RegenerateButton"));
1956        regenerateButton.setDefaultCapable(true);
1957        regenerateButton.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(EarProjectProperties.class,"AD_RegenerateButton"));
1958        NotifyDescriptor d = new NotifyDescriptor.Message(message, NotifyDescriptor.WARNING_MESSAGE);
1959        d.setTitle(title);
1960        d.setOptionType(NotifyDescriptor.OK_CANCEL_OPTION);
1961        d.setOptions(new Object JavaDoc[] {regenerateButton, NotifyDescriptor.CANCEL_OPTION});
1962        return DialogDisplayer.getDefault().notify(d) == regenerateButton;
1963    }
1964    
1965}
1966
Popular Tags