org.eclipse.wst.internet.monitor.core_1.0.505.v20110419

16:49:03.216 INFO  jd.cli.Main - Decompiling org.eclipse.wst.internet.monitor.core_1.0.505.v20110419.jar
package org.eclipse.wst.internet.monitor.core.internal;

import java.io.InterruptedIOException;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.SocketTimeoutException;
import org.eclipse.wst.internet.monitor.core.internal.provisional.IMonitor;

class AcceptThread$ServerThread
  extends Thread
{
  public AcceptThread$ServerThread(AcceptThread paramAcceptThread)
  {
    super("TCP/IP Monitor");
  }
  
  public void run()
  {
    try
    {
      this$0.serverSocket = new ServerSocket(this$0.monitor.getLocalPort());
      this$0.serverSocket.setSoTimeout(2000);
      if (!Trace.FINEST) {
        break label349;
      }
      Trace.trace("/finest", "Monitoring localhost:" + this$0.monitor.getLocalPort() + " -> " + 
        this$0.monitor.getRemoteHost() + ":" + this$0.monitor.getRemotePort());
    }
    catch (Exception localException1)
    {
      if (Trace.SEVERE) {
        Trace.trace("/severe", "Could not start monitoring");
      }
      return;
    }
    try
    {
      do
      {
        Socket localSocket = this$0.serverSocket.accept();
        
        int timeout = this$0.monitor.getTimeout();
        if (timeout != 0) {
          localSocket.setSoTimeout(timeout);
        }
        try
        {
          Socket remoteSocket = new Socket();
          if (timeout != 0) {
            remoteSocket.setSoTimeout(timeout);
          }
          remoteSocket.connect(new InetSocketAddress(this$0.monitor.getRemoteHost(), this$0.monitor.getRemotePort()), timeout);
          
          String protocolId = this$0.monitor.getProtocol();
          ProtocolAdapter adapter = MonitorPlugin.getInstance().getProtocolAdapter(protocolId);
          adapter.connect(this$0.monitor, localSocket, remoteSocket);
        }
        catch (SocketTimeoutException localSocketTimeoutException)
        {
          FailedConnectionThread thread2 = new FailedConnectionThread((Monitor)this$0.monitor, localSocket, Messages.errorConnectTimeout);
          thread2.start();
        }
        catch (Exception localException2)
        {
          FailedConnectionThread thread2 = new FailedConnectionThread((Monitor)this$0.monitor, localSocket, null);
          thread2.start();
        }
      } while (this$0.alive);
    }
    catch (InterruptedIOException localInterruptedIOException) {}catch (Exception e)
    {
      if ((this$0.alive) && 
        (Trace.SEVERE)) {
        Trace.trace("/severe", "Error while monitoring", e);
      }
    }
    label349:
  }
}

