1 11 package org.eclipse.help.internal.appserver; 12 13 import java.io.*; 14 import java.net.*; 15 16 import org.eclipse.core.runtime.*; 17 import org.eclipse.osgi.util.NLS; 18 import org.osgi.framework.*; 19 20 30 public class WebappManager { 31 private static boolean applicationsStarted = false; 32 33 38 private WebappManager() { 39 } 40 41 56 public static void start(String webappName, String pluginId, IPath path) 57 throws CoreException { 58 59 IPath webappPath = getWebappPath(pluginId, path); 60 61 IWebappServer server = AppserverPlugin.getDefault().getAppServer(); 64 applicationsStarted = true; 65 server.start(webappName, webappPath, new PluginClassLoaderWrapper( 66 pluginId)); 67 } 68 69 72 public static void stop(String webappName) throws CoreException { 73 if (!applicationsStarted) { 74 return; 76 } 77 AppserverPlugin.getDefault().getAppServer().stop(webappName); 78 } 79 80 85 public static int getPort() { 86 try { 87 return AppserverPlugin.getDefault().getAppServer().getPort(); 88 } catch (CoreException e) { 89 return 0; 90 } 91 } 92 93 99 public static String getHost() { 100 try { 101 return AppserverPlugin.getDefault().getAppServer().getHost(); 102 } catch (CoreException e) { 103 return null; 104 } 105 } 106 107 113 private static IPath getWebappPath(String pluginId, IPath path) 114 throws CoreException { 115 116 Bundle bundle = Platform.getBundle(pluginId); 117 if (bundle == null) { 118 throw new CoreException(new Status(IStatus.ERROR, 119 AppserverPlugin.PLUGIN_ID, IStatus.OK, NLS.bind(AppserverResources.Appserver_cannotFindPlugin, pluginId), null)); 120 } 121 122 URL webappURL = FileLocator.find(bundle, path, null); 125 if (webappURL == null) { 126 throw new CoreException(new Status(IStatus.ERROR, 127 AppserverPlugin.PLUGIN_ID, IStatus.OK, NLS.bind(AppserverResources.Appserver_cannotFindPath, pluginId, path.toOSString()), null)); 128 } 129 130 try { 131 String webappLocation = FileLocator.toFileURL( 132 FileLocator.resolve(webappURL)).getFile(); 133 return new Path(webappLocation); 134 } catch (IOException ioe) { 135 throw new CoreException(new Status(IStatus.ERROR, 136 AppserverPlugin.PLUGIN_ID, IStatus.OK, NLS.bind(AppserverResources.Appserver_cannotResolvePath, pluginId, path.toOSString()), ioe)); 137 } 138 } 139 } 140 | Popular Tags |