KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > ws7 > j2ee > WS70J2eePlatformImpl


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 /*
21  * WS70J2eePlatformImpl.java
22  *
23  */

24
25 package org.netbeans.modules.j2ee.sun.ws7.j2ee;
26
27 import java.awt.Image JavaDoc;
28 import java.beans.PropertyChangeEvent JavaDoc;
29 import java.beans.PropertyChangeListener JavaDoc;
30 import java.io.File JavaDoc;
31 import java.net.MalformedURLException JavaDoc;
32 import java.net.URL JavaDoc;
33 import java.util.ArrayList JavaDoc;
34 import java.util.HashSet JavaDoc;
35 import java.util.List JavaDoc;
36 import java.util.Set JavaDoc;
37 import javax.swing.SwingUtilities JavaDoc;
38 import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule;
39 import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eePlatform;
40 import org.openide.filesystems.FileUtil;
41 import org.netbeans.modules.j2ee.deployment.common.api.J2eeLibraryTypeProvider;
42 import org.netbeans.modules.j2ee.deployment.plugins.api.J2eePlatformImpl;
43 import org.netbeans.spi.project.libraries.LibraryImplementation;
44 import org.openide.modules.InstalledFileLocator;
45 import org.openide.util.NbBundle;
46 import org.openide.util.Utilities;
47 import org.netbeans.modules.j2ee.deployment.plugins.api.InstanceProperties;
48 import org.netbeans.api.java.platform.JavaPlatform;
49 /**
50  *
51  * @author Administrator
52  */

