1 19 20 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 36 37 42 public class WebServiceModuleInstaller extends ModuleInstall { 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(); persistenceManager.save(specialLoader); 53 } catch (ClassNotFoundException cnfe){ 54 } catch(Exception 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 ex) { 73 ErrorManager.getDefault().notify(ErrorManager.EXCEPTION, ex); 74 } 75 } 76 } 77 78 public static ClassLoader 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(); persistenceManager.load(specialLoader); 87 } catch(Exception ex) { 88 ErrorManager.getDefault().notify(ErrorManager.EXCEPTION, ex); 89 } 90 } 91 92 return specialLoader; 93 } 94 95 private static String 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 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 { 119 try { 120 133 134 String javaVersion = System.getProperty("java.version"); 136 if (javaVersion!=null && javaVersion.startsWith("1.4")) { 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); if (jarFile != null) { 141 loader.addURL(jarFile); 142 } else { 143 return; 145 } 146 } 147 } 148 149 InstalledFileLocator locator = InstalledFileLocator.getDefault(); 150 151 File f = locator.locate("modules/ext/websvcregistry.jar", null, true); 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 String [] 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 } catch(Exception ex) { 174 throw new Exception (ex.getLocalizedMessage(), ex); 175 } 176 } 177 private static void loadLocaleSpecificJars(File file, ExtensionClassLoader loader) { 178 File parentDir = file.getParentFile(); 179 File localeDir = new File(parentDir, "locale"); if(localeDir.exists()){ 182 File[] localeFiles = localeDir.listFiles(); 183 File localeFile = null; 184 String localeFileName = null; 185 String fileName = file.getName(); 186 fileName = getFileNameWithoutExt(fileName); 187 assert(fileName.length() > 0); 189 for(int i=0; i<localeFiles.length; i++){ 190 localeFile = localeFiles[i]; 191 localeFileName = localeFile.getName(); 192 assert(localeFileName.length() > 0); 194 if(localeFileName.startsWith(fileName)){ 195 try{ 196 loader.addURL(localeFile); 197 }catch (Exception ex2) { 198 System.out.println(ex2.getLocalizedMessage()); 199 } 200 } 201 } 202 } 203 } 204 205 private static String getFileNameWithoutExt(String fileName){ 206 int index = fileName.lastIndexOf("."); if(index != -1){ 208 fileName = fileName.substring(0, index); 209 } 210 return fileName; 211 } 212 213 } 244 | Popular Tags |