KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > tomcat5 > TomcatPlatformImpl


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.tomcat5;
21
22 import java.awt.Image JavaDoc;
23 import java.io.File JavaDoc;
24 import java.util.ArrayList JavaDoc;
25 import java.util.HashSet JavaDoc;
26 import java.util.List JavaDoc;
27 import java.util.Set JavaDoc;
28 import org.netbeans.api.java.platform.JavaPlatform;
29 import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule;
30 import org.netbeans.modules.j2ee.deployment.common.api.J2eeLibraryTypeProvider;
31 import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eePlatform;
32 import org.netbeans.modules.j2ee.deployment.plugins.api.J2eePlatformImpl;
33 import org.netbeans.modules.tomcat5.util.TomcatProperties;
34 import org.netbeans.spi.project.libraries.LibraryImplementation;
35 import org.openide.util.NbBundle;
36 import org.openide.util.Utilities;
37
38 /**
39  * Tomcat's implementation of the J2eePlatformImpl.
40  *
41  * @author Stepan Herold
42  */

43 public class TomcatPlatformImpl extends J2eePlatformImpl {
44     
45     private static final String JavaDoc WSCOMPILE_LIBS[] = new String JavaDoc[] {
46         "jaxrpc/lib/jaxrpc-api.jar", // NOI18N
47
"jaxrpc/lib/jaxrpc-impl.jar", // NOI18N
48
"jaxrpc/lib/jaxrpc-spi.jar", // NOI18N
49
"saaj/lib/saaj-api.jar", // NOI18N
50
"saaj/lib/saaj-impl.jar", // NOI18N
51
"jwsdp-shared/lib/mail.jar", // NOI18N
52
"jwsdp-shared/lib/activation.jar" // NOI18N
53
};
54
55     private static final String JavaDoc JWSDP_LIBS[] = new String JavaDoc[] {
56         "fastinfoset/lib/FastInfoset.jar", // NOI18N
57
"jaxb/lib/jaxb1-impl.jar", // NOI18N
58
"jaxb/lib/jaxb-impl.jar", // NOI18N
59
"jaxb/lib/jaxb-api.jar", // NOI18N
60
"jaxb/lib/jaxb-xjc.jar", // NOI18N
61
"jaxws/lib/jaxws-api.jar", // NOI18N
62
"jaxws/lib/jaxws-rt.jar", // NOI18N
63
"jaxws/lib/jaxws-tools.jar", // NOI18N
64
"jaxws/lib/jsr181-api.jar", // NOI18N
65
"jaxws/lib/jsr250-api.jar", // NOI18N
66
"saaj/lib/saaj-api.jar", // NOI18N
67
"saaj/lib/saaj-impl.jar", // NOI18N
68
"sjsxp/lib/sjsxp.jar", // NOI18N
69
"sjsxp/lib/jsr173_api.jar", // NOI18N
70
"jwsdp-shared/lib/activation.jar", // NOI18N
71
"jwsdp-shared/lib/jaas.jar", // NOI18N
72
"jwsdp-shared/lib/jta-spec1_0_1.jar", // NOI18N
73
"jwsdp-shared/lib/mail.jar", // NOI18N
74
//"jwsdp-shared/lib/PackageFormat.jar", // NOI18N
75
"jwsdp-shared/lib/relaxngDatatype.jar", // NOI18N
76
"jwsdp-shared/lib/resolver.jar", // NOI18N
77
"jwsdp-shared/lib/xmlsec.jar", // NOI18N
78
"jwsdp-shared/lib/xsdlib.jar" // NOI18N
79
};
80
81     private static final String JavaDoc WSIT_LIBS[] = new String JavaDoc[] {
82         "shared/lib/webservices-rt.jar", // NOI18N
83
"shared/lib/webservices-tools.jar" // NOI18N
84
};
85     
86     private static final String JavaDoc JWSDP_WSGEN_LIBS[] = new String JavaDoc[] {
87         "jaxws/lib/jaxws-tools.jar", // NOI18N
88
"jaxws/lib/jaxws-rt.jar", // NOI18N
89
"sjsxp/lib/sjsxp.jar", // NOI18N
90
"jaxb/lib/jaxb-xjc.jar", // NOI18N
91
"saaj/lib/saaj-impl.jar", // NOI18N
92
"saaj/lib/saaj-api.jar", // NOI18N
93
"jwsdp-shared/lib/relaxngDatatype.jar", // NOI18N
94
"jwsdp-shared/lib/resolver.jar" // NOI18N
95
};
96
97     private static final String JavaDoc JWSDP_WSIMPORT_LIBS[] = new String JavaDoc[] {
98         "jaxws/lib/jaxws-tools.jar", // NOI18N
99
"jaxws/lib/jaxws-rt.jar", // NOI18N
100
"sjsxp/lib/sjsxp.jar", // NOI18N
101
"jaxb/lib/jaxb-xjc.jar", // NOI18N
102
"jwsdp-shared/lib/relaxngDatatype.jar", // NOI18N
103
"jwsdp-shared/lib/resolver.jar" // NOI18N
104
};
105
106     private static final String JavaDoc WSIT_WSIMPORT_LIBS[] = new String JavaDoc[] {
107         "shared/lib/webservices-rt.jar", // NOI18N
108
"shared/lib/webservices-tools.jar" // NOI18N
109
};
110
111     private static final String JavaDoc WSIT_WSGEN_LIBS[] = new String JavaDoc[] {
112         "shared/lib/webservices-rt.jar", // NOI18N
113
"shared/lib/webservices-tools.jar" // NOI18N
114
};
115
116     private static final String JavaDoc[] KEYSTORE_LOCATION = new String JavaDoc[] {
117         "xws-security/etc/server-keystore.jks" //NOI18N
118
};
119     
120     private static final String JavaDoc[] TRUSTSTORE_LOCATION = new String JavaDoc[] {
121         "xws-security/etc/server-truststore.jks" //NOI18N
122
};
123     
124     private static final String JavaDoc[] KEYSTORE_CLIENT_LOCATION = new String JavaDoc[] {
125         "xws-security/etc/client-keystore.jks" //NOI18N
126
};
127     
128     private static final String JavaDoc[] TRUSTSTORE_CLIENT_LOCATION = new String JavaDoc[] {
129         "xws-security/etc/client-truststore.jks" //NOI18N
130
};
131     
132     private static final String JavaDoc ICON = "org/netbeans/modules/tomcat5/resources/tomcat5instance.png"; // NOI18N
133

134     private String JavaDoc displayName;
135     private TomcatProperties tp;
136     private TomcatManager manager;
137     
138     private List JavaDoc/*<LibraryImpl>*/ libraries = new ArrayList JavaDoc();
139     
140     /** Creates a new instance of TomcatInstallation */
141     public TomcatPlatformImpl(TomcatManager manager) {
142         this.manager = manager;
143         this.tp = manager.getTomcatProperties();
144         displayName = tp.getDisplayName();
145         
146         J2eeLibraryTypeProvider libProvider = new J2eeLibraryTypeProvider();
147         LibraryImplementation lib = libProvider.createLibrary();
148         lib.setName(NbBundle.getMessage(TomcatPlatformImpl.class, "LBL_lib_name", displayName));
149         loadLibraries(lib);
150         libraries.add(lib);
151     }
152     
153     public void notifyLibrariesChanged() {
154         LibraryImplementation lib = (LibraryImplementation)libraries.get(0);
155         loadLibraries(lib);
156         firePropertyChange(PROP_LIBRARIES, null, libraries);
157     }
158     
159     public LibraryImplementation[] getLibraries() {
160        return (LibraryImplementation[])libraries.toArray(new LibraryImplementation[libraries.size()]);
161     }
162     
163     public String JavaDoc getDisplayName() {
164         return displayName;
165     }
166     
167     public Image JavaDoc getIcon() {
168         return Utilities.loadImage(ICON);
169     }
170     
171     public File JavaDoc[] getPlatformRoots() {
172         if (tp.getCatalinaBase() != null) {
173             return new File JavaDoc[] {tp.getCatalinaHome(), tp.getCatalinaBase()};
174         } else {
175             return new File JavaDoc[] {tp.getCatalinaHome()};
176         }
177     }
178     
179     public File JavaDoc[] getToolClasspathEntries(String JavaDoc toolName) {
180         // wscompile support
181
if (J2eePlatform.TOOL_WSCOMPILE.equals(toolName)) {
182             if (isToolSupported(J2eePlatform.TOOL_WSCOMPILE)) {
183                 File JavaDoc[] retValue = new File JavaDoc[WSCOMPILE_LIBS.length];
184                 File JavaDoc homeDir = tp.getCatalinaHome();
185                 for (int i = 0; i < WSCOMPILE_LIBS.length; i++) {
186                     retValue[i] = new File JavaDoc(homeDir, WSCOMPILE_LIBS[i]);
187                 }
188                 return retValue;
189             }
190         }
191         // wsgen support
192
if (J2eePlatform.TOOL_WSGEN.equals(toolName)) {
193             if (isToolSupported(J2eePlatform.TOOL_WSGEN)) {
194                 if (isToolSupported(J2eePlatform.TOOL_WSIT)) {
195                     File JavaDoc[] retValue = new File JavaDoc[WSIT_WSGEN_LIBS.length];
196                     File JavaDoc homeDir = tp.getCatalinaHome();
197                     for (int i = 0; i < WSIT_WSGEN_LIBS.length; i++) {
198                         retValue[i] = new File JavaDoc(homeDir, WSIT_WSGEN_LIBS[i]);
199                     }
200                     return retValue;
201                 } else {
202                     File JavaDoc[] retValue = new File JavaDoc[JWSDP_WSGEN_LIBS.length];
203                     File JavaDoc homeDir = tp.getCatalinaHome();
204                     for (int i = 0; i < JWSDP_WSGEN_LIBS.length; i++) {
205                         retValue[i] = new File JavaDoc(homeDir, JWSDP_WSGEN_LIBS[i]);
206                     }
207                     return retValue;
208                 }
209             }
210         }
211         // wsimport support
212
if (J2eePlatform.TOOL_WSIMPORT.equals(toolName)) {
213             if (isToolSupported(J2eePlatform.TOOL_WSIMPORT)) {
214                 if (isToolSupported(J2eePlatform.TOOL_WSIT)) {
215                     File JavaDoc[] retValue = new File JavaDoc[WSIT_WSIMPORT_LIBS.length];
216                     File JavaDoc homeDir = tp.getCatalinaHome();
217                     for (int i = 0; i < WSIT_WSIMPORT_LIBS.length; i++) {
218                         retValue[i] = new File JavaDoc(homeDir, WSIT_WSIMPORT_LIBS[i]);
219                     }
220                     return retValue;
221                 } else {
222                     File JavaDoc[] retValue = new File JavaDoc[JWSDP_WSIMPORT_LIBS.length];
223                     File JavaDoc homeDir = tp.getCatalinaHome();
224                     for (int i = 0; i < JWSDP_WSIMPORT_LIBS.length; i++) {
225                         retValue[i] = new File JavaDoc(homeDir, JWSDP_WSIMPORT_LIBS[i]);
226                     }
227                     return retValue;
228                 }
229             }
230         }
231         // jwsdp support
232
if (J2eePlatform.TOOL_JWSDP.equals(toolName)) {
233             if (isToolSupported(J2eePlatform.TOOL_WSIT)) {
234                 return getToolClasspathEntries(J2eePlatform.TOOL_WSIT);
235             } else {
236                 if (isToolSupported(J2eePlatform.TOOL_JWSDP)) {
237                     File JavaDoc[] retValue = new File JavaDoc[JWSDP_LIBS.length];
238                     File JavaDoc homeDir = tp.getCatalinaHome();
239                     for (int i = 0; i < JWSDP_LIBS.length; i++) {
240                         retValue[i] = new File JavaDoc(homeDir, JWSDP_LIBS[i]);
241                     }
242                     return retValue;
243                 }
244             }
245         }
246         // keystore support
247
if (J2eePlatform.TOOL_KEYSTORE.equals(toolName)) {
248             if (isToolSupported(J2eePlatform.TOOL_KEYSTORE)) {
249                 File JavaDoc[] retValue = new File JavaDoc[KEYSTORE_LOCATION.length];
250                 File JavaDoc homeDir = tp.getCatalinaHome();
251                 for (int i = 0; i < KEYSTORE_LOCATION.length; i++) {
252                     retValue[i] = new File JavaDoc(homeDir, KEYSTORE_LOCATION[i]);
253                 }
254                 return retValue;
255             }
256         }
257         // truststore support
258
if (J2eePlatform.TOOL_TRUSTSTORE.equals(toolName)) {
259             if (isToolSupported(J2eePlatform.TOOL_TRUSTSTORE)) {
260                 File JavaDoc[] retValue = new File JavaDoc[TRUSTSTORE_LOCATION.length];
261                 File JavaDoc homeDir = tp.getCatalinaHome();
262                 for (int i = 0; i < TRUSTSTORE_LOCATION.length; i++) {
263                     retValue[i] = new File JavaDoc(homeDir, TRUSTSTORE_LOCATION[i]);
264                 }
265                 return retValue;
266             }
267         }
268         if (J2eePlatform.TOOL_KEYSTORE_CLIENT.equals(toolName)) {
269             if (isToolSupported(J2eePlatform.TOOL_KEYSTORE_CLIENT)) {
270                 File JavaDoc[] retValue = new File JavaDoc[KEYSTORE_CLIENT_LOCATION.length];
271                 File JavaDoc homeDir = tp.getCatalinaHome();
272                 for (int i = 0; i < KEYSTORE_CLIENT_LOCATION.length; i++) {
273                     retValue[i] = new File JavaDoc(homeDir, KEYSTORE_CLIENT_LOCATION[i]);
274                 }
275                 return retValue;
276             }
277         }
278         // truststore support
279
if (J2eePlatform.TOOL_TRUSTSTORE_CLIENT.equals(toolName)) {
280             if (isToolSupported(J2eePlatform.TOOL_TRUSTSTORE_CLIENT)) {
281                 File JavaDoc[] retValue = new File JavaDoc[TRUSTSTORE_CLIENT_LOCATION.length];
282                 File JavaDoc homeDir = tp.getCatalinaHome();
283                 for (int i = 0; i < TRUSTSTORE_CLIENT_LOCATION.length; i++) {
284                     retValue[i] = new File JavaDoc(homeDir, TRUSTSTORE_CLIENT_LOCATION[i]);
285                 }
286                 return retValue;
287             }
288         }
289         // wsit support
290
if (J2eePlatform.TOOL_WSIT.equals(toolName)) {
291             if (isToolSupported(J2eePlatform.TOOL_WSIT)) {
292                 File JavaDoc[] retValue = new File JavaDoc[WSIT_LIBS.length];
293                 File JavaDoc homeDir = tp.getCatalinaHome();
294                 for (int i = 0; i < WSIT_LIBS.length; i++) {
295                     retValue[i] = new File JavaDoc(homeDir, WSIT_LIBS[i]);
296                 }
297                 return retValue;
298             }
299         }
300         return null;
301     }
302     
303     public boolean isToolSupported(String JavaDoc toolName) {
304         // jwsdp support
305
if (J2eePlatform.TOOL_WSCOMPILE.equals(toolName)) {
306             File JavaDoc homeDir = tp.getCatalinaHome();
307             for (int i = 0; i < WSCOMPILE_LIBS.length; i++) {
308                 if (!new File JavaDoc(homeDir, WSCOMPILE_LIBS[i]).exists()) {
309                     return false;
310                 }
311             }
312             return true;
313         }
314         if (J2eePlatform.TOOL_WSGEN.equals(toolName)) {
315             File JavaDoc homeDir = tp.getCatalinaHome();
316             boolean wsit = isToolSupported(J2eePlatform.TOOL_WSIT);
317             if (wsit) {
318                 for (int i = 0; i < WSIT_WSGEN_LIBS.length; i++) {
319                     if (!new File JavaDoc(homeDir, WSIT_WSGEN_LIBS[i]).exists()) {
320                         return false;
321                     }
322                 }
323             } else {
324                 for (int i = 0; i < JWSDP_WSGEN_LIBS.length; i++) {
325                     if (!new File JavaDoc(homeDir, JWSDP_WSGEN_LIBS[i]).exists()) {
326                         return false;
327                     }
328                 }
329             }
330             return true;
331         }
332         if (J2eePlatform.TOOL_WSIMPORT.equals(toolName)) {
333             File JavaDoc homeDir = tp.getCatalinaHome();
334             boolean wsit = isToolSupported(J2eePlatform.TOOL_WSIT);
335             if (wsit) {
336                 for (int i = 0; i < WSIT_WSIMPORT_LIBS.length; i++) {
337                     if (!new File JavaDoc(homeDir, WSIT_WSIMPORT_LIBS[i]).exists()) {
338                         return false;
339                     }
340                 }
341             } else {
342                 for (int i = 0; i < JWSDP_WSIMPORT_LIBS.length; i++) {
343                     if (!new File JavaDoc(homeDir, JWSDP_WSIMPORT_LIBS[i]).exists()) {
344                         return false;
345                     }
346                 }
347             }
348             return true;
349         }
350         if (J2eePlatform.TOOL_JWSDP.equals(toolName)) {
351             
352             if (isToolSupported(J2eePlatform.TOOL_WSIT)) {
353                 return true;
354             }
355             
356             File JavaDoc homeDir = tp.getCatalinaHome();
357             for (int i = 0; i < JWSDP_LIBS.length; i++) {
358                 if (!new File JavaDoc(homeDir, JWSDP_LIBS[i]).exists()) {
359                     return false;
360                 }
361             }
362             return true;
363         }
364         if (J2eePlatform.TOOL_KEYSTORE.equals(toolName)) {
365             File JavaDoc homeDir = tp.getCatalinaHome();
366             for (int i = 0; i < KEYSTORE_LOCATION.length; i++) {
367                 if (!new File JavaDoc(homeDir, KEYSTORE_LOCATION[i]).exists()) {
368                     return false;
369                 }
370             }
371             return true;
372         }
373         if (J2eePlatform.TOOL_TRUSTSTORE.equals(toolName)) {
374             File JavaDoc homeDir = tp.getCatalinaHome();
375             for (int i = 0; i < TRUSTSTORE_LOCATION.length; i++) {
376                 if (!new File JavaDoc(homeDir, TRUSTSTORE_LOCATION[i]).exists()) {
377                     return false;
378                 }
379             }
380             return true;
381         }
382         if (J2eePlatform.TOOL_KEYSTORE_CLIENT.equals(toolName)) {
383             File JavaDoc homeDir = tp.getCatalinaHome();
384             for (int i = 0; i < KEYSTORE_CLIENT_LOCATION.length; i++) {
385                 if (!new File JavaDoc(homeDir, KEYSTORE_CLIENT_LOCATION[i]).exists()) {
386                     return false;
387                 }
388             }
389             return true;
390         }
391         if (J2eePlatform.TOOL_TRUSTSTORE_CLIENT.equals(toolName)) {
392             File JavaDoc homeDir = tp.getCatalinaHome();
393             for (int i = 0; i < TRUSTSTORE_CLIENT_LOCATION.length; i++) {
394                 if (!new File JavaDoc(homeDir, TRUSTSTORE_CLIENT_LOCATION[i]).exists()) {
395                     return false;
396                 }
397             }
398             return true;
399         }
400         if (J2eePlatform.TOOL_WSIT.equals(toolName)) {
401             File JavaDoc homeDir = tp.getCatalinaHome();
402             for (int i = 0; i < WSIT_LIBS.length; i++) {
403                 if (!new File JavaDoc(homeDir, WSIT_LIBS[i]).exists()) {
404                     return false;
405                 }
406             }
407             return true;
408         }
409         if (J2eePlatform.TOOL_JSR109.equals(toolName)) {
410             return false;
411         }
412         
413         // Test if server has the JAX-WS Tester capability
414
if ("jaxws-tester".equals(toolName)) { //NOI18N
415
return true;
416         }
417         
418         return false;
419     }
420         
421     public Set JavaDoc/*<Object>*/ getSupportedModuleTypes() {
422         Set JavaDoc moduleTypes = new HashSet JavaDoc(1);
423         moduleTypes.add(J2eeModule.WAR);
424         return moduleTypes;
425     }
426     
427     public Set JavaDoc/*<String>*/ getSupportedSpecVersions() {
428         Set JavaDoc specVersions = new HashSet JavaDoc(3);
429         specVersions.add(J2eeModule.J2EE_13);
430         specVersions.add(J2eeModule.J2EE_14);
431         if (manager.isTomcat60()) {
432             specVersions.add(J2eeModule.JAVA_EE_5);
433         }
434         return specVersions;
435     }
436     
437     public Set JavaDoc/*<String>*/ getSupportedJavaPlatformVersions() {
438         Set JavaDoc versions = new HashSet JavaDoc();
439         versions.add("1.4"); // NOI18N
440
versions.add("1.5"); // NOI18N
441
return versions;
442     }
443     
444     public JavaPlatform getJavaPlatform() {
445         return tp.getJavaPlatform();
446     }
447     
448     // private helper methods -------------------------------------------------
449

450     private void loadLibraries(LibraryImplementation lib) {
451         lib.setContent(J2eeLibraryTypeProvider.VOLUME_TYPE_CLASSPATH, tp.getClasses());
452         lib.setContent(J2eeLibraryTypeProvider.VOLUME_TYPE_JAVADOC, tp.getJavadocs());
453         lib.setContent(J2eeLibraryTypeProvider.VOLUME_TYPE_SRC, tp.getSources());
454     }
455 }
456
Popular Tags