/* Location:
 * Qualified Name:     org.eclipse.wst.internet.monitor.core.internal.AcceptThread.ServerThread
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.internet.monitor.core.internal;

import java.io.InterruptedIOException;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.SocketException;
import java.net.SocketTimeoutException;
import org.eclipse.wst.internet.monitor.core.internal.provisional.IMonitor;

public class AcceptThread
{
  protected IMonitor monitor;
  protected boolean alive = true;
  protected ServerSocket serverSocket;
  protected Thread thread;
  
  class ServerThread
    extends Thread
  {
    public ServerThread()
    {
      super();
    }
    
    public void run()
    {
      try
      {
        serverSocket = new ServerSocket(monitor.getLocalPort());
        serverSocket.setSoTimeout(2000);
        if (!Trace.FINEST) {
          break label349;
        }
        Trace.trace("/finest", "Monitoring localhost:" + monitor.getLocalPort() + " -> " + 
          monitor.getRemoteHost() + ":" + monitor.getRemotePort());
      }
      catch (Exception localException1)
      {
        if (Trace.SEVERE) {
          Trace.trace("/severe", "Could not start monitoring");
        }
        return;
      }
      try
      {
        do
        {
          Socket localSocket = serverSocket.accept();
          
          int timeout = monitor.getTimeout();
          if (timeout != 0) {
            localSocket.setSoTimeout(timeout);
          }
          try
          {
            Socket remoteSocket = new Socket();
            if (timeout != 0) {
              remoteSocket.setSoTimeout(timeout);
            }
            remoteSocket.connect(new InetSocketAddress(monitor.getRemoteHost(), monitor.getRemotePort()), timeout);
            
            String protocolId = monitor.getProtocol();
            ProtocolAdapter adapter = MonitorPlugin.getInstance().getProtocolAdapter(protocolId);
            adapter.connect(monitor, localSocket, remoteSocket);
          }
          catch (SocketTimeoutException localSocketTimeoutException)
          {
            FailedConnectionThread thread2 = new FailedConnectionThread((Monitor)monitor, localSocket, Messages.errorConnectTimeout);
            thread2.start();
          }
          catch (Exception localException2)
          {
            FailedConnectionThread thread2 = new FailedConnectionThread((Monitor)monitor, localSocket, null);
            thread2.start();
          }
        } while (alive);
      }
      catch (InterruptedIOException localInterruptedIOException) {}catch (Exception e)
      {
        if ((alive) && 
          (Trace.SEVERE)) {
          Trace.trace("/severe", "Error while monitoring", e);
        }
      }
      label349:
    }
  }
  
  public AcceptThread(IMonitor monitor)
  {
    this.monitor = monitor;
  }
  
  public void startServer()
  {
    if (thread != null) {
      return;
    }
    thread = new ServerThread();
    thread.setDaemon(true);
    thread.setPriority(6);
    thread.start();
    
    Thread.yield();
    
    int i = 0;
    while ((serverSocket == null) && (i < 10))
    {
      try
      {
        Thread.sleep(200L);
      }
      catch (Exception localException) {}
      i++;
    }
  }
  
  public boolean isRunning()
  {
    return thread != null;
  }
  
  public void stopServer()
  {
    try
    {
      alive = false;
      thread = null;
      
      String protocolId = monitor.getProtocol();
      ProtocolAdapter adapter = MonitorPlugin.getInstance().getProtocolAdapter(protocolId);
      adapter.disconnect(monitor);
      if (serverSocket != null) {
        serverSocket.close();
      }
    }
    catch (Exception e)
    {
      if (Trace.SEVERE) {
        Trace.trace("/severe", "Error stopping server", e);
      }
    }
  }
  
  public static boolean isPortInUse(int port)
  {
    ServerSocket s = null;
    try
    {
      s = new ServerSocket(port);
    }
    catch (SocketException localSocketException)
    {
      return true;
    }
    catch (Exception localException2)
    {
      return true;
    }
    finally
    {
      if (s != null) {
        try
        {
          s.close();
        }
        catch (Exception localException4) {}
      }
    }
    if (s != null) {
      try
      {
        s.close();
      }
      catch (Exception localException5) {}
    }
    return false;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.wst.internet.monitor.core.internal.AcceptThread
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.internet.monitor.core.internal;

import java.io.OutputStream;
import java.net.Socket;

public class Connection
{
  protected Socket in;
  protected Socket out;
  
  public Connection(Socket in, Socket out)
  {
    this.in = in;
    this.out = out;
  }
  
  public void close()
  {
    if (Trace.FINEST) {
      Trace.trace("/finest", "Closing connection");
    }
    try
    {
      in.getOutputStream().flush();
      in.shutdownInput();
      in.shutdownOutput();
      
      out.getOutputStream().flush();
      out.shutdownInput();
      out.shutdownOutput();
      if (Trace.FINEST) {
        Trace.trace("/finest", "Connection closed");
      }
    }
    catch (Exception ex)
    {
      if (Trace.WARNING) {
        Trace.trace("/warning", "Error closing connection " + this, ex);
      }
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.wst.internet.monitor.core.internal.Connection
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.internet.monitor.core.internal;

import java.io.IOException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.wst.internet.monitor.core.internal.provisional.ContentFilterDelegate;
import org.eclipse.wst.internet.monitor.core.internal.provisional.Request;

public class ContentFilter
  implements IContentFilter
{
  protected IConfigurationElement element;
  protected ContentFilterDelegate delegate;
  
  protected ContentFilter(IConfigurationElement element)
  {
    this.element = element;
  }
  
  public String getId()
  {
    return element.getAttribute("id");
  }
  
  public int getOrder()
  {
    try
    {
      return Integer.parseInt(element.getAttribute("order"));
    }
    catch (Exception localException) {}
    return 0;
  }
  
  public String getName()
  {
    return element.getAttribute("name");
  }
  
  public byte[] filter(Request request, boolean isRequest, byte[] content)
    throws IOException
  {
    if (delegate == null) {
      try
      {
        delegate = ((ContentFilterDelegate)element.createExecutableExtension("class"));
      }
      catch (Exception e)
      {
        if (Trace.SEVERE) {
          Trace.trace("/severe", "Could not create content filter delegate: " + getId(), e);
        }
        return new byte[0];
      }
    }
    return delegate.filter(request, isRequest, content);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.wst.internet.monitor.core.internal.ContentFilter
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.internet.monitor.core.internal;

import java.net.Socket;

public class FailedConnectionThread
  extends Thread
{
  private static final int BUFFER = 2048;
  protected Monitor monitor;
  protected Socket socket;
  protected String error;
  
  public FailedConnectionThread(Monitor monitor, Socket socket, String error)
  {
    this.monitor = monitor;
    this.socket = socket;
    this.error = error;
  }
  
  /* Error */
  public void run()
  {
    // Byte code:
    //   0: new 57	org/eclipse/wst/internet/monitor/core/internal/provisional/Request
    //   3: dup
    //   4: aload_0
    //   5: getfield 90	org/eclipse/wst/internet/monitor/core/internal/FailedConnectionThread:monitor	Lorg/eclipse/wst/internet/monitor/core/internal/Monitor;
    //   8: ldc 1
    //   10: aload_0
    //   11: getfield 90	org/eclipse/wst/internet/monitor/core/internal/FailedConnectionThread:monitor	Lorg/eclipse/wst/internet/monitor/core/internal/Monitor;
    //   14: invokevirtual 101	org/eclipse/wst/internet/monitor/core/internal/Monitor:getLocalPort	()I
    //   17: aload_0
    //   18: getfield 90	org/eclipse/wst/internet/monitor/core/internal/FailedConnectionThread:monitor	Lorg/eclipse/wst/internet/monitor/core/internal/Monitor;
    //   21: invokevirtual 103	org/eclipse/wst/internet/monitor/core/internal/Monitor:getRemoteHost	()Ljava/lang/String;
    //   24: aload_0
    //   25: getfield 90	org/eclipse/wst/internet/monitor/core/internal/FailedConnectionThread:monitor	Lorg/eclipse/wst/internet/monitor/core/internal/Monitor;
    //   28: invokevirtual 102	org/eclipse/wst/internet/monitor/core/internal/Monitor:getRemotePort	()I
    //   31: invokespecial 106	org/eclipse/wst/internet/monitor/core/internal/provisional/Request:<init>	(Lorg/eclipse/wst/internet/monitor/core/internal/Monitor;Ljava/lang/String;ILjava/lang/String;I)V
    //   34: astore_1
    //   35: aload_0
    //   36: getfield 88	org/eclipse/wst/internet/monitor/core/internal/FailedConnectionThread:error	Ljava/lang/String;
    //   39: astore_2
    //   40: aload_2
    //   41: ifnonnull +7 -> 48
    //   44: getstatic 91	org/eclipse/wst/internet/monitor/core/internal/Messages:errorConnectToServer	Ljava/lang/String;
    //   47: astore_2
    //   48: aload_1
    //   49: aload_2
    //   50: invokevirtual 94	java/lang/String:getBytes	()[B
    //   53: invokevirtual 105	org/eclipse/wst/internet/monitor/core/internal/provisional/Request:addToResponse	([B)V
    //   56: aload_0
    //   57: getfield 89	org/eclipse/wst/internet/monitor/core/internal/FailedConnectionThread:socket	Ljava/net/Socket;
    //   60: invokevirtual 100	java/net/Socket:getInputStream	()Ljava/io/InputStream;
    //   63: astore_3
    //   64: sipush 2048
    //   67: newarray <illegal type>
    //   69: astore 4
    //   71: goto +34 -> 105
    //   74: aload_3
    //   75: aload 4
    //   77: invokevirtual 93	java/io/InputStream:read	([B)I
    //   80: istore 5
    //   82: iload 5
    //   84: newarray <illegal type>
    //   86: astore 6
    //   88: aload 4
    //   90: iconst_0
    //   91: aload 6
    //   93: iconst_0
    //   94: iload 5
    //   96: invokestatic 95	java/lang/System:arraycopy	(Ljava/lang/Object;ILjava/lang/Object;II)V
    //   99: aload_1
    //   100: aload 6
    //   102: invokevirtual 104	org/eclipse/wst/internet/monitor/core/internal/provisional/Request:addToRequest	([B)V
    //   105: aload_3
    //   106: invokevirtual 92	java/io/InputStream:available	()I
    //   109: ifgt -35 -> 74
    //   112: goto +62 -> 174
    //   115: pop
    //   116: aload_0
    //   117: getfield 89	org/eclipse/wst/internet/monitor/core/internal/FailedConnectionThread:socket	Ljava/net/Socket;
    //   120: invokevirtual 98	java/net/Socket:shutdownInput	()V
    //   123: aload_0
    //   124: getfield 89	org/eclipse/wst/internet/monitor/core/internal/FailedConnectionThread:socket	Ljava/net/Socket;
    //   127: invokevirtual 99	java/net/Socket:shutdownOutput	()V
    //   130: aload_0
    //   131: getfield 89	org/eclipse/wst/internet/monitor/core/internal/FailedConnectionThread:socket	Ljava/net/Socket;
    //   134: invokevirtual 97	java/net/Socket:close	()V
    //   137: goto +62 -> 199
    //   140: pop
    //   141: goto +58 -> 199
    //   144: astore 7
    //   146: aload_0
    //   147: getfield 89	org/eclipse/wst/internet/monitor/core/internal/FailedConnectionThread:socket	Ljava/net/Socket;
    //   150: invokevirtual 98	java/net/Socket:shutdownInput	()V
    //   153: aload_0
    //   154: getfield 89	org/eclipse/wst/internet/monitor/core/internal/FailedConnectionThread:socket	Ljava/net/Socket;
    //   157: invokevirtual 99	java/net/Socket:shutdownOutput	()V
    //   160: aload_0
    //   161: getfield 89	org/eclipse/wst/internet/monitor/core/internal/FailedConnectionThread:socket	Ljava/net/Socket;
    //   164: invokevirtual 97	java/net/Socket:close	()V
    //   167: goto +4 -> 171
    //   170: pop
    //   171: aload 7
    //   173: athrow
    //   174: aload_0
    //   175: getfield 89	org/eclipse/wst/internet/monitor/core/internal/FailedConnectionThread:socket	Ljava/net/Socket;
    //   178: invokevirtual 98	java/net/Socket:shutdownInput	()V
    //   181: aload_0
    //   182: getfield 89	org/eclipse/wst/internet/monitor/core/internal/FailedConnectionThread:socket	Ljava/net/Socket;
    //   185: invokevirtual 99	java/net/Socket:shutdownOutput	()V
    //   188: aload_0
    //   189: getfield 89	org/eclipse/wst/internet/monitor/core/internal/FailedConnectionThread:socket	Ljava/net/Socket;
    //   192: invokevirtual 97	java/net/Socket:close	()V
    //   195: goto +4 -> 199
    //   198: pop
    //   199: return
    // Line number table:
    //   Java source line #35	-> byte code offset #0
    //   Java source line #36	-> byte code offset #35
    //   Java source line #37	-> byte code offset #40
    //   Java source line #38	-> byte code offset #44
    //   Java source line #39	-> byte code offset #48
    //   Java source line #42	-> byte code offset #56
    //   Java source line #43	-> byte code offset #64
    //   Java source line #44	-> byte code offset #71
    //   Java source line #45	-> byte code offset #74
    //   Java source line #46	-> byte code offset #82
    //   Java source line #47	-> byte code offset #88
    //   Java source line #48	-> byte code offset #99
    //   Java source line #44	-> byte code offset #105
    //   Java source line #50	-> byte code offset #115
    //   Java source line #54	-> byte code offset #116
    //   Java source line #55	-> byte code offset #123
    //   Java source line #56	-> byte code offset #130
    //   Java source line #57	-> byte code offset #140
    //   Java source line #52	-> byte code offset #144
    //   Java source line #54	-> byte code offset #146
    //   Java source line #55	-> byte code offset #153
    //   Java source line #56	-> byte code offset #160
    //   Java source line #57	-> byte code offset #170
    //   Java source line #60	-> byte code offset #171
    //   Java source line #54	-> byte code offset #174
    //   Java source line #55	-> byte code offset #181
    //   Java source line #56	-> byte code offset #188
    //   Java source line #57	-> byte code offset #198
    //   Java source line #61	-> byte code offset #199
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	200	0	this	FailedConnectionThread
    //   34	66	1	request	org.eclipse.wst.internet.monitor.core.internal.provisional.Request
    //   39	11	2	err	String
    //   63	43	3	in	java.io.InputStream
    //   69	20	4	b	byte[]
    //   80	15	5	n	int
    //   86	15	6	c	byte[]
    //   144	28	7	localObject	Object
    //   115	1	8	localException1	Exception
    //   140	1	9	localException2	Exception
    //   170	1	10	localException3	Exception
    //   198	1	11	localException4	Exception
    // Exception table:
    //   from	to	target	type
    //   56	112	115	java/lang/Exception
    //   116	137	140	java/lang/Exception
    //   56	116	144	finally
    //   146	167	170	java/lang/Exception
    //   174	195	198	java/lang/Exception
  }
}

