KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > weblogic9 > j2ee > WLJ2eePlatformFactory


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

46 public class WLJ2eePlatformFactory extends J2eePlatformFactory {
47     
48     public J2eePlatformImpl getJ2eePlatformImpl(DeploymentManager dm) {
49         assert WLDeploymentManager.class.isAssignableFrom(dm.getClass()) : this + " cannot create platform for unknown deployment manager:" + dm;
50         return new J2eePlatformImplImpl((WLDeploymentManager)dm);
51     }
52     
53     private static class J2eePlatformImplImpl extends J2eePlatformImpl {
54         
55         private static final String JavaDoc J2EE_API_DOC = "docs/javaee5-doc-api.zip"; // NOI18N
56
private static final Set MODULE_TYPES = new HashSet();
57         static {
58             MODULE_TYPES.add(J2eeModule.EAR);
59             MODULE_TYPES.add(J2eeModule.WAR);
60             MODULE_TYPES.add(J2eeModule.EJB);
61 // MODULE_TYPES.add(J2eeModule.CONN);
62
// MODULE_TYPES.add(J2eeModule.CLIENT);
63
}
64
65         private static final Set SPEC_VERSIONS = new HashSet();
66         static {
67             SPEC_VERSIONS.add(J2eeModule.J2EE_14);
68         }
69         
70 // private String platformRoot = WLPluginProperties.getInstance().getInstallLocation();
71
private String JavaDoc platformRoot;
72         
73         private LibraryImplementation[] libraries = null;
74         
75         /**
76          * The platform icon's URL
77          */

78         private static final String JavaDoc ICON = "org/netbeans/modules/" + // NOI18N
79
"j2ee/weblogic9/resources/16x16.gif"; // NOI18N
80

81         /**
82          * The server's deployment manager, to be exact the plugin's wrapper for
83          * it
84          */

85         WLDeploymentManager dm;
86         
87         public J2eePlatformImplImpl(WLDeploymentManager dm) {
88             this.dm = dm;
89         }
90         
91         public boolean isToolSupported(String JavaDoc toolName) {
92             if (J2eePlatform.TOOL_WSGEN.equals(toolName) || J2eePlatform.TOOL_WSIMPORT.equals(toolName)) {
93                 return true;
94             }
95             if (J2eePlatform.TOOL_JSR109.equals(toolName)) {
96                 return false; // to explicitelly emphasise that JSR 109 is not supported
97
}
98             return false;
99         }
100         
101         public File[] getToolClasspathEntries(String JavaDoc toolName) {
102             File[] cp = new File[0];
103             if (J2eePlatform.TOOL_WSGEN.equals(toolName) || J2eePlatform.TOOL_WSIMPORT.equals(toolName)) {
104                 cp = new File[] { new File(getPlatformRoot(), "server/lib/weblogic.jar") }; // NOI18N
105
}
106             return cp;
107         }
108         
109         public Set getSupportedSpecVersions() {
110             return SPEC_VERSIONS;
111         }
112         
113         public java.util.Set JavaDoc getSupportedModuleTypes() {
114             return MODULE_TYPES;
115         }
116         
117         public Set/*<String>*/ getSupportedJavaPlatformVersions() {
118             Set versions = new HashSet();
119             versions.add("1.4"); // NOI18N
120
versions.add("1.5"); // NOI18N
121
return versions;
122         }
123         
124         public JavaPlatform getJavaPlatform() {
125             return null;
126         }
127         
128         public java.io.File JavaDoc[] getPlatformRoots() {
129             return new File[]{new File(getPlatformRoot())};
130         }
131         
132         public LibraryImplementation[] getLibraries() {
133             if (libraries == null) {
134                 initLibraries();
135             }
136             return libraries;
137         }
138         
139         private void initLibraries() {
140             
141             // create a new library
142
LibraryImplementation library = new J2eeLibraryTypeProvider().
143                     createLibrary();
144             
145             // set its name
146
library.setName(NbBundle.getMessage(WLJ2eePlatformFactory.class,
147                     "LIBRARY_NAME")); // NOI18N
148

149             // add the required jars to the library
150
try {
151                 List list = new ArrayList();
152                 list.add(fileToUrl(new File(getPlatformRoot(), "server/lib/weblogic.jar"))); // NOI18N
153

154                 library.setContent(J2eeLibraryTypeProvider.
155                         VOLUME_TYPE_CLASSPATH, list);
156                File j2eeDoc = InstalledFileLocator.getDefault().locate(J2EE_API_DOC, null, false);
157                if (j2eeDoc != null) {
158                    list = new ArrayList();
159                    list.add(fileToUrl(j2eeDoc));
160                    library.setContent(J2eeLibraryTypeProvider.VOLUME_TYPE_JAVADOC, list);
161                }
162             } catch (MalformedURLException e) {
163                 ErrorManager.getDefault().notify(ErrorManager.EXCEPTION, e);
164             }
165             
166             libraries = new LibraryImplementation[1];
167             libraries[0] = library;
168         }
169         
170         /**
171          * Gets the platform icon. A platform icon is the one that appears near
172          * the libraries attached to j2ee project.
173          *
174          * @return the platform icon
175          */

176         public Image JavaDoc getIcon() {
177             return Utilities.loadImage(ICON);
178         }
179         
180         /**
181          * Gets the platform display name. This one appears exactly to the
182          * right of the platform icon ;)
183          *
184          * @return the platform's display name
185          */

186         public String JavaDoc getDisplayName() {
187             return NbBundle.getMessage(WLJ2eePlatformFactory.class, "PLATFORM_NAME"); // NOI18N
188
}
189         
190         /**
191          * Converts a file to the URI in system resources.
192          * Copied from the plugin for Sun Appserver 8
193          *
194          * @param file a file to be converted
195          *
196          * @return the resulting URI
197          */

198         private URL fileToUrl(File file) throws MalformedURLException {
199             URL url = file.toURI().toURL();
200             if (FileUtil.isArchiveFile(url)) {
201                 url = FileUtil.getArchiveRoot(url);
202             }
203             return url;
204         }
205
206         private String JavaDoc getPlatformRoot() {
207             if (platformRoot == null)
208                 platformRoot = dm.getInstanceProperties().getProperty(WLPluginProperties.SERVER_ROOT_ATTR);
209             
210             return platformRoot;
211         }
212     }
213     
214 }
215
Popular Tags