wms-winstone-1.0.5

ove(key);
    }
    out.writeInt(copy.size());
    for (Iterator<String> i = copy.keySet().iterator(); i.hasNext();)
    {
      String key = (String)i.next();
      out.writeUTF(key);
      out.writeObject(copy.get(key));
    }
  }
  
  private void readObject(ObjectInputStream in)
    throws IOException, ClassNotFoundException
  {
    sessionId = in.readUTF();
    createTime = in.readLong();
    lastAccessedTime = in.readLong();
    maxInactivePeriod = in.readInt();
    isNew = in.readBoolean();
    distributable = in.readBoolean();
    
    sessionData = new Hashtable();
    requestsUsingMe = Collections.synchronizedSet(new HashSet());
    int entryCount = in.readInt();
    for (int n = 0; n < entryCount; n++)
    {
      String key = in.readUTF();
      Object variable = in.readObject();
      sessionData.put(key, variable);
    }
    sessionMonitor = Boolean.TRUE;
  }
  
  @Deprecated
  public Object getValue(String name)
  {
    return getAttribute(name);
  }
  
  @Deprecated
  public void putValue(String name, Object value)
  {
    setAttribute(name, value);
  }
  
  @Deprecated
  public void removeValue(String name)
  {
    removeAttribute(name);
  }
  
  @Deprecated
  public String[] getValueNames()
  {
    return (String[])sessionData.keySet().toArray(new String[0]);
  }
  
  @Deprecated
  public HttpSessionContext getSessionContext()
  {
    return null;
  }
  
  public int hashCode()
  {
    int prime = 31;
    int result = 1;
    result = 31 * result + (sessionId == null ? 0 : sessionId.hashCode());
    return result;
  }
  
  public boolean equals(Object obj)
  {
    if (this == obj) {
      return Boolean.TRUE.booleanValue();
    }
    if (obj == null) {
      return Boolean.FALSE.booleanValue();
    }
    if (getClass() != obj.getClass()) {
      return Boolean.FALSE.booleanValue();
    }
    WinstoneSession other = (WinstoneSession)obj;
    if (sessionId == null)
    {
      if (sessionId != null) {
        return Boolean.FALSE.booleanValue();
      }
    }
    else if (!sessionId.equals(sessionId)) {
      return Boolean.FALSE.booleanValue();
    }
    return Boolean.TRUE.booleanValue();
  }
  
  public String toString()
  {
    return "WinstoneSession [sessionId=" + sessionId + "]";
  }
}