/* Location:
 * Qualified Name:     org.eclipse.wst.internet.monitor.core.internal.FailedConnectionThread
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.internet.monitor.core.internal;

import java.io.IOException;
import org.eclipse.wst.internet.monitor.core.internal.provisional.Request;

public abstract interface IContentFilter
{
  public abstract String getId();
  
  public abstract String getName();
  
  public abstract byte[] filter(Request paramRequest, boolean paramBoolean, byte[] paramArrayOfByte)
    throws IOException;
}

/* Location:
 * Qualified Name:     org.eclipse.wst.internet.monitor.core.internal.IContentFilter
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.internet.monitor.core.internal;

public abstract interface IMemento
{
  public abstract IMemento createChild(String paramString);
  
  public abstract IMemento getChild(String paramString);
  
  public abstract IMemento[] getChildren(String paramString);
  
  public abstract Integer getInteger(String paramString);
  
  public abstract String getString(String paramString);
  
  public abstract Boolean getBoolean(String paramString);
  
  public abstract void putInteger(String paramString, int paramInt);
  
  public abstract void putBoolean(String paramString, boolean paramBoolean);
  
  public abstract void putString(String paramString1, String paramString2);
}

/* Location:
 * Qualified Name:     org.eclipse.wst.internet.monitor.core.internal.IMemento
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.internet.monitor.core.internal;

public abstract interface IProtocolAdapter
{
  public static final String TCPIP_PROTOCOL_ID = "TCP/IP";
  public static final String HTTP_PROTOCOL_ID = "HTTP";
  
  public abstract String getId();
  
  public abstract String getName();
}

/* Location:
 * Qualified Name:     org.eclipse.wst.internet.monitor.core.internal.IProtocolAdapter
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.internet.monitor.core.internal;

public abstract interface IStartup
{
  public abstract void startup();
}

/* Location:
 * Qualified Name:     org.eclipse.wst.internet.monitor.core.internal.IStartup
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.internet.monitor.core.internal;

import org.eclipse.osgi.util.NLS;

public class Messages
  extends NLS
{
  public static String errorInvalidLocalPort;
  public static String errorInvalidRemotePort;
  public static String errorInvalidRemoteHost;
  public static String errorConnectToServer;
  public static String errorConnectTimeout;
  public static String monitorValid;
  public static String errorPortInUse;
  public static String errorContentSize;
  
  static
  {
    NLS.initializeMessages("org.eclipse.wst.internet.monitor.core.internal.Messages", Messages.class);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.wst.internet.monitor.core.internal.Messages
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.internet.monitor.core.internal;

import java.net.InetAddress;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.wst.internet.monitor.core.internal.provisional.IMonitor;
import org.eclipse.wst.internet.monitor.core.internal.provisional.IMonitorWorkingCopy;
import org.eclipse.wst.internet.monitor.core.internal.provisional.IRequestListener;
import org.eclipse.wst.internet.monitor.core.internal.provisional.Request;

public class Monitor
  implements IMonitor
{
  private static final String MEMENTO_ID = "id";
  private static final String MEMENTO_LOCAL_PORT = "local-port";
  private static final String MEMENTO_REMOTE_HOST = "remote-host";
  private static final String MEMENTO_REMOTE_PORT = "remote-port";
  private static final String MEMENTO_TYPE_ID = "type-id";
  private static final String MEMENTO_TIMEOUT = "timeout";
  private static final String MEMENTO_AUTO_START = "auto-start";
  private static final int ADD = 0;
  private static final int CHANGE = 1;
  protected String id;
  protected String remoteHost;
  protected int remotePort = 80;
  protected int localPort = 80;
  protected String protocolId;
  protected int timeout;
  protected boolean autoStart = false;
  protected List<IRequestListener> requestListeners = new ArrayList(2);
  
  public Monitor()
  {
    protocolId = MonitorPlugin.getInstance().getDefaultType();
  }
  
  public String getId()
  {
    return id;
  }
  
  public String getRemoteHost()
  {
    return remoteHost;
  }
  
  public int getRemotePort()
  {
    return remotePort;
  }
  
  public int getLocalPort()
  {
    return localPort;
  }
  
  public String getProtocol()
  {
    return protocolId;
  }
  
  public int getTimeout()
  {
    return timeout;
  }
  
  public boolean isAutoStart()
  {
    return autoStart;
  }
  
  public boolean isRunning()
  {
    if (isWorkingCopy()) {
      return false;
    }
    return MonitorManager.getInstance().isRunning(this);
  }
  
  public void delete()
  {
    if (isWorkingCopy()) {
      return;
    }
    MonitorManager.getInstance().removeMonitor(this);
  }
  
  public boolean isWorkingCopy()
  {
    return false;
  }
  
  public IMonitorWorkingCopy createWorkingCopy()
  {
    return new MonitorWorkingCopy(this);
  }
  
  protected void setInternal(IMonitor monitor)
  {
    id = monitor.getId();
    remoteHost = monitor.getRemoteHost();
    remotePort = monitor.getRemotePort();
    localPort = monitor.getLocalPort();
    protocolId = monitor.getProtocol();
    timeout = monitor.getTimeout();
    autoStart = monitor.isAutoStart();
  }
  
  protected void save(IMemento memento)
  {
    memento.putString("id", id);
    memento.putString("type-id", protocolId);
    memento.putInteger("local-port", localPort);
    memento.putString("remote-host", remoteHost);
    memento.putInteger("remote-port", remotePort);
    memento.putInteger("timeout", timeout);
    memento.putBoolean("auto-start", autoStart);
  }
  
  protected void load(IMemento memento)
  {
    id = memento.getString("id");
    protocolId = memento.getString("type-id");
    Integer temp = memento.getInteger("local-port");
    if (temp != null) {
      localPort = temp.intValue();
    }
    remoteHost = memento.getString("remote-host");
    temp = memento.getInteger("remote-port");
    if (temp != null) {
      remotePort = temp.intValue();
    }
    temp = memento.getInteger("timeout");
    if (temp != null) {
      timeout = temp.intValue();
    }
    Boolean temp2 = memento.getBoolean("auto-start");
    if (temp != null) {
      autoStart = temp2.booleanValue();
    }
  }
  
  public synchronized void start()
    throws CoreException
  {
    if (isRunning()) {
      return;
    }
    if ((isWorkingCopy()) || (!MonitorManager.getInstance().exists(this))) {
      throw new IllegalArgumentException();
    }
    IStatus status = validate();
    if (!status.isOK()) {
      throw new CoreException(status);
    }
    MonitorManager.getInstance().startMonitor(this);
  }
  
  public synchronized void stop()
  {
    if ((isWorkingCopy()) || (!MonitorManager.getInstance().exists(this))) {
      throw new IllegalArgumentException();
    }
    if (!isRunning()) {
      return;
    }
    MonitorManager.getInstance().stopMonitor(this);
  }
  
  public synchronized void addRequestListener(IRequestListener listener)
  {
    if (listener == null) {
      throw new IllegalArgumentException();
    }
    if (!requestListeners.contains(listener)) {
      requestListeners.add(listener);
    }
  }
  
  public synchronized void removeRequestListener(IRequestListener listener)
  {
    if (listener == null) {
      throw new IllegalArgumentException();
    }
    requestListeners.remove(listener);
  }
  
  protected void fireRequestEvent(Request rr, int type)
  {
    int size = requestListeners.size();
    IRequestListener[] rl = new IRequestListener[size];
    requestListeners.toArray(rl);
    IRequestListener[] arrayOfIRequestListener1;
    int j = (arrayOfIRequestListener1 = rl).length;
    for (int i = 0; i < j; i++)
    {
      IRequestListener listener = arrayOfIRequestListener1[i];
      if (type == 0) {
        listener.requestAdded(this, rr);
      } else if (type == 1) {
        listener.requestChanged(this, rr);
      }
    }
  }
  
  public void addRequest(Request request)
  {
    fireRequestEvent(request, 0);
  }
  
  public void requestChanged(Request request)
  {
    fireRequestEvent(request, 1);
  }
  
  public IStatus validate()
  {
    if (localPort < 0) {
      return new Status(4, "org.eclipse.wst.internet.monitor.core", 0, Messages.errorInvalidLocalPort, null);
    }
    if (remotePort < 0) {
      return new Status(4, "org.eclipse.wst.internet.monitor.core", 0, Messages.errorInvalidRemotePort, null);
    }
    if ((remoteHost == null) || (remoteHost.length() == 0) || (!isValidHostname(remoteHost))) {
      return new Status(4, "org.eclipse.wst.internet.monitor.core", 0, Messages.errorInvalidRemoteHost, null);
    }
    if ((isLocalhost(remoteHost)) && (localPort == remotePort)) {
      return new Status(4, "org.eclipse.wst.internet.monitor.core", 0, Messages.errorInvalidLocalPort, null);
    }
    return Status.OK_STATUS;
  }
  
  protected static boolean isValidHostname(String host)
  {
    if ((host == null) || (host.trim().length() < 1)) {
      return false;
    }
    int length = host.length();
    for (int i = 0; i < length; i++)
    {
      char c = host.charAt(i);
      if ((!Character.isLetterOrDigit(c)) && (c != ':') && (c != '.') && (c != '-')) {
        return false;
      }
    }
    if (host.endsWith(":")) {
      return false;
    }
    return true;
  }
  
  protected static boolean isLocalhost(String host)
  {
    if (host == null) {
      return false;
    }
    try
    {
      if (("localhost".equals(host)) || ("127.0.0.1".equals(host))) {
        return true;
      }
      InetAddress localHostaddr = InetAddress.getLocalHost();
      if (localHostaddr.getHostName().equals(host)) {
        return true;
      }
    }
    catch (Exception e)
    {
      if (Trace.WARNING) {
        Trace.trace("/warning", "Error checking for localhost", e);
      }
    }
    return false;
  }
  
  public String toString()
  {
    return 
      "Monitor [" + getId() + ", " + getProtocol() + ", " + getLocalPort() + ", " + getRemoteHost() + ", " + getRemotePort() + "]";
  }
  
  public boolean equals(Object obj)
  {
    if (!(obj instanceof Monitor)) {
      return false;
    }
    IMonitor m = (IMonitor)obj;
    if (m.isWorkingCopy())
    {
      m = ((IMonitorWorkingCopy)m).getOriginal();
      if (m == null) {
        return false;
      }
    }
    if ((id == null) && (m.getId() != null)) {
      return false;
    }
    if ((id != null) && (!id.equals(m.getId()))) {
      return false;
    }
    if (localPort != m.getLocalPort()) {
      return false;
    }
    if (remotePort != m.getRemotePort()) {
      return false;
    }
    if ((remoteHost == null) && (m.getRemoteHost() != null)) {
      return false;
    }
    if ((remoteHost != null) && (!remoteHost.equals(m.getRemoteHost()))) {
      return false;
    }
    if ((protocolId == null) && (m.getProtocol() != null)) {
      return false;
    }
    if ((protocolId != null) && (!protocolId.equals(m.getProtocol()))) {
      return false;
    }
    return true;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.wst.internet.monitor.core.internal.Monitor
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.internet.monitor.core.internal;

import org.eclipse.core.runtime.Preferences.IPropertyChangeListener;
import org.eclipse.core.runtime.Preferences.PropertyChangeEvent;

class MonitorManager$1
  implements Preferences.IPropertyChangeListener
{
  MonitorManager$1(MonitorManager paramMonitorManager) {}
  
  public void propertyChange(Preferences.PropertyChangeEvent event)
  {
    if (this$0.ignorePreferenceChanges) {
      return;
    }
    String property = event.getProperty();
    if (property.equals("monitors")) {
      this$0.loadMonitors();
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.wst.internet.monitor.core.internal.MonitorManager.1
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.internet.monitor.core.internal;

import java.io.ByteArrayInputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.Preferences;
import org.eclipse.core.runtime.Preferences.IPropertyChangeListener;
import org.eclipse.core.runtime.Preferences.PropertyChangeEvent;
import org.eclipse.core.runtime.Status;
import org.eclipse.osgi.util.NLS;
import org.eclipse.wst.internet.monitor.core.internal.http.ResendHTTPRequest;
import org.eclipse.wst.internet.monitor.core.internal.provisional.IMonitor;
import org.eclipse.wst.internet.monitor.core.internal.provisional.IMonitorListener;
import org.eclipse.wst.internet.monitor.core.internal.provisional.IMonitorWorkingCopy;
import org.eclipse.wst.internet.monitor.core.internal.provisional.Request;

public class MonitorManager
{
  private static final int ADD = 0;
  private static final int CHANGE = 1;
  private static final int REMOVE = 2;
  protected List<IMonitor> monitors;
  protected Map<IMonitor, AcceptThread> threads = new HashMap();
  protected List<IMonitorListener> monitorListeners = new ArrayList();
  private Preferences.IPropertyChangeListener pcl;
  protected boolean ignorePreferenceChanges = false;
  protected Map<Request, List<ResendHTTPRequest>> resendMap = new HashMap();
  protected static MonitorManager instance;
  
  static
  {
    MonitorPlugin.getInstance().executeStartups();
  }
  
  public static MonitorManager getInstance()
  {
    if (instance == null)
    {
      instance = new MonitorManager();
      instance.startMonitors();
    }
    return instance;
  }
  
  private MonitorManager()
  {
    loadMonitors();
    
    pcl = new Preferences.IPropertyChangeListener()
    {
      public void propertyChange(Preferences.PropertyChangeEvent event)
      {
        if (ignorePreferenceChanges) {
          return;
        }
        String property = event.getProperty();
        if (property.equals("monitors")) {
          loadMonitors();
        }
      }
    };
    MonitorPlugin.getInstance().getPluginPreferences().addPropertyChangeListener(pcl);
  }
  
  protected void dispose()
  {
    MonitorPlugin.getInstance().getPluginPreferences().removePropertyChangeListener(pcl);
  }
  
  public IMonitorWorkingCopy createMonitor()
  {
    return new MonitorWorkingCopy();
  }
  
  public List<IMonitor> getMonitors()
  {
    return new ArrayList(monitors);
  }
  
  protected synchronized void addMonitor(IMonitor monitor)
  {
    if (!monitors.contains(monitor)) {
      monitors.add(monitor);
    }
    fireMonitorEvent(monitor, 0);
    saveMonitors();
  }
  
  protected boolean isRunning(IMonitor monitor)
  {
    return threads.get(monitor) != null;
  }
  
  public void startMonitor(IMonitor monitor)
    throws CoreException
  {
    if (!monitors.contains(monitor)) {
      return;
    }
    if (AcceptThread.isPortInUse(monitor.getLocalPort())) {
      throw new CoreException(new Status(4, "org.eclipse.wst.internet.monitor.core", 0, NLS.bind(Messages.errorPortInUse, monitor.getLocalPort()), null));
    }
    AcceptThread thread = new AcceptThread(monitor);
    thread.startServer();
    threads.put(monitor, thread);
  }
  
  public void stopMonitor(IMonitor monitor)
  {
    if (!monitors.contains(monitor)) {
      return;
    }
    AcceptThread thread = (AcceptThread)threads.get(monitor);
    if (thread != null)
    {
      thread.stopServer();
      threads.remove(monitor);
    }
  }
  
  protected synchronized void removeMonitor(IMonitor monitor)
  {
    if (monitor.isRunning()) {
      stopMonitor(monitor);
    }
    monitors.remove(monitor);
    fireMonitorEvent(monitor, 2);
    saveMonitors();
  }
  
  protected synchronized void monitorChanged(IMonitor monitor)
  {
    fireMonitorEvent(monitor, 1);
    saveMonitors();
  }
  
  protected boolean exists(IMonitor monitor)
  {
    return monitors.contains(monitor);
  }
  
  public synchronized void addMonitorListener(IMonitorListener listener)
  {
    if (!monitorListeners.contains(listener)) {
      monitorListeners.add(listener);
    }
  }
  
  public synchronized void removeMonitorListener(IMonitorListener listener)
  {
    if (monitorListeners.contains(listener)) {
      monitorListeners.remove(listener);
    }
  }
  
  protected void fireMonitorEvent(IMonitor monitor, int type)
  {
    IMonitorListener[] obj = (IMonitorListener[])monitorListeners.toArray(new IMonitorListener[monitorListeners.size()]);
    IMonitorListener[] arrayOfIMonitorListener1;
    int j = (arrayOfIMonitorListener1 = obj).length;
    for (int i = 0; i < j; i++)
    {
      IMonitorListener listener = arrayOfIMonitorListener1[i];
      if (type == 0) {
        listener.monitorAdded(monitor);
      } else if (type == 1) {
        listener.monitorChanged(monitor);
      } else if (type == 2) {
        listener.monitorRemoved(monitor);
      }
    }
  }
  
  protected synchronized void loadMonitors()
  {
    if (Trace.FINEST) {
      Trace.trace("/finest", "Loading monitors");
    }
    monitors = new ArrayList();
    Preferences prefs = MonitorPlugin.getInstance().getPluginPreferences();
    String xmlString = prefs.getString("monitors");
    if ((xmlString != null) && (xmlString.length() > 0)) {
      try
      {
        ByteArrayInputStream in = new ByteArrayInputStream(xmlString.getBytes("UTF-8"));
        IMemento memento = XMLMemento.loadMemento(in);
        
        IMemento[] children = memento.getChildren("monitor");
        if (children != null)
        {
          int size = children.length;
          for (int i = 0; i < size; i++)
          {
            Monitor monitor = new Monitor();
            monitor.load(children[i]);
            monitors.add(monitor);
          }
        }
      }
      catch (Exception e)
      {
        if (Trace.WARNING) {
          Trace.trace("/warning", "Could not load monitors", e);
        }
      }
    }
  }
  
  protected synchronized void saveMonitors()
  {
    try
    {
      ignorePreferenceChanges = true;
      XMLMemento memento = XMLMemento.createWriteRoot("monitors");
      
      Iterator iterator = monitors.iterator();
      while (iterator.hasNext())
      {
        Monitor monitor = (Monitor)iterator.next();
        IMemento child = memento.createChild("monitor");
        monitor.save(child);
      }
      String xmlString = memento.saveToString();
      Preferences prefs = MonitorPlugin.getInstance().getPluginPreferences();
      prefs.setValue("monitors", xmlString);
      MonitorPlugin.getInstance().savePluginPreferences();
    }
    catch (Exception e)
    {
      if (Trace.SEVERE) {
        Trace.trace("/severe", "Could not save browsers", e);
      }
    }
    ignorePreferenceChanges = false;
  }
  
  public static ResendHTTPRequest createResendRequest(Request request)
  {
    if (request == null) {
      throw new IllegalArgumentException();
    }
    return new ResendHTTPRequest((Monitor)request.getMonitor(), request);
  }
  
  public void addResendRequest(Request request, ResendHTTPRequest resendReq)
  {
    if ((request == null) || (resendReq == null)) {
      return;
    }
    List<ResendHTTPRequest> list = null;
    try
    {
      list = (List)resendMap.get(request);
    }
    catch (Exception localException) {}
    if (list == null)
    {
      list = new ArrayList();
      resendMap.put(request, list);
    }
    list.add(resendReq);
  }
  
  public ResendHTTPRequest[] getResendRequests(Request request)
  {
    List<ResendHTTPRequest> list = (List)resendMap.get(request);
    if (list != null) {
      return (ResendHTTPRequest[])list.toArray(new ResendHTTPRequest[list.size()]);
    }
    return new ResendHTTPRequest[0];
  }
  
  public synchronized void startMonitors()
  {
    MonitorManager manager = getInstance();
    List monitorList = manager.getMonitors();
    Iterator monitorIterator = monitorList.iterator();
    while (monitorIterator.hasNext())
    {
      IMonitor monitor = (IMonitor)monitorIterator.next();
      if (monitor.isAutoStart()) {
        try
        {
          monitor.start();
        }
        catch (CoreException e)
        {
          if (Trace.SEVERE) {
            Trace.trace("/severe", "Failed to start monitor:" + monitor.toString(), e);
          }
        }
      }
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.wst.internet.monitor.core.internal.MonitorManager
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.internet.monitor.core.internal;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Plugin;
import org.eclipse.osgi.service.debug.DebugOptionsListener;
import org.osgi.framework.BundleContext;

public class MonitorPlugin
  extends Plugin
{
  public static final String PLUGIN_ID = "org.eclipse.wst.internet.monitor.core";
  private static MonitorPlugin singleton;
  protected Map<String, ProtocolAdapter> protocolAdapters;
  protected Map<String, IContentFilter> contentFilters;
  protected boolean startupsLoaded;
  
  public MonitorPlugin()
  {
    singleton = this;
    loadProtocolAdapters();
    loadContentFilters();
  }
  
  public static MonitorPlugin getInstance()
  {
    return singleton;
  }
  
  public String getDefaultType()
  {
    return "HTTP
1 2 3

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