53 public class WS70J2eePlatformImpl extends J2eePlatformImpl{
54     private static final Set JavaDoc MODULE_TYPES = new HashSet JavaDoc();
55     private static final Set JavaDoc SPEC_VERSIONS = new HashSet JavaDoc();
56     
57     
58     private static final String JavaDoc WS70_JAR = "lib/pwc.jar"; //NOI18N
59
private static final String JavaDoc JWSDP20_JAR = "lib/webserv-jwsdp.jar"; //NOI18N
60
private static final String JavaDoc JSTL_JAR = "lib/webserv-jstl.jar"; //NOI18N
61
private static final String JavaDoc MAIL_JAR = "lib/mail.jar"; //NOI18N
62
private static final String JavaDoc JAXRPC_API_JAR = "lib/jaxrpc-api.jar"; //NOI18N
63
private static final String JavaDoc JAXRPC_IMPL_JAR = "lib/jaxrpc-impl.jar"; //NOI18N
64
private static final String JavaDoc JAXRPC_SPI_JAR = "lib/jaxrpc-spi.jar"; //NOI18N
65
private static final String JavaDoc ACTIVATION = "lib/activation.jar"; //NOI18N
66

67     private List JavaDoc libraries = new ArrayList JavaDoc();
68           
69     
70     
71     static {
72         MODULE_TYPES.add(J2eeModule.WAR);
73
74         SPEC_VERSIONS.add(J2eeModule.J2EE_13);
75         SPEC_VERSIONS.add(J2eeModule.J2EE_14);
76     }
77     
78     private File JavaDoc root;
79     private String JavaDoc displayName;
80     
81     /**
82      * Creates a new instance of WS70J2eePlatformImpl
83      */

84     public WS70J2eePlatformImpl(String JavaDoc rootLocation, String JavaDoc displayName) {
85         if(rootLocation!=null){
86             root = new File JavaDoc(rootLocation);
87             init(root);
88         }
89         this.displayName = displayName;
90     }
91     
92     private void init(File JavaDoc location){
93         try {
94             J2eeLibraryTypeProvider lp = new J2eeLibraryTypeProvider();
95             lp.createLibrary().setName ("a");
96             LibraryImplementation lib = lp.createLibrary();
97
98             lib.setName("webserver70 library"); // NOI18N
99

100             List JavaDoc l = new ArrayList JavaDoc();
101
102             l.add(fileToUrl(new File JavaDoc(root, WS70_JAR)));
103             l.add(fileToUrl(new File JavaDoc(root, JWSDP20_JAR)));
104             l.add(fileToUrl(new File JavaDoc(root, MAIL_JAR)));
105             l.add(fileToUrl(new File JavaDoc(root, JSTL_JAR)));
106             l.add(fileToUrl(new File JavaDoc(root, JAXRPC_API_JAR)));
107             l.add(fileToUrl(new File JavaDoc(root, JAXRPC_IMPL_JAR)));
108             l.add(fileToUrl(new File JavaDoc(root, JAXRPC_SPI_JAR)));
109             l.add(fileToUrl(new File JavaDoc(root, ACTIVATION)));
110
111
112             lib.setContent(J2eeLibraryTypeProvider.VOLUME_TYPE_CLASSPATH, l);
113             
114             File JavaDoc doc = InstalledFileLocator.getDefault().locate("docs/j2eeri-1_4-doc-api.zip", null, false); // NOI18N
115
if (doc != null) {
116                 l = new ArrayList JavaDoc();
117                 l.add(fileToUrl(doc));
118                 lib.setContent(J2eeLibraryTypeProvider.VOLUME_TYPE_JAVADOC, l);
119             }
120
121             libraries.add(lib);
122
123         } catch(Exception JavaDoc e) {
124             e.printStackTrace();
125         }
126     }
127     /**
128      * Return a list of supported J2EE specification versions. Use J2EE specification
129      * versions defined in the {@link org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule}
130      * class.
131      *
132      * @return list of supported J2EE specification versions.
133      */

134     public Set JavaDoc getSupportedSpecVersions() {
135         return SPEC_VERSIONS;
136     }
137     
138     /**
139      * Return a list of supported J2EE module types. Use module types defined in the
140      * {@link org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule}
141      * class.
142      *
143      * @return list of supported J2EE module types.
144      */

145     public Set JavaDoc getSupportedModuleTypes() {
146         return MODULE_TYPES;
147     }
148         /**
149      * Specifies whether a tool of the given name is supported by this platform.
150      *
151      * @param toolName tool's name e.g. "wscompile".
152      * @return <code>true</code> if platform supports tool of the given name,
153      * <code>false</code> otherwise.
154      */

155     public boolean isToolSupported(String JavaDoc toolName) {
156         if(toolName.equals("wscompile")){
157             return true;
158         }else{
159             return false;
160         }
161     }
162     
163     /**
164      * Return platform's libraries.
165      *
166      * @return platform's libraries.
167      */

168     public LibraryImplementation[] getLibraries() {
169         return (LibraryImplementation[])libraries.toArray(new LibraryImplementation[libraries.size()]);
170     }
171     
172     public File JavaDoc[] getToolClasspathEntries(String JavaDoc toolName) {
173         return new File JavaDoc[] {
174             new File JavaDoc(root, JWSDP20_JAR),
175             new File JavaDoc(root, JAXRPC_API_JAR),
176             new File JavaDoc(root, JAXRPC_IMPL_JAR),
177             new File JavaDoc(root, JAXRPC_SPI_JAR),
178             new File JavaDoc(root, MAIL_JAR),
179             new File JavaDoc(root, ACTIVATION)
180             
181         };
182     }
183     
184     /**
185      * Return platform's display name.
186      *
187      * @return platform's display name.
188      */

189     public String JavaDoc getDisplayName() {
190         return displayName;
191     }
192     
193     /**
194      * Return platform's icon.
195      *
196      * @return platform's icon.
197      */

198     public Image JavaDoc getIcon() {
199         return Utilities.loadImage("org/netbeans/modules/j2ee/sun/ide/resources/ServerInstanceIcon.gif"); // NOI18N;
200
}
201     
202     /**
203      * Return platform's root directories. This will be mostly server's installation
204      * directory.
205      *
206      * @return platform's root directories.
207      */

208     public File JavaDoc[] getPlatformRoots() {
209         return new File JavaDoc [] {root};
210     }
211     
212     public Set JavaDoc/*<String>*/ getSupportedJavaPlatformVersions(){
213         Set JavaDoc versions = new HashSet JavaDoc();
214         versions.add("1.4"); // NOI18N
215
versions.add("1.5"); // NOI18N
216
return versions;
217     }
218     
219     /**
220      * Return server J2SE platform or null if the platform is unknown, not
221      * registered in the IDE.
222      *
223      * @return server J2SE platform or null if the platform is unknown, not
224      * registered in the IDE.
225      *
226      * @since 1.9
227      */

228     public JavaPlatform getJavaPlatform(){
229         return null;
230     }
231     private URL JavaDoc fileToUrl(File JavaDoc file) throws MalformedURLException JavaDoc {
232         URL JavaDoc url = file.toURI().toURL();
233         if (FileUtil.isArchiveFile(url)) {
234             url = FileUtil.getArchiveRoot(url);
235         }
236         return url;
237     }
238 }
239
Popular Tags