KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > websphere6 > j2ee > WSJ2eePlatformFactory


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 package org.netbeans.modules.j2ee.websphere6.j2ee;
20
21 import java.io.*;
22 import java.net.*;
23 import java.util.*;
24 import java.awt.*;
25
26 import javax.enterprise.deploy.spi.DeploymentManager JavaDoc;
27 import org.netbeans.api.java.platform.JavaPlatform;
28 import org.openide.*;
29 import org.openide.filesystems.*;
30 import org.openide.util.*;
31 import org.netbeans.spi.project.libraries.*;
32 import org.netbeans.modules.j2ee.deployment.common.api.*;
33 import org.netbeans.modules.j2ee.deployment.devmodules.api.*;
34 import org.netbeans.modules.j2ee.deployment.plugins.api.*;
35 import org.netbeans.modules.j2ee.websphere6.*;
36
37 /**
38  * A sub-class of the J2eePlatformFactory that is set up to return the
39  * plugin-specific J2eePlatform.
40  *
41  * @author Kirill Sorokin
42  */

43 public class WSJ2eePlatformFactory extends J2eePlatformFactory {
44     
45     /**
46      * Factory method for WSJ2eePlatformImpl. This method is used for
47      * constructing the plugin-specific J2eePlatform object.
48      *
49      * @param dm the server specific deployment manager that can be used as an
50      * additional source of information
51      */

52     public J2eePlatformImpl getJ2eePlatformImpl(DeploymentManager JavaDoc dm) {
53         return new J2eePlatformImplImpl(dm);
54     }
55     
56     /**
57      * The plugin implementation of the J2eePlatform interface. It is used to
58      * provide all kinds of information about the environment that the deployed
59      * application will run against, such as the set of .jsr files representing
60      * the j2ee implementation, which kinds of application the server may
61      * contain, which j2ee specification version the server supports, etc.
62      */

63     private static class J2eePlatformImplImpl extends J2eePlatformImpl {
64         
65         /**
66          * The platform icon's URL
67          */

68         private static final String JavaDoc ICON = "org/netbeans/modules/" + // NOI18N
69
"j2ee/websphere6/resources/16x16.gif"; // NOI18N
70

71         /**
72          * The server's deployment manager, to be exact the plugin's wrapper for
73          * it
74          */

75         WSDeploymentManager dm;
76         
77         /**
78          * Creates a new instance of J2eePlatformImplImpl.
79          *
80          * @param dm the server's deployment manager
81          */

82         public J2eePlatformImplImpl(DeploymentManager JavaDoc dm) {
83             // save the prarmeters
84
this.dm = (WSDeploymentManager) dm;
85         }
86         
87         /**
88          * Defines whether the platform supports the named tool. Since it's
89          * unclear what actually a 'tool' is, currently it returns false.
90          *
91          * @param toolName tool name
92          *
93          * @return false
94          */

95         public boolean isToolSupported(String JavaDoc toolName) {
96             return false;
97         }
98         
99         /**
100          * Gets the classpath entries for the named tool. Since it's
101          * unclear what actually a 'tool' is, currently it returns an empty
102          * array.
103          *
104          * @param toolName tool name
105          *
106          * @return an empty array of File
107          */

108         public File[] getToolClasspathEntries(String JavaDoc toolName) {
109             return new File[0];
110         }
111         
112         /**
113          * Specifies which versions of j2ee the server supports.
114          *
115          * @return a Set with the supported versions
116          */

117         public Set getSupportedSpecVersions() {
118             // init the set
119
Set result = new HashSet();
120             
121             // add j2ee 1.4
122
result.add(J2eeModule.J2EE_14);
123             
124             // return
125
return result;
126         }
127         
128         
129         public Set getSupportedJavaPlatformVersions() {
130             Set versions = new HashSet();
131             versions.add("1.4"); // NOI18N
132
versions.add("1.5"); // NOI18N
133
return versions;
134             
135         }
136         
137         /**
138          * Specifies which module types the server supports.
139          *
140          * @return a Set the the supported module types
141          */

142         public Set getSupportedModuleTypes() {
143             // init the set
144
Set result = new HashSet();
145             
146             // add supported modules
147
result.add(J2eeModule.EAR);
148             result.add(J2eeModule.WAR);
149             result.add(J2eeModule.EJB);
150             result.add(J2eeModule.CONN);
151             result.add(J2eeModule.CLIENT);
152             
153             // return
154
return result;
155         }
156         
157         /**
158          * Specifies the platform root directories. It's unclear where and why
159          * it is used, for now returning the server home directory.
160          *
161          * @return an array of files with a single entry - the server home
162          * directory
163          */

164         public java.io.File JavaDoc[] getPlatformRoots() {
165             return new File[] {
166                 new File(dm.getInstanceProperties().getProperty(
167                         WSDeploymentFactory.SERVER_ROOT_ATTR))
168             };
169         }
170         
171         /**
172          * Gets the libraries that will be attached to the project for
173          * compilation. A library includes a set of jar files, sources and
174          * javadocs. As there may be multiple jars per library we create only
175          * one.
176          *
177          * @return an array of libraries
178          */

179         public LibraryImplementation[] getLibraries() {
180             // init the resulting array
181
LibraryImplementation[] libraries = new LibraryImplementation[1];
182             
183             // create a new library
184
LibraryImplementation library = new J2eeLibraryTypeProvider().
185                     createLibrary();
186             
187             // set its name
188
library.setName(NbBundle.getMessage(WSJ2eePlatformFactory.class,
189                     "TXT_libraryName")); // NOI18N
190

191             // add the required jars to the library
192
try {
193                 ArrayList list = new ArrayList();
194                 list.add(fileToUrl(new File(dm.getInstanceProperties().
195                         getProperty(WSDeploymentFactory.SERVER_ROOT_ATTR),
196                         "/lib/j2ee.jar"))); // NOI18N
197

198                 library.setContent(J2eeLibraryTypeProvider.
199                         VOLUME_TYPE_CLASSPATH, list);
200             } catch (MalformedURLException e) {
201                 ErrorManager.getDefault().notify(ErrorManager.EXCEPTION, e);
202             }
203             
204             // add the created library to the array
205
libraries[0] = library;
206             
207             // return
208
return libraries;
209         }
210         
211         /**
212          * Gets the platform icon. A platform icon is the one that appears near
213          * the libraries attached to j2ee project.
214          *
215          * @return the platform icon
216          */

217         public Image getIcon() {
218             return Utilities.loadImage(ICON);
219         }
220         
221         /**
222          * Gets the platform display name. This one appears exactly to the
223          * right of the platform icon ;)
224          *
225          * @return the platform's display name
226          */

227         public String JavaDoc getDisplayName() {
228             return NbBundle.getMessage(WSJ2eePlatformFactory.class,
229                     "TXT_platformName"); // NOI18N
230
}
231         
232         /**
233          * Converts a file to the URI in system resources.
234          * Copied from the plugin for Sun Appserver 8
235          *
236          * @param file a file to be converted
237          *
238          * @return the resulting URI
239          */

240         private URL fileToUrl(File file) throws MalformedURLException {
241             // get the file's absolute URL
242
URL url = file.toURI().toURL();
243             
244             // strip the jar's path and remain with the system resources URI
245
if (FileUtil.isArchiveFile(url)) {
246                 url = FileUtil.getArchiveRoot(url);
247             }
248             
249             // return
250
return url;
251         }
252         
253         
254         /**
255          * Implements J2eePlatformImpl
256          *
257          */

258         
259         public JavaPlatform getJavaPlatform() {
260             /* TO DO
261             String currentJvm = ip.getProperty(PROP_JAVA_PLATFORM);
262             JavaPlatformManager jpm = JavaPlatformManager.getDefault();
263             JavaPlatform[] installedPlatforms = jpm.getPlatforms(null, new Specification("J2SE", null)); // NOI18N
264             for (int i = 0; i < installedPlatforms.length; i++) {
265                 String platformName = (String)installedPlatforms[i].getProperties().get(PLAT_PROP_ANT_NAME);
266                 if (platformName != null && platformName.equals(currentJvm)) {
267                     return installedPlatforms[i];
268                 }
269             }
270             // return default platform if none was set
271             return jpm.getDefaultPlatform();
272              */

273             return null;
274         }
275     }
276 }
Popular Tags