org.eclipse.help.appserver_3.1.400.v20110425

16:44:54.004 INFO  jd.cli.Main - Decompiling org.eclipse.help.appserver_3.1.400.v20110425.jar
package org.eclipse.help.internal.appserver;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IContributor;
import org.eclipse.core.runtime.IExtension;
import org.eclipse.core.runtime.IExtensionPoint;
import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.core.runtime.ILog;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Plugin;
import org.eclipse.core.runtime.Preferences;
import org.eclipse.core.runtime.Status;
import org.osgi.framework.BundleContext;

public class AppserverPlugin
  extends Plugin
{
  public static final String PLUGIN_ID = "org.eclipse.help.appserver";
  public static final String HOST_KEY = "host";
  public static final String PORT_KEY = "port";
  private static final String APP_SERVER_EXTENSION_ID = "org.eclipse.help.appserver.server";
  private static final String APP_SERVER_CLASS_ATTRIBUTE = "class";
  private static final String APP_SERVER_DEFAULT_ATTRIBUTE = "default";
  private static AppserverPlugin plugin;
  private IWebappServer appServer;
  private String contributingServerPlugin;
  private String hostAddress;
  private int port;
  
  public static AppserverPlugin getDefault()
  {
    return plugin;
  }
  
  public synchronized IWebappServer getAppServer()
    throws CoreException
  {
    if (appServer == null)
    {
      createWebappServer();
      startWebappServer();
    }
    return appServer;
  }
  
  public static synchronized void logError(String message, Throwable ex)
  {
    if (message == null) {
      message = "";
    }
    Status errorStatus = new Status(4, "org.eclipse.help.appserver", 0, 
      message, ex);
    getDefault().getLog().log(errorStatus);
  }
  
  public void stop(BundleContext context)
    throws Exception
  {
    if (appServer != null) {
      appServer.stop();
    }
    plugin = null;
    
    super.stop(context);
  }
  
  public void start(BundleContext context)
    throws Exception
  {
    super.start(context);
    plugin = this;
  }
  
  public String getContributingServerPlugin()
  {
    return contributingServerPlugin;
  }
  
  private void createWebappServer()
    throws CoreException
  {
    IExtensionPoint point = Platform.getExtensionRegistry()
      .getExtensionPoint("org.eclipse.help.appserver.server");
    if (point != null)
    {
      IExtension[] extensions = point.getExtensions();
      if (extensions.length != 0)
      {
        IConfigurationElement[] elements = extensions[0]
          .getConfigurationElements();
        if (elements.length == 0) {
          return;
        }
        IConfigurationElement serverElement = null;
        for (int i = 0; i < elements.length; i++)
        {
          String defaultValue = elements[i]
            .getAttribute("default");
          if ((defaultValue == null) || (defaultValue.equals("false")))
          {
            serverElement = elements[i];
            break;
          }
        }
        if (serverElement == null) {
          serverElement = elements[0];
        }
        try
        {
          appServer = 
            ((IWebappServer)serverElement.createExecutableExtension("class"));
          contributingServerPlugin = serverElement
            .getContributor().getName();
        }
        catch (CoreException e)
        {
          getLog().log(e.getStatus());
          throw e;
        }
      }
    }
  }
  
  private void startWebappServer()
    throws CoreException
  {
    hostAddress = getPluginPreferences().getString("host");
    if ("".equals(hostAddress)) {
      hostAddress = null;
    }
    port = getPluginPreferences().getInt("port");
    try
    {
      String hostCommandLineOverride = System.getProperty("server_host");
      if ((hostCommandLineOverride != null) && 
        (hostCommandLineOverride.trim().length() > 0)) {
        hostAddress = hostCommandLineOverride;
      }
    }
    catch (Exception localException1) {}
    try
    {
      String portCommandLineOverride = System.getProperty("server_port");
      if ((portCommandLineOverride != null) && 
        (portCommandLineOverride.trim().length() > 0)) {
        port = Integer.parseInt(portCommandLineOverride);
      }
    }
    catch (Exception localException2) {}
    if (appServer == null) {
      throw new CoreException(new Status(4, "org.eclipse.help.appserver", 
        0, 
        AppserverResources.Appserver_start, null));
    }
    appServer.start(port, hostAddress);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.help.internal.appserver.AppserverPlugin
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.help.internal.appserver;

import org.eclipse.osgi.util.NLS;

public final class AppserverResources
  extends NLS
{
  private static final String BUNDLE_NAME = "org.eclipse.help.internal.appserver.AppserverResources";
  public static String LocalConnectionTest_cannotGetLocalhostName;
  public static String Appserver_cannotFindPlugin;
  public static String Appserver_cannotFindPath;
  public static String Appserver_cannotResolvePath;
  public static String Appserver_engineRemove;
  public static String Appserver_embeddedStop;
  public static String Appserver_addingWebapp;
  public static String Appserver_start;
  
  static
  {
    NLS.initializeMessages("org.eclipse.help.internal.appserver.AppserverResources", AppserverResources.class);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.help.internal.appserver.AppserverResources
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.help.internal.appserver;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.Properties;
import java.util.StringTokenizer;
import java.util.Vector;

public class DevClassPathHelper
{
  protected static boolean inDevelopmentMode = false;
  protected static String[] devDefaultClasspath;
  protected static Properties devProperties = null;
  
  static
  {
    String osgiDev = System.getProperty("osgi.dev");
    if (osgiDev != null) {
      try
      {
        inDevelopmentMode = true;
        URL location = new URL(osgiDev);
        devProperties = load(location);
        if (devProperties != null) {
          devDefaultClasspath = getArrayFromList(devProperties
            .getProperty("*"));
        }
      }
      catch (MalformedURLException localMalformedURLException)
      {
        devDefaultClasspath = getArrayFromList(osgiDev);
      }
    }
  }
  
  public static String[] getDevClassPath(String id)
  {
    String[] result = (String[])null;
    if ((id != null) && (devProperties != null))
    {
      String entry = devProperties.getProperty(id);
      if (entry != null) {
        result = getArrayFromList(entry);
      }
    }
    if (result == null) {
      result = devDefaultClasspath;
    }
    return result;
  }
  
  public static String[] getArrayFromList(String prop)
  {
    if ((prop == null) || (prop.trim().equals(""))) {
      return new String[0];
    }
    Vector list = new Vector();
    StringTokenizer tokens = new StringTokenizer(prop, ",");
    while (tokens.hasMoreTokens())
    {
      String token = tokens.nextToken().trim();
      if (!token.equals("")) {
        list.addElement(token);
      }
    }
    return list.isEmpty() ? new String[0] : 
      (String[])list.toArray(new String[list.size()]);
  }
  
  public static boolean inDevelopmentMode()
  {
    return inDevelopmentMode;
  }
  
  /* Error */
  private static Properties load(URL url)
  {
    // Byte code:
    //   0: new 74	java/util/Properties
    //   3: dup
    //   4: invokespecial 136	java/util/Properties:<init>	()V
    //   7: astore_1
    //   8: aconst_null
    //   9: astore_2
    //   10: aload_0
    //   11: invokevirtual 134	java/net/URL:openStream	()Ljava/io/InputStream;
    //   14: astore_2
    //   15: aload_1
    //   16: aload_2
    //   17: invokevirtual 137	java/util/Properties:load	(Ljava/io/InputStream;)V
    //   20: goto +14 -> 34
    //   23: astore_3
    //   24: aload_2
    //   25: ifnull +7 -> 32
    //   28: aload_2
    //   29: invokevirtual 126	java/io/InputStream:close	()V
    //   32: aload_3
    //   33: athrow
    //   34: aload_2
    //   35: ifnull +31 -> 66
    //   38: aload_2
    //   39: invokevirtual 126	java/io/InputStream:close	()V
    //   42: goto +24 -> 66
    //   45: astore_2
    //   46: new 70	java/lang/StringBuffer
    //   49: dup
    //   50: ldc 4
    //   52: invokespecial 131	java/lang/StringBuffer:<init>	(Ljava/lang/String;)V
    //   55: aload_0
    //   56: invokevirtual 132	java/lang/StringBuffer:append	(Ljava/lang/Object;)Ljava/lang/StringBuffer;
    //   59: invokevirtual 130	java/lang/StringBuffer:toString	()Ljava/lang/String;
    //   62: aload_2
    //   63: invokestatic 147	org/eclipse/help/internal/appserver/AppserverPlugin:logError	(Ljava/lang/String;Ljava/lang/Throwable;)V
    //   66: aload_1
    //   67: areturn
    // Line number table:
    //   Java source line #85	-> byte code offset #0
    //   Java source line #87	-> byte code offset #8
    //   Java source line #89	-> byte code offset #10
    //   Java source line #90	-> byte code offset #15
    //   Java source line #91	-> byte code offset #23
    //   Java source line #92	-> byte code offset #24
    //   Java source line #93	-> byte code offset #28
    //   Java source line #94	-> byte code offset #32
    //   Java source line #92	-> byte code offset #34
    //   Java source line #93	-> byte code offset #38
    //   Java source line #95	-> byte code offset #45
    //   Java source line #96	-> byte code offset #46
    //   Java source line #98	-> byte code offset #66
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	68	0	url	URL
    //   7	60	1	props	Properties
    //   9	30	2	is	java.io.InputStream
    //   45	18	2	e	java.io.IOException
    //   23	10	3	localObject	Object
    // Exception table:
    //   from	to	target	type
    //   10	23	23	finally
    //   8	42	45	java/io/IOException
  }
}

/* Location:
 * Qualified Name:     org.eclipse.help.internal.appserver.DevClassPathHelper
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.help.internal.appserver;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;

/**
 * @deprecated
 */
public abstract interface IWebappServer
{
  public abstract void start(int paramInt, String paramString)
    throws CoreException;
  
  public abstract void stop()
    throws CoreException;
  
  public abstract boolean isRunning();
  
  public abstract void start(String paramString, IPath paramIPath, ClassLoader paramClassLoader)
    throws CoreException;
  
  public abstract void stop(String paramString)
    throws CoreException;
  
  public abstract int getPort();
  
  public abstract String getHost();
}

/* Location:
 * Qualified Name:     org.eclipse.help.internal.appserver.IWebappServer
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.help.internal.appserver;

import java.io.IOException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.Dictionary;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.Platform;
import org.eclipse.osgi.util.ManifestElement;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleException;

public class PluginClassLoaderWrapper
  extends URLClassLoader
{
  private String plugin;
  private Bundle bundle;
  
  public PluginClassLoaderWrapper(String plugin)
  {
    super(new URL[0]);
    this.plugin = plugin;
    bundle = Platform.getBundle(plugin);
  }
  
  public Class loadClass(String className)
    throws ClassNotFoundException
  {
    return bundle.loadClass(className);
  }
  
  public URL getResource(String resName)
  {
    return bundle.getResource(resName);
  }
  
  public URL[] getURLs()
  {
    Set urls = getPluginClasspath(plugin);
    return (URL[])urls.toArray(new URL[urls.size()]);
  }
  
  private Set getPluginClasspath(String pluginId)
  {
    Set plugins = new HashSet();
    addPluginWithPrereqs(pluginId, plugins);
    
    Set urls = new HashSet();
    for (Iterator it = plugins.iterator(); it.hasNext();)
    {
      String id = (String)it.next();
      try
      {
        Bundle b = Platform.getBundle(id);
        if (b != null)
        {
          String headers = (String)b.getHeaders().get(
            "Bundle-ClassPath");
          ManifestElement[] paths = ManifestElement.parseHeader(
            "Bundle-ClassPath", headers);
          if (paths != null) {
            for (int i = 0; i < paths.length; i++)
            {
              String path = paths[i].getValue();
              URL url = b.getEntry(path);
              if (url != null) {
                try
                {
                  urls.add(FileLocator.toFileURL(url));
                }
                catch (IOException localIOException1) {}
              }
            }
          }
          String[] devpaths = 
            DevClassPathHelper.getDevClassPath(pluginId);
          if (devpaths != null) {
            for (int i = 0; i < devpaths.length; i++)
            {
              URL url = b.getEntry(devpaths[i]);
              if (url != null) {
                try
                {
                  urls.add(FileLocator.toFileURL(url));
                }
                catch (IOException localIOException2) {}
              }
            }
          }
        }
      }
      catch (BundleException localBundleException) {}
    }
    return urls;
  }
  
  private void addPluginWithPrereqs(String pluginId, Set pluginIds)
  {
    if (pluginIds.contains(pluginId)) {
      return;
    }
    String[] immidiatePrereqs = getDirectPrereqs(pluginId);
    for (int i = 0; i < immidiatePrereqs.length; i++) {
      addPluginWithPrereqs(immidiatePrereqs[i], pluginIds);
    }
    pluginIds.add(pluginId);
  }
  
  private String[] getDirectPrereqs(String pluginId)
  {
    try
    {
      Bundle bundle = Platform.getBundle(pluginId);
      if (bundle != null)
      {
        String header = (String)bundle.getHeaders().get(
          "Require-Bundle");
        ManifestElement[] requires = ManifestElement.parseHeader(
          "Require-Bundle", header);
        if (requires != null)
        {
          String[] reqs = new String[requires.length];
          for (int i = 0; i < requires.length; i++) {
            reqs[i] = requires[i].getValue();
          }
          return reqs;
        }
      }
    }
    catch (BundleException localBundleException) {}
    return new String[0];
  }
}

/* Location:
 * Qualified Name:     org.eclipse.help.internal.appserver.PluginClassLoaderWrapper
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.help.internal.appserver;

import java.io.IOException;
import java.net.URL;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
import org.eclipse.osgi.util.NLS;
import org.osgi.framework.Bundle;

/**
 * @deprecated
 */
public class WebappManager
{
  private static boolean applicationsStarted = false;
  
  public static void start(String webappName, String pluginId, IPath path)
    throws CoreException
  {
    IPath webappPath = getWebappPath(pluginId, path);
    
    IWebappServer server = AppserverPlugin.getDefault().getAppServer();
    applicationsStarted = true;
    server.start(webappName, webappPath, new PluginClassLoaderWrapper(
      pluginId));
  }
  
  public static void stop(String webappName)
    throws CoreException
  {
    if (!applicationsStarted) {
      return;
    }
    AppserverPlugin.getDefault().getAppServer().stop(webappName);
  }
  
  public static int getPort()
  {
    try
    {
      return AppserverPlugin.getDefault().getAppServer().getPort();
    }
    catch (CoreException localCoreException) {}
    return 0;
  }
  
  public static String getHost()
  {
    try
    {
      return AppserverPlugin.getDefault().getAppServer().getHost();
    }
    catch (CoreException localCoreException) {}
    return null;
  }
  
  private static IPath getWebappPath(String pluginId, IPath path)
    throws CoreException
  {
    Bundle bundle = Platform.getBundle(pluginId);
    if (bundle == null) {
      throw new CoreException(new Status(4, 
        "org.eclipse.help.appserver", 0, NLS.bind(AppserverResources.Appserver_cannotFindPlugin, pluginId), null));
    }
    URL webappURL = FileLocator.find(bundle, path, null);
    if (webappURL == null) {
      throw new CoreException(new Status(4, 
        "org.eclipse.help.appserver", 0, NLS.bind(AppserverResources.Appserver_cannotFindPath, pluginId, path.toOSString()), null));
    }
    try
    {
      String webappLocation = FileLocator.toFileURL(
        FileLocator.resolve(webappURL)).getFile();
      return new Path(webappLocation);
    }
    catch (IOException ioe)
    {
      throw new CoreException(new Status(4, 
        "org.eclipse.help.appserver", 0, NLS.bind(AppserverResources.Appserver_cannotResolvePath, pluginId, path.toOSString()), ioe));
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.help.internal.appserver.WebappManager
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
1

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2017. Infinite Loop Ltd