org.eclipse.equinox.http.registry_1.1.200.v20120912-130548

16:43:56.441 INFO  jd.cli.Main - Decompiling org.eclipse.equinox.http.registry_1.1.200.v20120912-130548.jar
package org.eclipse.equinox.http.registry;

import org.osgi.framework.ServiceReference;
import org.osgi.service.http.HttpContext;

public abstract interface HttpContextExtensionService
{
  public abstract HttpContext getHttpContext(ServiceReference paramServiceReference, String paramString);
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.http.registry.HttpContextExtensionService
 * Java Class Version: 1.1 (45.3)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.http.registry.internal;

import org.eclipse.core.runtime.IExtensionRegistry;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
import org.osgi.service.packageadmin.PackageAdmin;
import org.osgi.util.tracker.ServiceTracker;
import org.osgi.util.tracker.ServiceTrackerCustomizer;

public class Activator
  implements BundleActivator, ServiceTrackerCustomizer
{
  private ServiceTracker httpServiceTracker;
  private ServiceTracker packageAdminTracker;
  private ServiceTracker registryTracker;
  private PackageAdmin packageAdmin;
  private IExtensionRegistry registry;
  private BundleContext context;
  
  public void start(BundleContext context)
    throws Exception
  {
    this.context = context;
    packageAdminTracker = new ServiceTracker(context, PackageAdmin.class.getName(), this);
    packageAdminTracker.open();
    
    registryTracker = new ServiceTracker(context, IExtensionRegistry.class.getName(), this);
    registryTracker.open();
  }
  
  public void stop(BundleContext context)
    throws Exception
  {
    packageAdminTracker.close();
    packageAdminTracker = null;
    registryTracker.close();
    registryTracker = null;
    this.context = null;
  }
  
  public Object addingService(ServiceReference reference)
  {
    Object service = context.getService(reference);
    if (((service instanceof PackageAdmin)) && (packageAdmin == null)) {
      packageAdmin = ((PackageAdmin)service);
    }
    if (((service instanceof IExtensionRegistry)) && (registry == null)) {
      registry = ((IExtensionRegistry)service);
    }
    if ((packageAdmin != null) && (registry != null))
    {
      httpServiceTracker = new HttpServiceTracker(context, packageAdmin, registry);
      httpServiceTracker.open();
    }
    return service;
  }
  
  public void modifiedService(ServiceReference reference, Object service) {}
  
  public void removedService(ServiceReference reference, Object service)
  {
    if (service == packageAdmin) {
      packageAdmin = null;
    }
    if (service == registry) {
      registry = null;
    }
    if (((packageAdmin == null) || (registry == null)) && 
      (httpServiceTracker != null))
    {
      httpServiceTracker.close();
      httpServiceTracker = null;
    }
    context.ungetService(reference);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.http.registry.internal.Activator
 * Java Class Version: 1.1 (45.3)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.http.registry.internal;

import java.net.URL;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.Set;
import org.osgi.framework.Bundle;

public class DefaultRegistryHttpContext$ResourceMapping
{
  private Bundle bundle;
  private String bundlePath;
  
  public DefaultRegistryHttpContext$ResourceMapping(Bundle bundle, String path)
  {
    this.bundle = bundle;
    if (path != null)
    {
      if (path.endsWith("/")) {
        path = path.substring(0, path.length() - 1);
      }
      if (path.length() == 0) {
        path = null;
      }
    }
    bundlePath = path;
  }
  
  public URL getResource(String resourceName)
  {
    if (bundlePath != null) {
      resourceName = bundlePath + resourceName;
    }
    int lastSlash = resourceName.lastIndexOf('/');
    if (lastSlash == -1) {
      return null;
    }
    String path = resourceName.substring(0, lastSlash);
    if (path.length() == 0) {
      path = "/";
    }
    String file = sanitizeEntryName(resourceName.substring(lastSlash + 1));
    Enumeration entryPaths = bundle.findEntries(path, file, false);
    if ((entryPaths != null) && (entryPaths.hasMoreElements())) {
      return (URL)entryPaths.nextElement();
    }
    return null;
  }
  
  private String sanitizeEntryName(String name)
  {
    StringBuffer buffer = null;
    for (int i = 0; i < name.length(); i++)
    {
      char c = name.charAt(i);
      switch (c)
      {
      case '*': 
      case '\\': 
        if (buffer == null)
        {
          buffer = new StringBuffer(name.length() + 16);
          buffer.append(name.substring(0, i));
        }
        buffer.append('\\').append(c);
        break;
      default: 
        if (buffer != null) {
          buffer.append(c);
        }
        break;
      }
    }
    return buffer == null ? name : buffer.toString();
  }
  
  public Set getResourcePaths(String path)
  {
    if (bundlePath != null) {
      path = bundlePath + path;
    }
    Enumeration entryPaths = bundle.findEntries(path, null, false);
    if (entryPaths == null) {
      return null;
    }
    Set result = new HashSet();
    while (entryPaths.hasMoreElements())
    {
      URL entryURL = (URL)entryPaths.nextElement();
      String entryPath = entryURL.getFile();
      if (bundlePath == null) {
        result.add(entryPath);
      } else {
        result.add(entryPath.substring(bundlePath.length()));
      }
    }
    return result;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.http.registry.internal.DefaultRegistryHttpContext.ResourceMapping
 * Java Class Version: 1.1 (45.3)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.http.registry.internal;

import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import java.util.Properties;
import java.util.Set;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.osgi.framework.Bundle;
import org.osgi.service.http.HttpContext;

public class DefaultRegistryHttpContext
  implements HttpContext
{
  private HttpContext delegate;
  private List resourceMappings;
  private Properties mimeMappings;
  
  public DefaultRegistryHttpContext(HttpContext delegate)
  {
    this.delegate = delegate;
  }
  
  public void addResourceMapping(Bundle contributingBundle, String path)
  {
    if (resourceMappings == null) {
      resourceMappings = new ArrayList();
    }
    resourceMappings.add(new ResourceMapping(contributingBundle, path));
  }
  
  public void addMimeMapping(String mimeExtension, String mimeType)
  {
    if (mimeMappings == null) {
      mimeMappings = new Properties();
    }
    mimeMappings.put(mimeExtension, mimeType);
  }
  
  public String getMimeType(String name)
  {
    if (mimeMappings != null)
    {
      int dotIndex = name.lastIndexOf('.');
      if (dotIndex != -1)
      {
        String mimeExtension = name.substring(dotIndex + 1);
        String mimeType = mimeMappings.getProperty(mimeExtension);
        if (mimeType != null) {
          return mimeType;
        }
      }
    }
    return delegate.getMimeType(name);
  }
  
  public boolean handleSecurity(HttpServletRequest arg0, HttpServletResponse arg1)
    throws IOException
  {
    return delegate.handleSecurity(arg0, arg1);
  }
  
  public URL getResource(String name)
  {
    if (resourceMappings == null) {
      return null;
    }
    for (Iterator it = resourceMappings.iterator(); it.hasNext();)
    {
      ResourceMapping mapping = (ResourceMapping)it.next();
      URL resourceURL = mapping.getResource(name);
      if (resourceURL != null) {
        return resourceURL;
      }
    }
    return null;
  }
  
  public Set getResourcePaths(String path)
  {
    if ((resourceMappings == null) || (path == null) || (!path.startsWith("/"))) {
      return null;
    }
    Set result = null;
    for (Iterator it = resourceMappings.iterator(); it.hasNext();)
    {
      ResourceMapping mapping = (ResourceMapping)it.next();
      Set resourcePaths = mapping.getResourcePaths(path);
      if (resourcePaths != null)
      {
        if (result == null) {
          result = new HashSet();
        }
        result.addAll(resourcePaths);
      }
    }
    return result;
  }
  
  public static class ResourceMapping
  {
    private Bundle bundle;
    private String bundlePath;
    
    public ResourceMapping(Bundle bundle, String path)
    {
      this.bundle = bundle;
      if (path != null)
      {
        if (path.endsWith("/")) {
          path = path.substring(0, path.length() - 1);
        }
        if (path.length() == 0) {
          path = null;
        }
      }
      bundlePath = path;
    }
    
    public URL getResource(String resourceName)
    {
      if (bundlePath != null) {
        resourceName = bundlePath + resourceName;
      }
      int lastSlash = resourceName.lastIndexOf('/');
      if (lastSlash == -1) {
        return null;
      }
      String path = resourceName.substring(0, lastSlash);
      if (path.length() == 0) {
        path = "/";
      }
      String file = sanitizeEntryName(resourceName.substring(lastSlash + 1));
      Enumeration entryPaths = bundle.findEntries(path, file, false);
      if ((entryPaths != null) && (entryPaths.hasMoreElements())) {
        return (URL)entryPaths.nextElement();
      }
      return null;
    }
    
    private String sanitizeEntryName(String name)
    {
      StringBuffer buffer = null;
      for (int i = 0; i < name.length(); i++)
      {
        char c = name.charAt(i);
        switch (c)
        {
        case '*': 
        case '\\': 
          if (buffer == null)
          {
            buffer = new StringBuffer(name.length() + 16);
            buffer.append(name.substring(0, i));
          }
          buffer.append('\\').append(c);
          break;
        default: 
          if (buffer != null) {
            buffer.append(c);
          }
          break;
        }
      }
      return buffer == null ? name : buffer.toString();
    }
    
    public Set getResourcePaths(String path)
    {
      if (bundlePath != null) {
        path = bundlePath + path;
      }
      Enumeration entryPaths = bundle.findEntries(path, null, false);
      if (entryPaths == null) {
        return null;
      }
      Set result = new HashSet();
      while (entryPaths.hasMoreElements())
      {
        URL entryURL = (URL)entryPaths.nextElement();
        String entryPath = entryURL.getFile();
        if (bundlePath == null) {
          result.add(entryPath);
        } else {
          result.add(entryPath.substring(bundlePath.length()));
        }
      }
      return result;
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.http.registry.internal.DefaultRegistryHttpContext
 * Java Class Version: 1.1 (45.3)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.http.registry.internal;

import org.eclipse.core.runtime.IExtension;

class ExtensionPointTracker$1
  implements ExtensionPointTracker.Listener
{
  public void added(IExtension extension) {}
  
  public void removed(IExtension extension) {}
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.http.registry.internal.ExtensionPointTracker.1
 * Java Class Version: 1.1 (45.3)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.http.registry.internal;

import org.eclipse.core.runtime.IExtension;

public abstract interface ExtensionPointTracker$Listener
{
  public abstract void added(IExtension paramIExtension);
  
  public abstract void removed(IExtension paramIExtension);
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.http.registry.internal.ExtensionPointTracker.Listener
 * Java Class Version: 1.1 (45.3)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.http.registry.internal;

import org.eclipse.core.runtime.IExtension;
import org.eclipse.core.runtime.IExtensionDelta;
import org.eclipse.core.runtime.IRegistryChangeEvent;
import org.eclipse.core.runtime.IRegistryChangeListener;

class ExtensionPointTracker$RegistryChangeListener
  implements IRegistryChangeListener
{
  final ExtensionPointTracker this$0;
  
  ExtensionPointTracker$RegistryChangeListener(ExtensionPointTracker paramExtensionPointTracker)
  {
    this$0 = paramExtensionPointTracker;
  }
  
  public void registryChanged(IRegistryChangeEvent event)
  {
    IExtensionDelta[] deltas = event.getExtensionDeltas(this$0.namespace, this$0.simpleIdentifier);
    for (int i = 0; i < deltas.length; i++)
    {
      IExtensionDelta delta = deltas[i];
      IExtension extension = delta.getExtension();
      switch (delta.getKind())
      {
      case 1: 
        if (this$0.addExtension(extension)) {
          this$0.listener.added(extension);
        }
        break;
      case 2: 
        if (this$0.removeExtension(extension)) {
          this$0.listener.removed(extension);
        }
        break;
      }
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.http.registry.internal.ExtensionPointTracker.RegistryChangeListener
 * Java Class Version: 1.1 (45.3)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.http.registry.internal;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import org.eclipse.core.runtime.IExtension;
import org.eclipse.core.runtime.IExtensionDelta;
import org.eclipse.core.runtime.IExtensionPoint;
import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.core.runtime.IRegistryChangeEvent;
import org.eclipse.core.runtime.IRegistryChangeListener;
import org.eclipse.core.runtime.InvalidRegistryObjectException;

public class ExtensionPointTracker
{
  private static final Listener NULL_LISTENER = new Listener()
  {
    public void added(IExtension extension) {}
    
    public void removed(IExtension extension) {}
  };
  private final IExtensionRegistry registry;
  private final String extensionPointId;
  final String namespace;
  final String simpleIdentifier;
  private final Set extensionCache = new HashSet();
  protected final Listener listener;
  private final RegistryChangeListener registryChangeListener = new RegistryChangeListener();
  private boolean closed = true;
  
  public ExtensionPointTracker(IExtensionRegistry registry, String extensionPointId, Listener listener)
  {
    this.registry = registry;
    this.extensionPointId = extensionPointId;
    this.listener = (listener != null ? listener : NULL_LISTENER);
    if ((extensionPointId == null) || (-1 == extensionPointId.indexOf('.'))) {
      throw new IllegalArgumentException("Unexpected Extension Point Identifier: " + extensionPointId);
    }
    int lastDotIndex = extensionPointId.lastIndexOf('.');
    namespace = extensionPointId.substring(0, lastDotIndex);
    simpleIdentifier = extensionPointId.substring(lastDotIndex + 1);
  }
  
  public void open()
  {
    IExtension[] extensions = null;
    synchronized (this)
    {
      if (!closed) {
        return;
      }
      registry.addRegistryChangeListener(registryChangeListener, namespace);
      try
      {
        IExtensionPoint point = registry.getExtensionPoint(extensionPointId);
        if (point != null)
        {
          extensions = point.getExtensions();
          extensionCache.addAll(Arrays.asList(extensions));
        }
        closed = false;
      }
      catch (InvalidRegistryObjectException e)
      {
        registry.removeRegistryChangeListener(registryChangeListener);
        throw e;
      }
    }
    if (extensions != null) {
      for (int i = 0; i < extensions.length; i++) {
        listener.added(extensions[i]);
      }
    }
  }
  
  public void close()
  {
    IExtension[] extensions = null;
    synchronized (this)
    {
      if (closed) {
        return;
      }
      closed = true;
      registry.removeRegistryChangeListener(registryChangeListener);
      extensions = getExtensions();
      extensionCache.clear();
    }
    for (int i = 0; i < extensions.length; i++) {
      listener.removed(extensions[i]);
    }
  }
  
  synchronized boolean removeExtension(IExtension extension)
  {
    if (closed) {
      return false;
    }
    return extensionCache.remove(extension);
  }
  
  synchronized boolean addExtension(IExtension extension)
  {
    if (closed) {
      return false;
    }
    return extensionCache.add(extension);
  }
  
  public synchronized IExtension[] getExtensions()
  {
    return (IExtension[])extensionCache.toArray(new IExtension[extensionCache.size()]);
  }
  
  public static abstract interface Listener
  {
    public abstract void added(IExtension paramIExtension);
    
    public abstract void removed(IExtension paramIExtension);
  }
  
  class RegistryChangeListener
    implements IRegistryChangeListener
  {
    RegistryChangeListener() {}
    
    public void registryChanged(IRegistryChangeEvent event)
    {
      IExtensionDelta[] deltas = event.getExtensionDeltas(namespace, simpleIdentifier);
      for (int i = 0; i < deltas.length; i++)
      {
        IExtensionDelta delta = deltas[i];
        IExtension extension = delta.getExtension();
        switch (delta.getKind())
        {
        case 1: 
          if (addExtension(extension)) {
            listener.added(extension);
          }
          break;
        case 2: 
          if (removeExtension(extension)) {
            listener.removed(extension);
          }
          break;
        }
      }
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.http.registry.internal.ExtensionPointTracker
 * Java Class Version: 1.1 (45.3)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.http.registry.internal;

import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;

class FilterManager$FilterWrapper
  implements Filter
{
  private IConfigurationElement element;
  private Filter delegate;
  private FilterConfig config;
  private boolean loadOnStartup = false;
  
  public FilterManager$FilterWrapper(IConfigurationElement element)
  {
    this.element = element;
  }
  
  public void setLoadOnStartup()
  {
    loadOnStartup = true;
  }
  
  public void init(FilterConfig filterConfig)
    throws ServletException
  {
    config = filterConfig;
    if (loadOnStartup) {
      initializeDelegate();
    }
  }
  
  public void doFilter(ServletRequest arg0, ServletResponse arg1, FilterChain chain)
    throws ServletException, IOException
  {
    initializeDelegate();
    delegate.doFilter(arg0, arg1, chain);
  }
  
  public void destroy()
  {
    destroyDelegate();
  }
  
  private synchronized void initializeDelegate()
    throws ServletException
  {
    if (delegate == null) {
      try
      {
        Filter newDelegate = (Filter)element.createExecutableExtension("class");
        newDelegate.init(config);
        delegate = newDelegate;
      }
      catch (CoreException e)
      {
        throw new ServletException(e);
      }
    }
  }
  
  private synchronized void destroyDelegate()
  {
    if (delegate != null)
    {
      Filter doomedDelegate = delegate;
      delegate = null;
      doomedDelegate.destroy();
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.http.registry.internal.FilterManager.FilterWrapper
 * Java Class Version: 1.1 (45.3)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.http.registry.internal;

import java.io.IOException;
import java.util.Dictionary;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Map;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtension;
import org.eclipse.core.runtime.IExtensionRegistry;
import org.osgi.framework.FrameworkUtil;
import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.ServiceReference;

public class FilterManager
  implements ExtensionPointTracker.Listener
{
  private static final String FILTERS_EXTENSION_POINT = "org.eclipse.equinox.http.registry.filters";
  private static final String HTTPCONTEXT_NAME = "httpcontext-name";
  private static final String PARAM_VALUE = "value";
  private static final String PARAM_NAME = "name";
  private static final String INIT_PARAM = "init-param";
  private static final String ALIAS = "alias";
  private static final String LOAD_ON_STARTUP = "load-on-startup";
  private static final String HTTPCONTEXT_ID = "httpcontextId";
  private static final String SERVICESELECTOR = "serviceSelector";
  private static final String CLASS = "class";
  private static final String FILTER = "filter";
  private ExtensionPointTracker tracker;
  private HttpRegistryManager httpRegistryManager;
  private Map registered = new HashMap();
  private ServiceReference reference;
  
  public FilterManager(HttpRegistryManager httpRegistryManager, ServiceReference reference, IExtensionRegistry registry)
  {
    this.httpRegistryManager = httpRegistryManager;
    this.reference = reference;
    tracker = new ExtensionPointTracker(registry, "org.eclipse.equinox.http.registry.filters", this);
  }
  
  public void start()
  {
    tracker.open();
  }
  
  public void stop()
  {
    tracker.close();
  }
  
  public void added(IExtension extension)
  {
    IConfigurationElement[] elements = extension.getConfigurationElements();
    for (int i = 0; i < elements.length; i++)
    {
      IConfigurationElement serviceSelectorElement = elements[i];
      if ("serviceSelector".equals(serviceSelectorElement.getName()))
      {
        org.osgi.framework.Filter serviceSelector = null;
        String clazz = serviceSelectorElement.getAttribute("class");
        if (clazz != null)
        {
          try
          {
            serviceSelector = (org.osgi.framework.Filter)serviceSelectorElement.createExecutableExtension("class");
          }
          catch (CoreException e)
          {
            e.printStackTrace();
            return;
          }
        }
        else
        {
          String filter = serviceSelectorElement.getAttribute("filter");
          if (filter == null) {
            return;
          }
          try
          {
            serviceSelector = FrameworkUtil.createFilter(filter);
          }
          catch (InvalidSyntaxException e)
          {
            e.printStackTrace();
            return;
          }
        }
        if (serviceSelector.match(reference)) {
          break;
        }
        return;
      }
    }
    for (int i = 0; i < elements.length; i++)
    {
      IConfigurationElement filterElement = elements[i];
      if ("filter".equals(filterElement.getName()))
      {
        FilterWrapper wrapper = new FilterWrapper(filterElement);
        String alias = filterElement.getAttribute("alias");
        if (alias != null)
        {
          Dictionary initparams = new Hashtable();
          IConfigurationElement[] initParams = filterElement.getChildren("init-param");
          for (int j = 0; j < initParams.length; j++)
          {
            String paramName = initParams[j].getAttribute("name");
            String paramValue = initParams[j].getAttribute("value");
            initparams.put(paramName, paramValue);
          }
          boolean loadOnStartup = new Boolean(filterElement.getAttribute("load-on-startup")).booleanValue();
          if (loadOnStartup) {
            wrapper.setLoadOnStartup();
          }
          String httpContextId = filterElement.getAttribute("httpcontextId");
          if (httpContextId == null) {
            httpContextId = filterElement.getAttribute("httpcontext-name");
          }
          if ((httpContextId != null) && (httpContextId.indexOf('.') == -1)) {
            httpContextId = filterElement.getNamespaceIdentifier() + "." + httpContextId;
          }
          if (httpRegistryManager.addFilterContribution(alias, wrapper, initparams, httpContextId, extension.getContributor())) {
            registered.put(filterElement, wrapper);
          }
        }
      }
    }
  }
  
  public void removed(IExtension extension)
  {
    IConfigurationElement[] elements = extension.getConfigurationElements();
    for (int i = 0; i < elements.length; i++)
    {
      IConfigurationElement filterElement = elements[i];
      javax.servlet.Filter filter = (javax.servlet.Filter)registered.remove(filterElement);
      if (filter != null) {
        httpRegistryManager.removeFilterContribution(filter);
      }
    }
  }
  
  private static class FilterWrapper
    implements javax.servlet.Filter
  {
    private IConfigurationElement element;
    private javax.servlet.Filter delegate;
    private FilterConfig config;
    private boolean loadOnStartup = false;
    
    public FilterWrapper(IConfigurationElement element)
    {
      this.element = element;
    }
    
    public void setLoadOnStartup()
    {
      loadOnStartup = true;
    }
    
    public void init(FilterConfig filterConfig)
      throws ServletException
    {
      config = filterConfig;
      if (loadOnStartup) {
        initializeDelegate();
      }
    }
    
    public void doFilter(ServletRequest arg0, ServletResponse arg1, FilterChain chain)
      throws ServletException, IOException
    {
      initializeDelegate();
      delegate.doFilter(arg0, arg1, chain);
    }
    
    public void destroy()
    {
      destroyDelegate();
    }
    
    private synchronized void initializeDelegate()
      throws ServletException
    {
      if (delegate == null) {
        try
        {
          javax.servlet.Filter newDelegate = (javax.servlet.Filter)element.createExecutableExtension("class");
          newDelegate.init(config);
          delegate = newDelegate;
        }
        catch (CoreException e)
        {
          throw new ServletException(e);
        }
      }
    }
    
    private synchronized void destroyDelegate()
    {
      if (delegate != null)
      {
        javax.servlet.Filter doomedDelegate = delegate;
        delegate = null;
        doomedDelegate.destroy();
      }
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.http.registry.internal.FilterManager
 * Java Class Version: 1.1 (45.3)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.http.registry.internal;

import java.util.ArrayList;
import java.util.List;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtension;
import org.eclipse.core.runtime.IExtensionRegistry;
import org.osgi.framework.AdminPermission;
import org.osgi.framework.Bundle;
import org.osgi.service.http.HttpContext;

public class HttpContextManager
  implements ExtensionPointTracker.Listener
{
  private static final String HTTPCONTEXTS_EXTENSION_POINT = "org.eclipse.equinox.http.registry.httpcontexts";
  private static final String HTTPCONTEXT = "httpcontext";
  private static final String NAME = "name";
  private static final String ID = "id";
  private static final String CLASS = "class";
  private static final String PATH = "path";
  private static final String MIMEMAPPING = "mime-mapping";
  private static final String MIMEEXTENSION = "extension";
  private static final String MIMETYPE = "mime-type";
  private static final String RESOURCEMAPPING = "resource-mapping";
  private static final String BUNDLE = "bundle";
  private List registered = new ArrayList();
  private HttpRegistryManager httpRegistryManager;
  private ExtensionPointTracker tracker;
  
  public HttpContextManager(HttpRegistryManager httpRegistryManager, IExtensionRegistry registry)
  {
    this.httpRegistryManager = httpRegistryManager;
    tracker = new ExtensionPointTracker(registry, "org.eclipse.equinox.http.registry.httpcontexts", this);
  }
  
  public void start()
  {
    tracker.open();
  }
  
  public void stop()
  {
    tracker.close();
  }
  
  public void added(IExtension extension)
  {
    IConfigurationElement[] elements = extension.getConfigurationElements();
    for (int i = 0; i < elements.length; i++)
    {
      IConfigurationElement httpContextElement = elements[i];
      if ("httpcontext".equals(httpContextElement.getName()))
      {
        String httpContextId = httpContextElement.getAttribute("id");
        if (httpContextId == null)
        {
          httpContextId = httpContextElement.getAttribute("name");
          if (httpContextId == null) {}
        }
        else
        {
          if (httpContextId.indexOf('.') == -1) {
            httpContextId = httpContextElement.getNamespaceIdentifier() + "." + httpContextId;
          }
          HttpContext context = null;
          String clazz = httpContextElement.getAttribute("class");
          if (clazz != null)
          {
            try
            {
              context = (HttpContext)httpContextElement.createExecutableExtension("class");
            }
            catch (CoreException e)
            {
              e.printStackTrace();
              continue;
            }
          }
          else
          {
            Bundle contributingBundle = httpRegistryManager.getBundle(extension.getContributor());
            DefaultRegistryHttpContext defaultContext = httpRegistryManager.createDefaultRegistryHttpContext();
            
            String oldPath = httpContextElement.getAttribute("path");
            if (oldPath != null) {
              defaultContext.addResourceMapping(contributingBundle, oldPath);
            }
            IConfigurationElement[] resourceMappingElements = httpContextElement.getChildren("resource-mapping");
            for (int j = 0; j < resourceMappingElements.length; j++)
            {
              IConfigurationElement resourceMappingElement = resourceMappingElements[j];
              String path = resourceMappingElement.getAttribute("path");
              Bundle resourceBundle = contributingBundle;
              String bundleName = resourceMappingElement.getAttribute("bundle");
              if (bundleName != null)
              {
                resourceBundle = httpRegistryManager.getBundle(bundleName);
                if (resourceBundle == null) {
                  continue;
                }
                if (System.getSecurityManager() != null)
                {
                  AdminPermission resourcePermission = new AdminPermission(resourceBundle, "resource");
                  if (!contributingBundle.hasPermission(resourcePermission)) {
                    continue;
                  }
                }
              }
              defaultContext.addResourceMapping(resourceBundle, path);
            }
            IConfigurationElement[] mimeMappingElements = httpContextElement.getChildren("mime-mapping");
            for (int j = 0; j < mimeMappingElements.length; j++)
            {
              IConfigurationElement mimeMappingElement = mimeMappingElements[j];
              String mimeExtension = mimeMappingElement.getAttribute("extension");
              String mimeType = mimeMappingElement.getAttribute("mime-type");
              defaultContext.addMimeMapping(mimeExtension, mimeType);
            }
            context = defaultContext;
          }
          if (httpRegistryManager.addHttpContextContribution(httpContextId, context, extension.getContributor())) {
            registered.add(httpContextElement);
          }
        }
      }
    }
  }
  
  public void removed(IExtension extension)
  {
    IConfigurationElement[] elements = extension.getConfigurationElements();
    for (int i = 0; i < elements.length; i++)
    {
      IConfigurationElement httpContextElement = elements[i];
      if ("httpcontext".equals(httpContextElement.getName()))
      {
        String httpContextId = httpContextElement.getAttribute("id");
        if (httpContextId == null)
        {
          httpContextId = httpContextElement.getAttribute("name");
          if (httpContextId == null) {}
        }
        else
        {
          if (httpContextId.indexOf('.') == -1) {
            httpContextId = httpContextElement.getNamespaceIdentifier() + "." + httpContextId;
          }
          if (registered.remove(httpContextElement)) {
            httpRegistryManager.removeHttpContextContribution(httpContextId);
          }
        }
      }
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.http.registry.internal.HttpContextManager
 * Java Class Version: 1.1 (45.3)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.http.registry.internal;

import java.util.Dictionary;
import javax.servlet.Filter;
import org.eclipse.core.runtime.IContributor;

class HttpRegistryManager$FilterContribution
{
  String alias;
  Filter filter;
  Dictionary initparams;
  String httpContextId;
  IContributor contributor;
  final HttpRegistryManager this$0;
  
  public HttpRegistryManager$FilterContribution(HttpRegistryManager paramHttpRegistryManager, String alias, Filter filter, Dictionary initparams, String httpContextId, IContributor contributor)
  {
    this$0 = paramHttpRegistryManager;
    this.alias = alias;
    this.filter = filter;
    this.initparams = initparams;
    this.httpContextId = httpContextId;
    this.contributor = contributor;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.http.registry.internal.HttpRegistryManager.FilterContribution
 * Java Class Version: 1.1 (45.3)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.http.registry.internal;

import org.eclipse.core.runtime.IContributor;
import org.osgi.service.http.HttpContext;

class HttpRegistryManager$HttpContextContribution
{
  HttpContext context;
  IContributor contributor;
  final HttpRegistryManager this$0;
  
  public HttpRegistryManager$HttpContextContribution(HttpRegistryManager paramHttpRegistryManager, HttpContext context, IContributor contributor)
  {
    this$0 = paramHttpRegistryManager;
    this.context = context;
    this.contributor = contributor;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.http.registry.internal.HttpRegistryManager.HttpContextContribution
 * Java Class Version: 1.1 (45.3)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.http.registry.internal;

import org.eclipse.core.runtime.IContributor;

class HttpRegistryManager$ResourcesContribution
{
  String alias;
  String baseName;
  String httpContextId;
  IContributor contributor;
  final HttpRegistryManager this$0;
  
  public HttpRegistryManager$ResourcesContribution(HttpRegistryManager paramHttpRegistryManager, String alias, String baseName, String httpContextId, IContributor contributor)
  {
    this$0 = paramHttpRegistryManager;
    this.alias = alias;
    this.baseName = baseName;
    this.httpContextId = httpContextId;
    this.contributor = contributor;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.http.registry.internal.HttpRegistryManager.ResourcesContribution
 * Java Class Version: 1.1 (45.3)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.http.registry.internal;

import java.util.Dictionary;
import javax.servlet.Servlet;
import org.eclipse.core.runtime.IContributor;

class HttpRegistryManager$ServletContribution
{
  String alias;
  Servlet servlet;
  Dictionary initparams;
  String httpContextId;
  IContributor contributor;
  final HttpRegistryManager this$0;
  
  public HttpRegistryManager$ServletContribution(HttpRegistryManager paramHttpRegistryManager, String alias, Servlet servlet, Dictionary initparams, String httpContextId, IContributor contributor)
  {
    this$0 = paramHttpRegistryManager;
    this.alias = alias;
    this.servlet = servlet;
    this.initparams = initparams;
    this.httpContextId = httpContextId;
    this.contributor = contributor;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.equinox.http.registry.internal.HttpRegistryManager.ServletContribution
 * Java Class Version: 1.1 (45.3)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.equinox.http.registry.internal;

import java.io.PrintStream;
import java.lang.reflect.Method;
import java.util.Collection;
import java.util.Dictionary;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import javax.servlet.Filter;
import javax.servlet.Servlet;
import javax.servlet.ServletException;
import org.eclipse.core.runtime.IContributor;
import org.eclipse.core.runtime.IExtensionRegistry;
import org.osgi.framework.AdminPermission;
import org.osgi.framework.Bundle;
import org.osgi.framework.ServiceReference;
import org.osgi.service.http.HttpContext;
import org.osgi.service.http.HttpService;
import org.osgi.service.http.NamespaceException;
import org.osgi.service.packageadmin.PackageAdmin;

public class HttpRegistryManager
{
  private HttpContextManager httpContextManager;
  private ServletManager servletManager;
  private FilterManager filterManager;
  private ResourceManager resourceManager;
  private HttpService httpService;
  private PackageAdmin packageAdmin;
  
  class ResourcesContribution
  {
    String alias;
    String baseName;
    String httpContextId;
    IContributor contributor;
    
    public ResourcesContribution(String alias, String baseName, String httpContextId, IContributor contributor)
    {
      this.alias = alias;
      this.baseName = baseName;
      this.httpContextId = httpContextId;
      this.contributor = contributor;
    }
  }
  
  class ServletContribution
  {
    String alias;
    Servlet servlet;
    Dictionary initparams;
    String httpContextId;
    IContributor contributor;
    
    public ServletContribution(String alias, Servlet servlet, Dictionary initparams, String httpContextId, IContributor contributor)
    {
      this.alias = alias;
      this.servlet = servlet;
      this.initparams = initparams;
      this.httpContextId = httpContextId;
      this.contributor = contributor;
    }
  }
  
  class FilterContribution
  {
    String alias;
    Filter filter;
    Dictionary initparams;
    String httpContextId;
    IContributor contributor;
    
    public FilterContribution(String alias, Filter filter, Dictionary initparams, String httpContextId, IContributor contributor)
    {
      this.alias = alias;
      this.filter = filter;
      this.initparams = initparams;
      this.httpContextId = httpContextId;
      this.contributor = contributor;
    }
  }
  
  class HttpContextContribution
  {
    HttpContext context;
    IContributor contributor;
    
    public HttpContextContribution(HttpContext context, IContributor contributor)
    {
      this.context = context;
      this.contributor = contributor;
    }
  }
  
  private Map contexts = new HashMap();
  private Map filters = new HashMap();
  private Map servlets = new HashMap();
  private Map resources = new HashMap();
  private Set registered = new HashSet();
  
  public HttpRegistryManager(ServiceReference reference, HttpService httpService, PackageAdmin packageAdmin, IExtensionRegistry registry)
  {
    this.httpService = httpService;
    this.packageAdmin = packageAdmin;
    
    httpContextManager = new HttpContextManager(this, registry);
    filterManager = new FilterManager(this, reference, registry);
    servletManager = new ServletManager(this, reference, registry);
    resourceManager = new ResourceManager(this, reference, registry);
  }
  
  public void start()
  {
    httpContextManager.start();
    filterManager.start();
    servletManager.start();
    resourceManager.start();
  }
  
  public void stop()
  {
    resourceM
1 2

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