/* Location:
 * Qualified Name:     net.winstone.core.WinstoneSession
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package net.winstone.filters.gzip;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import javax.servlet.ServletOutputStream;

public class ByteArrayServletOutputStream
  extends ServletOutputStream
{
  private final ByteArrayOutputStream bodyStream;
  
  public ByteArrayServletOutputStream()
  {
    bodyStream = new ByteArrayOutputStream();
  }
  
  public byte[] getContent()
  {
    return bodyStream.toByteArray();
  }
  
  public void write(int b)
    throws IOException
  {
    bodyStream.write(b);
  }
  
  public void flush()
    throws IOException
  {
    bodyStream.flush();
  }
}

/* Location:
 * Qualified Name:     net.winstone.filters.gzip.ByteArrayServletOutputStream
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package net.winstone.filters.gzip;

import java.io.IOException;
import java.util.Enumeration;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletResponse;
import net.winstone.core.WinstoneRequest;

public class GzipFilter
  implements Filter
{
  private static final String ACCEPT_ENCODING = "Accept-Encoding";
  private ServletContext context;
  
  public void init(FilterConfig config)
    throws ServletException
  {
    context = config.getServletContext();
  }
  
  public void destroy()
  {
    context = null;
  }
  
  public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
    throws IOException, ServletException
  {
    Enumeration<String> headers = ((WinstoneRequest)request).getHeaders("Accept-Encoding");
    boolean acceptsGzipEncoding = Boolean.FALSE.booleanValue();
    while ((headers.hasMoreElements()) && (!acceptsGzipEncoding)) {
      acceptsGzipEncoding = ((String)headers.nextElement()).indexOf("gzip") != -1;
    }
    if (acceptsGzipEncoding)
    {
      GzipResponseWrapper encodedResponse = new GzipResponseWrapper((HttpServletResponse)response, context);
      chain.doFilter(request, encodedResponse);
      encodedResponse.close();
    }
    else
    {
      chain.doFilter(request, response);
    }
  }
}

/* Location:
 * Qualified Name:     net.winstone.filters.gzip.GzipFilter
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package net.winstone.filters.gzip;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.zip.GZIPOutputStream;
import javax.servlet.ServletContext;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServletResponseWrapper;

public class GzipResponseWrapper
  extends HttpServletResponseWrapper
{
  private ByteArrayServletOutputStream bufferStream;
  private PrintWriter bufferWriter;
  private final ServletContext context;
  
  public GzipResponseWrapper(HttpServletResponse response, ServletContext context)
  {
    super(response);
    this.context = context;
    setHeader("Content-Encoding", "gzip");
  }
  
  public void close()
    throws IOException
  {
    if (bufferWriter != null) {
      bufferWriter.flush();
    }
    if (bufferStream != null)
    {
      byte[] content = bufferStream.getContent();
      long startTime = System.currentTimeMillis();
      
      int initialContentLength = content.length;
      ByteArrayOutputStream buffer = new ByteArrayOutputStream();
      GZIPOutputStream gzip = new GZIPOutputStream(buffer);
      gzip.write(content);
      gzip.close();
      content = buffer.toByteArray();
      buffer.close();
      
      context.log("Gzipped " + initialContentLength + " bytes of " + "response content to " + content.length + " bytes in " + (System.currentTimeMillis() - startTime) + "ms");
      
      super.setContentLength(content.length);
      ServletOutputStream out = null;
      try
      {
        out = super.getOutputStream();
      }
      catch (IllegalStateException err)
      {
        throw new IOException("Can't use a gzip response wrapper on included files");
      }
      out.write(content);
      out.flush();
    }
  }
  
  public void setContentLength(int length) {}
  
  public ServletOutputStream getOutputStream()
    throws IOException
  {
    if (bufferStream != null) {
      return bufferStream;
    }
    bufferStream = new ByteArrayServletOutputStream();
    return bufferStream;
  }
  
  public PrintWriter getWriter()
    throws IOException
  {
    if (bufferWriter != null) {
      return bufferWriter;
    }
    if (bufferStream == null) {
      bufferStream = new ByteArrayServletOutputStream();
    }
    bufferWriter = new PrintWriter(new OutputStreamWriter(bufferStream, getCharacterEncoding()), Boolean.TRUE.booleanValue());
    return bufferWriter;
  }
}

/* Location:
 * Qualified Name:     net.winstone.filters.gzip.GzipResponseWrapper
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package net.winstone.filters.multipart;

import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletResponse;

public class MultipartRequestFilter
  implements Filter
{
  private int maxContentLength = -1;
  private String tooBigPage;
  private ServletContext context;
  
  public void init(FilterConfig config)
    throws ServletException
  {
    tooBigPage = config.getInitParameter("tooBigPage");
    String pmaxContentLength = config.getInitParameter("maxContentLength");
    if (pmaxContentLength == null) {
      pmaxContentLength = "-1";
    }
    maxContentLength = Integer.parseInt(pmaxContentLength);
    context = config.getServletContext();
  }
  
  public void destroy()
  {
    context = null;
    maxContentLength = -1;
    tooBigPage = null;
  }
  
  public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
    throws IOException, ServletException
  {
    String contentType = request.getContentType();
    if ((contentType != null) && (contentType.startsWith("multipart/form-data")))
    {
      if (maxContentLength >= 0)
      {
        int contentLength = request.getContentLength();
        if ((contentLength != -1) && (contentLength > maxContentLength))
        {
          if (tooBigPage == null)
          {
            ((HttpServletResponse)response).sendError(500, "Upload size (" + contentLength + " bytes) was larger " + "than the maxContentLength (" + maxContentLength + " bytes)");
          }
          else
          {
            RequestDispatcher rdTooBig = context.getRequestDispatcher(tooBigPage);
            if (rdTooBig == null) {
              ((HttpServletResponse)response).sendError(500, "Upload size (" + contentLength + " bytes) was larger " + "than the maxContentLength (" + maxContentLength + " bytes) - page " + tooBigPage + " not found");
            } else {
              rdTooBig.forward(request, response);
            }
          }
        }
        else {
          chain.doFilter(new MultipartRequestWrapper(request), response);
        }
      }
      else
      {
        chain.doFilter(new MultipartRequestWrapper(request), response);
      }
    }
    else {
      chain.doFilter(request, response);
    }
  }
}

/* Location:
 * Qualified Name:     net.winstone.filters.multipart.MultipartRequestFilter
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package net.winstone.filters.multipart;

class MultipartRequestWrapper$1 {}

/* Location:
 * Qualified Name:     net.winstone.filters.multipart.MultipartRequestWrapper.1
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package net.winstone.filters.multipart;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import javax.activation.DataSource;

class MultipartRequestWrapper$MultipartRequestWrapperDataSource
  implements DataSource
{
  private final byte[] mimeByteArray;
  private final String contentType;
  
  private MultipartRequestWrapper$MultipartRequestWrapperDataSource(MultipartRequestWrapper paramMultipartRequestWrapper, String contentType, byte[] mimeByteArray)
  {
    this.mimeByteArray = mimeByteArray;
    this.contentType = contentType;
  }
  
  public String getName()
  {
    return "MultipartHandler";
  }
  
  public String getContentType()
  {
    return contentType;
  }
  
  public InputStream getInputStream()
    throws IOException
  {
    return new ByteArrayInputStream(mimeByteArray);
  }
  
  public OutputStream getOutputStream()
    throws IOException
  {
    throw new IOException("This is a read-only datasource.");
  }
}

/* Location:
 * Qualified Name:     net.winstone.filters.multipart.MultipartRequestWrapper.MultipartRequestWrapperDataSource
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package net.winstone.filters.multipart;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import javax.activation.DataSource;
import javax.mail.MessagingException;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMultipart;
import javax.mail.internet.MimeUtility;
import javax.servlet.ServletInputStream;
import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;

public class MultipartRequestWrapper
  extends HttpServletRequestWrapper
{
  public static final String MPH_ATTRIBUTE = "MultipartRequestWrapper.reference";
  private Map<String, String[]> stringParameters;
  private Map<String, File> tempFileNames;
  private Map<String, String> mimeTypes;
  private Map<String, String> uploadFileNames;
  
  public MultipartRequestWrapper(ServletRequest request)
    throws IOException
  {
    super((HttpServletRequest)request);
    String contentType = request.getContentType();
    if (!contentType.toLowerCase().startsWith("multipart/form-data")) {
      throw new IOException("The MIME Content-Type of the Request must be \"multipart/form-data\", not \"" + contentType + '"' + ".");
    }
    if (request.getAttribute("MultipartRequestWrapper.reference") != null)
    {
      MultipartRequestWrapper oldMPH = (MultipartRequestWrapper)request.getAttribute("MultipartRequestWrapper.reference");
      
      stringParameters = stringParameters;
      mimeTypes = mimeTypes;
      tempFileNames = tempFileNames;
      uploadFileNames = uploadFileNames;
      
      return;
    }
    try
    {
      ByteArrayOutputStream byteArray = new ByteArrayOutputStream();
      InputStream inputServlet = request.getInputStream();
      byte[] buffer = new byte['?'];
      int readBytes = inputServlet.read(buffer);
      while (readBytes != -1)
      {
        byteArray.write(buffer, 0, readBytes);
        readBytes = inputServlet.read(buffer);
      }
      inputServlet.close();
      MimeMultipart parts = new MimeMultipart(new MultipartRequestWrapperDataSource(contentType, byteArray.toByteArray(), null));
      byteArray.close();
      
      Map<String, String[]> parameters = new HashMap();
      Map<String, String> mimes = new HashMap();
      Map<String, File> fileNames = new HashMap();
      Map<String, String> uploadNames = new HashMap();
      String encoding = request.getCharacterEncoding();
      if (encoding == null) {
        encoding = "8859_1";
      }
      for (int loopCount = 0; loopCount < parts.getCount(); loopCount++)
      {
        MimeBodyPart current = (MimeBodyPart)parts.getBodyPart(loopCount);
        String headers = current.getHeader("Content-Disposition", "; ");
        if (headers.indexOf(" name=\"") == -1) {
          throw new MessagingException("No name header found in Content-Disposition field.");
        }
        String namePart = headers.substring(headers.indexOf(" name=\"") + 7);
        namePart = namePart.substring(0, namePart.indexOf('"'));
        String nameField = MimeUtility.decodeText(namePart);
        
        InputStream inRaw = current.getInputStream();
        if (headers.indexOf(" filename=\"") != -1)
        {
          String fileName = headers.substring(headers.indexOf(" filename=\"") + 11);
          fileName = fileName.substring(0, fileName.indexOf('"'));
          if (fileName.lastIndexOf('/') != -1) {
            fileName = fileName.substring(fileName.lastIndexOf('/') + 1);
          }
          if (fileName.lastIndexOf('\\') != -1) {
            fileName = fileName.substring(fileName.lastIndexOf('\\') + 1);
          }
          uploadNames.put(nameField, fileName);
          if (fileNames.containsKey(nameField)) {
            throw new IOException("Multiple parameters named " + nameField);
          }
          if (current.getContentType() == null) {
            mimes.put(nameField, "text/plain");
          } else {
            mimes.put(nameField, current.getContentType());
          }
          File tempFile = File.createTempFile("mph", ".tmp");
          OutputStream outStream = new FileOutputStream(tempFile, Boolean.TRUE.booleanValue());
          while ((readBytes = inRaw.read(buffer)) != -1) {
            outStream.write(buffer, 0, readBytes);
          }
          inRaw.close();
          outStream.close();
          fileNames.put(nameField, tempFile.getAbsoluteFile());
        }
        else
        {
          byte[] stash = new byte[inRaw.available()];
          inRaw.read(stash);
          inRaw.close();
          
          Object oldParam = parameters.get(nameField);
          if (oldParam == null)
          {
            parameters.put(nameField, new String[] { new String(stash, encoding) });
          }
          else
          {
            String[] oldParams = (String[])oldParam;
            String[] newParams = new String[oldParams.length + 1];
            System.arraycopy(oldParams, 0, newParams, 0, oldParams.length);
            newParams[oldParams.length] = new String(stash, encoding);
            parameters.put(nameField, newParams);
          }
        }
      }
      parts = null;
      stringParameters = Collections.unmodifiableMap(parameters);
      mimeTypes = Collections.unmodifiableMap(mimes);
      tempFileNames = Collections.unmodifiableMap(fileNames);
      uploadFileNames = Collections.unmodifiableMap(uploadNames);
      
      request.setAttribute("MultipartRequestWrapper.reference", this);
    }
    catch (MessagingException errMime)
    {
      throw new IOException(errMime.toString());
    }
  }
  
  public String getParameter(String name)
  {
    String[] parameterValues = getParameterValues(name);
    if ((parameterValues == null) || (parameterValues.length == 0)) {
      return null;
    }
    return parameterValues[0];
  }
  
  public Map<String, String[]> getParameterMap()
  {
    Map<String, String[]> paramMap = new HashMap();
    for (Enumeration<String> names = getParameterNames(); names.hasMoreElements();)
    {
      String name = (String)names.nextElement();
      paramMap.put(name, getParameterValues(name));
    }
    return Collections.unmodifiableMap(paramMap);
  }
  
  public Enumeration<String> getParameterNames()
  {
    Set<String> names = new HashSet(stringParameters.keySet());
    names.addAll(tempFileNames.keySet());
    Enumeration<String> parent = super.getParameterNames();
    names.addAll(Collections.list(parent));
    return Collections.enumeration(names);
  }
  
  public ServletInputStream getInputStream()
    throws IOException
  {
    throw new IOException("InputStream already parsed by the MultipartRequestWrapper class");
  }
  
  public String[] getParameterValues(String name)
  {
    String[] parentValue = super.getParameterValues(name);
    if (parentValue != null) {
      return parentValue;
    }
    if (name == null) {
      return null;
    }
    if ((name.endsWith(".filename")) && (isFileUploadParameter(name.substring(0, name.length() - 9)))) {
      return new String[] { getUploadFileName(name.substring(0, name.length() - 9)) };
    }
    if ((name.endsWith(".content-type")) && (isFileUploadParameter(name.substring(0, name.length() - 13)))) {
      return new String[] { getContentType(name.substring(0, name.length() - 13)) };
    }
    if (isNonFileUploadParameter(name)) {
      return (String[])stringParameters.get(name);
    }
    if (isFileUploadParameter(name)) {
      return new String[] { ((File)tempFileNames.get(name)).getAbsolutePath() };
    }
    return null;
  }
  
  public byte[] getRawParameter(String name)
    throws IOException
  {
    if (name == null) {
      return null;
    }
    File tempFile = (File)tempFileNames.get(name);
    if (tempFile == null) {
      return null;
    }
    InputStream inFile = new FileInputStream(tempFile);
    ByteArrayOutputStream byteArray = new ByteArrayOutputStream();
    byte[] buffer = new byte['?'];
    int readBytes = inFile.read(buffer);
    while (readBytes != -1)
    {
      byteArray.write(buffer, 0, readBytes);
      readBytes = inFile.read(buffer);
    }
    inFile.close();
    byte[] output = byteArray.toByteArray();
    byteArray.close();
    return output;
  }
  
  public String getContentType(String name)
  {
    return (String)mimeTypes.get(name);
  }
  
  public String getUploadFileName(String name)
  {
    return (String)uploadFileNames.get(name);
  }
  
  public boolean isFileUploadParameter(String name)
  {
    return tempFileNames.containsKey(name);
  }
  
  public boolean isNonFileUploadParameter(String name)
  {
    return stringParameters.containsKey(name);
  }
  
  public Map<String, byte[]> getRawParameterMap()
    throws IOException
  {
    Map<String, byte[]> output = new HashMap();
    for (Iterator<String> i = uploadFileNames.keySet().iterator(); i.hasNext();)
    {
      String key = (String)i.next();
      output.put(key, getRawParameter(key));
    }
    return output;
  }
  
  public Map<String, String> getContentTypeMap()
  {
    return mimeTypes;
  }
  
  public Map<String, String> getUploadFileNameMap()
  {
    return uploadFileNames;
  }
  
  private class MultipartRequestWrapperDataSource
    implements DataSource
  {
    private final byte[] mimeByteArray;
    private final String contentType;
    
    private MultipartRequestWrapperDataSource(String contentType, byte[] mimeByteArray)
    {
      this.mimeByteArray = mimeByteArray;
      this.contentType = contentType;
    }
    
    public String getName()
    {
      return "MultipartHandler";
    }
    
    public String getContentType()
    {
      return contentType;
    }
    
    public InputStream getInputStream()
      throws IOException
    {
      return new ByteArrayInputStream(mimeByteArray);
    }
    
    public OutputStream getOutputStream()
      throws IOException
    {
      throw new IOException("This is a read-only datasource.");
    }
  }
}

/* Location:
 * Qualified Name:     net.winstone.filters.multipart.MultipartRequestWrapper
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package net.winstone.loader;

import java.net.URL;
import java.util.Enumeration;
import java.util.Iterator;

class FilteringClassLoader$1
  implements Enumeration<URL>
{
  FilteringClassLoader$1(FilteringClassLoader paramFilteringClassLoader, Iterator paramIterator) {}
  
  public boolean hasMoreElements()
  {
    return val$iterator.hasNext();
  }
  
  public URL nextElement()
  {
    return (URL)val$iterator.next();
  }
}

/* Location:
 * Qualified Name:     net.winstone.loader.FilteringClassLoader.1
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package net.winstone.loader;

import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.List;

public class FilteringClassLoader
  extends ClassLoader
{
  private String[] packages;
  private String[] paths;
  private String[] urls;
  
  public FilteringClassLoader(ClassLoader parent, String[] packages)
  {
    super(parent);
    if (packages == null) {
      throw new IllegalArgumentException("Null packages");
    }
    this.packages = packages;
    
    paths = new String[packages.length];
    for (int i = 0; i < packages.length; i++) {
      paths[i] = packages[i].replace('.', '/');
    }
    try
    {
      Enumeration<URL> enumeration = super.getResources("");
      List<URL> rootURLs = new ArrayList();
      while (enumeration.hasMoreElements()) {
        rootURLs.add(enumeration.nextElement());
      }
      urls = new String[paths.length * rootURLs.size()];
      int i = 0;
      String path;
      for (path : paths) {
        for (URL rootURL : rootURLs) {
          urls[(i++)] = new URL(rootURL, path).toString();
        }
      }
    }
    catch (Exception e)
    {
      throw new RuntimeException("Error determining classloader urls", e);
    }
  }
  
  protected synchronized Class<?> loadClass(String name, boolean resolve)
    throws ClassNotFoundException
  {
    for (String pkg : packages) {
      if (name.startsWith(pkg)) {
        throw new ClassNotFoundException("Class not found (filtered): " + name);
      }
    }
    return super.loadClass(name, resolve);
  }
  
  public URL getResource(String name)
  {
    for (String path : paths) {
      if (name.startsWith(path)) {
        return null;
      }
    }
    return super.getResource(name);
  }
  
  public Enumeration<URL> getResources(String name)
    throws IOException
  {
    Enumeration<URL> unfiltered = super.getResources(name);
    List<URL> filtered = new ArrayList();
    while (unfiltered.hasMoreElements())
    {
      URL next = (URL)unfiltered.nextElement();
      boolean ignore = false;
      for (String url : urls) {
        if (next.toString().startsWith(url)) {
          ignore = true;
        }
      }
      if (!ignore) {
        filtered.add(next);
      }
    }
    final Iterator<URL> iterator = filtered.iterator();
    new Enumeration()
    {
      public boolean hasMoreElements()
      {
        return iterator.hasNext();
      }
      
      public URL nextElement()
      {
        return (URL)iterator.next();
      }
    };
  }
}

/* Location:
 * Qualified Name:     net.winstone.loader.FilteringClassLoader
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package net.winstone.loader;

import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.Date;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import net.winstone.core.WebAppConfiguration;
import net.winstone.util.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ReloadingClassLoader
  extends WebappClassLoader
  implements ServletContextListener, Runnable
{
  protected Logger logger = LoggerFactory.getLogger(getClass());
  private static final int RELOAD_SEARCH_SLEEP = 10;
  private boolean interrupted;
  private WebAppConfiguration webAppConfig;
  private final Set<String> loadedClasses;
  private File[] classPaths;
  private int classPathsLength;
  
  public ReloadingClassLoader(URL[] urls, ClassLoader parent)
  {
    super(urls, parent);
    loadedClasses = new HashSet();
    if (urls != null)
    {
      classPaths = new File[urls.length];
      for (int n = 0; n < urls.length; n++) {
        classPaths[(classPathsLength++)] = new File(urls[n].getFile());
      }
    }
  }
  
  protected void addURL(URL url)
  {
    super.addURL(url);
    synchronized (loadedClasses)
    {
      if (classPaths == null)
      {
        classPaths = new File[10];
        classPathsLength = 0;
      }
      else if (classPathsLength == classPaths.length - 1)
      {
        File[] temp = classPaths;
        classPaths = new File[(int)(classPathsLength * 1.75D)];
        System.arraycopy(temp, 0, classPaths, 0, classPathsLength);
      }
      classPaths[(classPathsLength++)] = new File(url.getFile());
    }
  }
  
  public void contextInitialized(ServletContextEvent sce)
  {
    webAppConfig = ((WebAppConfiguration)sce.getServletContext());
    interrupted = Boolean.FALSE.booleanValue();
    synchronized (this)
    {
      loadedClasses.clear();
    }
    Thread thread = new Thread(this, "WinstoneClassLoader Reloading Monitor Thread");
    thread.setDaemon(Boolean.TRUE.booleanValue());
    thread.setPriority(1);
    thread.start();
  }
  
  public void contextDestroyed(ServletContextEvent sce)
  {
    interrupted = Boolean.TRUE.booleanValue();
    webAppConfig = null;
    synchronized (this)
    {
      loadedClasses.clear();
    }
  }
  
  public void run()
  {
    logger.info("WinstoneClassLoader reloading monitor thread started");
    
    Map<String, Long> classDateTable = new HashMap();
    Map<String, File> classLocationTable = new HashMap();
    Set<String> lostClasses = new HashSet();
    while (!interrupted) {
      try
      {
        String[] loadedClassesCopy = null;
        synchronized (this)
        {
          loadedClassesCopy = (String[])loadedClasses.toArray(new String[0]);
        }
        for (int n = 0; (n < loadedClassesCopy.length) && (!interrupted); n++)
        {
          Thread.sleep(10L);
          String className = transformToFileFormat(loadedClassesCopy[n]);
          File location = (File)classLocationTable.get(className);
          Long classDate = null;
          if ((location == null) || (!location.exists())) {
            for (int j = 0; (j < classPaths.length) && (classDate == null); j++)
            {
              File path = classPaths[j];
              if (path.exists()) {
                if (path.isDirectory())
                {
                  File classLocation = new File(path, className);
                  if (classLocation.exists())
                  {
                    classDate = new Long(classLocation.lastModified());
                    classLocationTable.put(className, classLocation);
                  }
                }
                else if (path.isFile())
                {
                  classDate = searchJarPath(className, path);
                  if (classDate != null) {
                    classLocationTable.put(className, path);
                  }
                }
              }
            }
          } else if (location.exists()) {
            classDate = new Long(location.lastModified());
          }
          if (classDate == null)
          {
            if (!lostClasses.contains(className))
            {
              lostClasses.add(className);
              logger.debug("WARNING: Maintenance thread can't find class {} - Lost ? Ignoring", className);
            }
          }
          else
          {
            if ((classDate != null) && (lostClasses.contains(className))) {
              lostClasses.remove(className);
            }
            Long oldClassDate = (Long)classDateTable.get(className);
            if (oldClassDate == null)
            {
              classDateTable.put(className, classDate);
            }
            else if (oldClassDate.compareTo(classDate) != 0)
            {
              logger.info("Class {} changed at {} (old date {}) - reloading", new Object[] { className, new Date(classDate.longValue()).toString(), new Date(oldClassDate.longValue()).toString() });
              webAppConfig.resetClassLoader();
            }
          }
        }
      }
      catch (Throwable err)
      {
        logger.error("Error in WinstoneClassLoader reloading monitor thread", err);
      }
    }
    logger.info("WinstoneClassLoader reloading monitor thread finished");
  }
  
  protected Class<?> findClass(String name)
    throws ClassNotFoundException
  {
    synchronized (this)
    {
      loadedClasses.add("Class:" + name);
    }
    return super.findClass(name);
  }
  
  public URL findResource(String name)
  {
    synchronized (this)
    {
      loadedClasses.add(name);
    }
    return super.findResource(name);
  }
  
  private Long searchJarPath(String classResourceName, File path)
    throws IOException, InterruptedException
  {
    JarFile jar = new JarFile(path);
    for (Enumeration<JarEntry> e = jar.entries(); (e.hasMoreElements()) && (!interrupted);)
    {
      JarEntry entry = (JarEntry)e.nextElement();
      if (entry.getName().equals(classResourceName)) {
        return new Long(path.lastModified());
      }
    }
    return null;
  }
  
  private static String transformToFileFormat(String name)
  {
    if (!name.startsWith("Class:")) {
      return name;
    }
    return StringUtils.replace(name.substring(6), ".", "/") + ".class";
  }
}

/* Location:
 * Qualified Name:     net.winstone.loader.ReloadingClassLoader
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package net.winstone.loader;

import java.io.InputStream;
import java.net.URL;
import java.net.URLClassLoader;
import java.net.URLStreamHandlerFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class WebappClassLoader
  extends URLClassLoader
{
  private final Logger logger = LoggerFactory.getLogger(getClass());
  protected ClassLoader system = ClassLoader.getSystemClassLoader();
  
  public WebappClassLoader(URL[] urls)
  {
    super(urls);
  }
  
  public WebappClassLoader(URL[] urls, ClassLoader parent)
  {
    super(urls, parent);
  }
  
  public WebappClassLoader(URL[] urls, ClassLoader parent, URLStreamHandlerFactory factory)
  {
    super(urls, parent, factory);
  }
  
  protected synchronized Class<?> loadClass(String name, boolean resolve)
    throws ClassNotFoundException
  {
    Class<?> c = findLoadedClass(name);
    if (c == null) {
      try
      {
        c = system.loadClass(name);
        if (c != null) {
          logger.debug("Webapp classloader deferred to system classloader for loading {}", name);
        }
      }
      catch (ClassNotFoundException e)
      {
        c = null;
      }
    }
    if (c == null) {
      try
      {
        c = findClass(name);
        if (c != null) {
          logger.debug("Webapp classloader found class locally when loading {}", name);
        }
      }
      catch (ClassNotFoundException e)
      {
        c = null;
      }
    }
    if (c == null)
    {
      ClassLoader parent = getParent();
      if (parent != null)
      {
        c = parent.loadClass(name);
        if (c != null) {
          logger.debug("Webapp classloader deferred to parent for loading {}", name);
        }
      }
      else
      {
        throw new ClassNotFoundException(name);
      }
    }
    if ((resolve) && (c != null)) {
      resolveClass(c);
    }
    return c;
  }
  
  public InputStream getResourceAsStream(String name)
  {
    String pName = name;
    if ((name != null) && (name.startsWith("/"))) {
      pName = name.substring(1);
    }
    return super.getResourceAsStream(pName);
  }
}

/* Location:
 * Qualified Name:     net.winstone.loader.WebappClassLoader
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package net.winstone;

class MimeTypes$1 {}

/* Location:
 * Qualified Name:     net.winstone.MimeTypes.1
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package net.winstone;

class MimeTypes$MimeTypesLazyHolder
{
  private static MimeTypes uniqueInstance = new MimeTypes(null);
}

/* Location:
 * Qualified Name:     net.winstone.MimeTypes.MimeTypesLazyHolder
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package net.winstone;

import java.net.FileNameMap;
import java.util.Collections;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.ResourceBundle;
import net.winstone.util.MapLoader;

public class MimeTypes
  implements FileNameMap
{
  private static final transient String UNKNOWN_EXTENSION = "unknown/unknown";
  private final Map<String, String> ressource;
  
  private MimeTypes()
  {
    this(Collections.unmodifiableMap(MapLoader.load(ResourceBundle.getBundle("mime"))));
  }
  
  private MimeTypes(Map<String, String> ressource)
  {
    this.ressource = ressource;
  }
  
  public String getContentType(String extension)
  {
    String contentType = (String)ressource.get(extension.toLowerCase(Locale.ENGLISH));
    if (contentType == null) {
      contentType = "unknown/unknown";
    }
    return contentType;
  }
  
  public String getContentTypeFor(String fileName)
  {
    int dotPos = fileName.lastIndexOf('.');
    if ((dotPos != -1) && (dotPos != fileName.length() - 1))
    {
      String extension = fileName.substring(dotPos + 1).toLowerCase();
      return getContentType(extension);
    }
    return null;
  }
  
  private static class MimeTypesLazyHolder
  {
    private static MimeTypes uniqueInstance = new MimeTypes(null);
  }
  
  public static MimeTypes getInstance()
  {
    return MimeTypesLazyHolder.uniqueInstance;
  }
  
  public static MimeTypes getInstance(Map<String, String> additionalMimeType)
  {
    MimeTypes mimeTypes = getInstance();
    if ((additionalMimeType == null) || (additionalMimeType.isEmpty())) {
      return mimeTypes;
    }
    Map<String, String> customized = new HashMap(additionalMimeType.size() + ressource.size());
    customized.putAll(ressource);
    customized.putAll(additionalMimeType);
    return new MimeTypes(customized);
  }
}

/* Location:
 * Qualified Name:     net.winstone.MimeTypes
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package net.winstone.relocate;

class TreePath$1 {}

/* Location:
 * Qualified Name:     net.winstone.relocate.TreePath.1
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package net.winstone.relocate;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

final class TreePath$TreeNode
{
  Map<String, TreeNode> children;
  Object value;
  
  private TreePath$TreeNode(TreePath paramTreePath) {}
  
  public Set<String> keys()
  {
    return children == null ? Collections.EMPTY_SET : children.keySet();
  }
  
  public void put(String name, TreeNode node)
  {
    if (children == null) {
      children = new HashMap();
    }
    children.put(name, node);
  }
  
  public TreeNode get(String pc)
  {
    return children != null ? (TreeNode)children.get(pc) : null;
  }
}

/* Location:
 * Qualified Name:     net.winstone.relocate.TreePath.TreeNode
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package net.winstone.relocate;

import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;

public class TreePath
{
  private final TreeNode root;
  
  public TreePath()
  {
    root = new TreeNode(null);
  }
  
  public Set<String> keys()
  {
    Set<String> result = new HashSet();
    addSiblingNames(root, result, "");
    return result;
  }
  
  protected void addSiblingNames(TreeNode node, Set<String> result, String path)
  {
    for (String pc : node.keys())
    {
      TreeNode childNode = node.get(pc);
      pc = path + '/' + pc;
      if (value != null) {
        result.add(pc);
      }
      addSiblingNames(childNode, result, pc);
    }
  }
  
  public Set<Object> elements()
  {
    Set<Object> result = new HashSet();
    addSiblingObjects(root, result);
    return result;
  }
  
  protected void addSiblingObjects(TreeNode node, Set<Object> result)
  {
    for (String pc : node.keys())
    {
      TreeNode childNode = node.get(pc);
      if (value != null) {
        result.add(value);
      }
      addSiblingObjects(childNode, result);
    }
  }
  
  public void put(String path, Object value)
  {
    StringTokenizer st = new StringTokenizer(path, "\\/");
    TreeNode cur_node = root;
    while (st.hasMoreTokens())
    {
      String nodename = st.nextToken();
      TreeNode node = cur_node.get(nodename);
      if (node == null)
      {
        node = new TreeNode(null);
        cur_node.put(nodename, node);
      }
      cur_node = node;
    }
    value = value;
  }
  
  public Object[] remove(Object value)
  {
    return remove(root, value);
  }
  
  public Object[] remove(String path)
  {
    Object[] result = get(path);
    if (result[1] != null) {
      return remove(result[1]);
    }
    return result;
  }
  
  public Object[] remove(TreeNode node, Object value)
  {
    for (String path : node.keys())
    {
      TreeNode childNode = node.get(path);
      if (value == value)
      {
        value = null;
        return new Object[] { value, new Integer(0) };
      }
      Object[] result = remove(childNode, value);
      if (result[0] != null) {
        return result;
      }
    }
    return new Object[] { null, null };
  }
  
  public Object[] get(String path)
  {
    Object[] result = new Object[2];
    if (path == null) {
      return result;
    }
    char[] ps = path.toCharArray();
    TreeNode cur_node = root;
    int p0 = 0;int lm = 0;
    result[0] = value;
    boolean div_state = 
1 2 3 4 5 6 7 8 9 10 11 12 13 14

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-2019. Infinite Loop Ltd