KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > websvc > registry > netbeans > WebServiceModuleInstaller


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  * Module installer class that persist the
22  * @author Winston Prakash
23  */

24 package org.netbeans.modules.websvc.registry.netbeans;
25
26 import java.io.*;
27
28 import org.openide.ErrorManager;
29 import org.openide.modules.ModuleInstall;
30 import org.openide.modules.InstalledFileLocator;
31
32 //import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eePlatform;
33
//import org.netbeans.modules.j2ee.deployment.devmodules.api.Deployment;
34
//import org.netbeans.modules.j2ee.deployment.devmodules.spi.InstanceListener;
35

36
37 /** class WebServiceModuleInstaller
38  *
39  * ModuleInstall for the web service registry module. Handles reading
40  * the registry on module startup and saving any changes on module shutdown.
41  */

42 public class WebServiceModuleInstaller extends ModuleInstall /*implements InstanceListener*/ {
43     
44     private static ExtensionClassLoader specialLoader = null;
45     private static boolean registryInstalled = false;
46         
47     public void close() {
48         if(registryInstalled) {
49             try {
50                 PersistenceManagerInterface persistenceManager =(PersistenceManagerInterface)
51                 specialLoader.loadClass("org.netbeans.modules.websvc.registry.WebServicePersistenceManager").newInstance(); //NOI18N
52
persistenceManager.save(specialLoader);
53             } catch (ClassNotFoundException JavaDoc cnfe){
54                 // nothing to do in this case, this server does not support wscompile or web services
55
// see bug 55323
56
} catch(Exception JavaDoc ex) {
57                 ErrorManager.getDefault().notify(ErrorManager.EXCEPTION, ex);
58             } finally {
59             }
60         }
61     }
62     
63     public void uninstalled() {
64         close();
65     }
66     
67     public static void restoreds() {
68         if(specialLoader == null) {
69             try {
70                 specialLoader = new ExtensionClassLoader(WebServiceModuleInstaller.class.getClassLoader());
71                 updatesSpecialLoader(specialLoader);
72             } catch(Exception JavaDoc ex) {
73                 ErrorManager.getDefault().notify(ErrorManager.EXCEPTION, ex);
74             }
75         }
76     }
77
78     public static ClassLoader JavaDoc getExtensionClassLoader() {
79         if (!registryInstalled) {
80             restoreds();
81         }
82         if (registryInstalled) {
83             try {
84                 PersistenceManagerInterface persistenceManager = (PersistenceManagerInterface)
85                 specialLoader.loadClass("org.netbeans.modules.websvc.registry.WebServicePersistenceManager").newInstance(); //NOI18N
86
persistenceManager.load(specialLoader);
87             } catch(Exception JavaDoc ex) {
88                 ErrorManager.getDefault().notify(ErrorManager.EXCEPTION, ex);
89             }
90         }
91         
92         return specialLoader;
93     }
94  
95     private static String JavaDoc JAXRPC_16 [] = {
96         "modules/ext/jaxrpc16/activation.jar",
97         "modules/ext/jaxrpc16/jax-qname.jar",
98         "modules/ext/jaxrpc16/jaxp-api.jar",
99         "modules/ext/jaxrpc16/FastInfoset.jar",
100         "modules/ext/jaxrpc16/jaxrpc-api.jar",
101         "modules/ext/jaxrpc16/jaxrpc-impl.jar",
102         "modules/ext/jaxrpc16/jaxrpc-spi.jar",
103         "modules/ext/jaxrpc16/jsr173_api.jar",
104         "modules/ext/jaxrpc16/mail.jar",
105         "modules/ext/jaxrpc16/relaxngDatatype.jar",
106         "modules/ext/jaxrpc16/saaj-api.jar",
107         "modules/ext/jaxrpc16/saaj-impl.jar",
108         "modules/ext/jaxrpc16/xsdlib.jar"
109     };
110     
111     private static String JavaDoc JAXRPC_16_XML [] = {
112         "modules/ext/jaxrpc16_xml/dom.jar",
113         "modules/ext/jaxrpc16_xml/sax.jar",
114         "modules/ext/jaxrpc16_xml/xercesImpl.jar",
115         "modules/ext/jaxrpc16_xml/xalan.jar"
116     };
117         
118     public static void updatesSpecialLoader(ExtensionClassLoader loader) throws Exception JavaDoc {
119         try {
120 // String serverInstanceIDs[] = Deployment.getDefault().getServerInstanceIDs();
121
// J2eePlatform platform = null;
122
// for (int i = 0; i < serverInstanceIDs.length; i++) {
123
// J2eePlatform p = Deployment.getDefault().getJ2eePlatform(serverInstanceIDs [i]);
124
// if (p!= null && p.isToolSupported("wscompile")) {
125
// platform = p;
126
// break;
127
// }
128
// }
129
// File f1 = platform == null ? null : platform.getPlatformRoots() [0];
130
// if(f1 != null && f1.exists()) {
131
// String installRoot = f1.getAbsolutePath();
132

133                 
134                 String JavaDoc javaVersion = System.getProperty("java.version"); //NOI18N
135

136                 if (javaVersion!=null && javaVersion.startsWith("1.4")) { //NOI18N
137
InstalledFileLocator loc = InstalledFileLocator.getDefault();
138                     for(int i = 0; i < JAXRPC_16_XML.length; i++) {
139                         File jarFile = loc.locate(JAXRPC_16_XML[i], "org.netbeans.modules.websvc.jaxrpc16_xml", false); //NOI18N
140
if (jarFile != null) {
141                             loader.addURL(jarFile);
142                         } else {
143                             //System.out.println("Cannot load jar: " + JAXRPC_16_XML[i]);
144
return;
145                         }
146                     }
147                 }
148                 
149                 InstalledFileLocator locator = InstalledFileLocator.getDefault();
150                 
151                 File f = locator.locate("modules/ext/websvcregistry.jar", null, true); // NOI18N
152
if(f != null) {
153                     registryInstalled = true;
154                     loader.addURL(f);
155                     loadLocaleSpecificJars(f, loader);
156                 } else {
157                     ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL, "Cannot locate file modules/ext/websvcregistry.jar");
158                 }
159                 
160                 // Add correct jars from the installed application server.
161
// SJSASVersion appServerVersion = SJSASVersion.getSJSAppServerVersion();
162
String JavaDoc [] registryRuntimeJars = JAXRPC_16;
163                 
164                 for(int i = 0; i < registryRuntimeJars.length; i++) {
165                     File jarFile = locator.locate(registryRuntimeJars[i], null, false);
166                     if (jarFile != null) {
167                         loader.addURL(jarFile);
168                     } else {
169                         System.out.println("Cannot load jar: " + registryRuntimeJars[i]);
170                     }
171                 }
172 // }
173
} catch(Exception JavaDoc ex) {
174             throw new Exception JavaDoc(ex.getLocalizedMessage(), ex);
175         }
176     }
177     private static void loadLocaleSpecificJars(File file, ExtensionClassLoader loader) {
178         File parentDir = file.getParentFile();
179         //System.out.println("parentDir: " + parentDir);
180
File localeDir = new File(parentDir, "locale"); //NOI18N
181
if(localeDir.exists()){
182             File[] localeFiles = localeDir.listFiles();
183             File localeFile = null;
184             String JavaDoc localeFileName = null;
185             String JavaDoc fileName = file.getName();
186             fileName = getFileNameWithoutExt(fileName);
187             //System.out.println("fineName: " + fileName);
188
assert(fileName.length() > 0);
189             for(int i=0; i<localeFiles.length; i++){
190                 localeFile = localeFiles[i];
191                 localeFileName = localeFile.getName();
192                 //System.out.println("localeFileName: " + localeFileName);
193
assert(localeFileName.length() > 0);
194                 if(localeFileName.startsWith(fileName)){
195                     try{
196                         loader.addURL(localeFile);
197                     }catch (Exception JavaDoc ex2) {
198                         System.out.println(ex2.getLocalizedMessage());
199                     }
200                 }
201             }
202         }
203     }
204     
205     private static String JavaDoc getFileNameWithoutExt(String JavaDoc fileName){
206         int index = fileName.lastIndexOf("."); //NOI18N
207
if(index != -1){
208             fileName = fileName.substring(0, index);
209         }
210         return fileName;
211     }
212
213 // public void changeDefaultInstance(String oldServerInstanceID, String newServerInstanceID) {
214
// }
215
//
216
// public void instanceAdded(String serverInstanceID) {
217
// if (registryInstalled==false){
218
// specialLoader = null;
219
// restoreds();
220
// try {
221
// PersistenceManagerInterface persistenceManager = (PersistenceManagerInterface)
222
// specialLoader.loadClass("org.netbeans.modules.websvc.registry.WebServicePersistenceManager").newInstance(); //NOI18N
223
// persistenceManager.load(specialLoader);
224
// } catch (ClassNotFoundException cnfe){
225
// // nothing to do in this case, this server does not support wscompile or web services
226
// // see bug 55323
227
// } catch(Exception ex) {
228
// ErrorManager.getDefault().notify(ErrorManager.EXCEPTION, ex);
229
// }
230
//
231
// firePropertyChange("specialLoader", null,"specialLoader");//NOI18N
232
// }
233
// }
234
//
235
// public void instanceRemoved(String serverInstanceID) {
236
// }
237
// /*
238
// * Used to get the netbeans classloader of this class.
239
// *
240
// */
241
// static class Empty {
242
// }
243
}
244
Popular Tags