org.eclipse.wst.jsdt.debug.rhino.debugger_1.0.201.v201201112313

16:49:09.432 INFO  jd.cli.Main - Decompiling org.eclipse.wst.jsdt.debug.rhino.debugger_1.0.201.v201201112313.jar
package org.eclipse.wst.jsdt.debug.internal.rhino.debugger;

import java.util.HashMap;

public class Breakpoint
{
  final Long breakpointId;
  final ScriptSource script;
  final Integer lineNumber;
  final Object functionName;
  final String condition;
  final Long threadId;
  
  public Breakpoint(Long breakpointId, ScriptSource script, Integer lineNumber, String functionName, String condition, Long threadId)
  {
    if (script == null) {
      throw new IllegalArgumentException("The parent script cannot be null");
    }
    this.breakpointId = breakpointId;
    this.script = script;
    this.lineNumber = lineNumber;
    this.functionName = functionName;
    this.condition = condition;
    this.threadId = threadId;
  }
  
  public Object toJSON()
  {
    HashMap result = new HashMap();
    result.put("breakpointId", breakpointId);
    result.put("scriptId", script.getId());
    if (lineNumber != null) {
      result.put("line", lineNumber);
    }
    if (functionName != null) {
      result.put("function", functionName);
    }
    if (condition != null) {
      result.put("condition", condition);
    }
    if (threadId != null) {
      result.put("threadId", threadId);
    }
    return result;
  }
  
  public void delete()
  {
    script.removeBreakpoint(this);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.wst.jsdt.debug.internal.rhino.debugger.Breakpoint
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.jsdt.debug.internal.rhino.debugger;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import org.eclipse.wst.jsdt.debug.internal.rhino.transport.EventPacket;

public class ContextData
{
  private static final int CONTEXT_RUNNING = 0;
  private static final int CONTEXT_SUSPENDED = 1;
  private static final int STEP_CONTINUE = 0;
  private static final int STEP_IN = 1;
  private static final int STEP_NEXT = 2;
  private static final int STEP_OUT = 4;
  private final Long threadId;
  private final Long contextId;
  private final RhinoDebuggerImpl debugger;
  private final LinkedList frames = new LinkedList();
  private int contextState = 0;
  private int stepState = 0;
  private StackFrame stepFrame;
  
  public ContextData(Long threadId, Long contextId, RhinoDebuggerImpl debugger)
  {
    this.threadId = threadId;
    this.contextId = contextId;
    this.debugger = debugger;
  }
  
  public Long getId()
  {
    return contextId;
  }
  
  public synchronized List getFrameIds()
  {
    List result = new ArrayList();
    for (Iterator iterator = frames.iterator(); iterator.hasNext();) {
      result.add(((StackFrame)iterator.next()).getId());
    }
    return result;
  }
  
  public synchronized StackFrame getFrame(Long frameId)
  {
    StackFrame frame = null;
    for (Iterator iterator = frames.iterator(); iterator.hasNext();)
    {
      frame = (StackFrame)iterator.next();
      if (frame.getId().equals(frameId)) {
        return frame;
      }
    }
    return null;
  }
  
  public synchronized void pushFrame(StackFrame frame, ScriptSource script, Integer lineNumber, String functionName)
  {
    frames.addFirst(frame);
    Breakpoint breakpoint = script.getBreakpoint(lineNumber, functionName);
    boolean isStepBreak = stepBreak(1);
    if (((isStepBreak) || (breakpoint != null)) && 
      (sendBreakEvent(script, frame.getLineNumber(), functionName, breakpoint, isStepBreak, false))) {
      suspendState();
    }
  }
  
  private boolean stepBreak(int step)
  {
    return ((step & stepState) != 0) && ((stepFrame == null) || (stepFrame == frames.getFirst()));
  }
  
  private void suspendState()
  {
    contextState = 1;
    while (contextState == 1) {
      try
      {
        wait();
      }
      catch (InterruptedException e)
      {
        e.printStackTrace();
      }
    }
  }
  
  public synchronized void popFrame(boolean byThrow, Object resultOrException)
  {
    if (!frames.isEmpty())
    {
      StackFrame frame = (StackFrame)frames.removeFirst();
      if (stepFrame == frame)
      {
        stepFrame = null;
        stepState = 4;
      }
      boolean isStepBreak = stepBreak(5);
      if (isStepBreak)
      {
        frame = getTopFrame();
        if ((frame != null) && (sendBreakEvent(frame.getScript(), frame.getLineNumber(), null, null, isStepBreak, false))) {
          suspendState();
        }
      }
    }
  }
  
  public synchronized void resume(String stepType)
  {
    try
    {
      if (stepType == null)
      {
        stepState = 0;
        stepFrame = null;
        break label185;
      }
      if (stepType.equals("in"))
      {
        stepState = 1;
        stepFrame = null;
        break label185;
      }
      if (stepType.equals("next"))
      {
        stepState = 2;
        stepFrame = getTopFrame();
        break label185;
      }
      if (stepType.equals("out"))
      {
        if (frames.size() > 1)
        {
          stepState = 4;
          stepFrame = ((StackFrame)frames.get(1));
          break label185;
        }
        stepState = 0;
        stepFrame = null;
        break label185;
      }
      if (stepType.equals("any"))
      {
        stepState = 7;
        stepFrame = null;
        break label185;
      }
      throw new IllegalStateException("bad stepType: " + stepType);
    }
    finally
    {
      jsr 5;
    }
    localObject1 = 
    
      returnAddress;contextState = 0;notifyAll();ret;
    label185:
    jsr -12;
  }
  
  private StackFrame getTopFrame()
  {
    if ((frames != null) && (!frames.isEmpty())) {
      return (StackFrame)frames.getFirst();
    }
    return null;
  }
  
  public synchronized void suspend()
  {
    stepState = 7;
    stepFrame = null;
  }
  
  public synchronized void debuggerStatement(ScriptSource script, Integer lineNumber)
  {
    Breakpoint breakpoint = script.getBreakpoint(lineNumber, null);
    boolean isStepBreak = stepBreak(3);
    if (sendBreakEvent(script, lineNumber, null, breakpoint, isStepBreak, true)) {
      suspendState();
    }
  }
  
  public synchronized void lineChange(ScriptSource script, Integer lineNumber)
  {
    Breakpoint breakpoint = script.getBreakpoint(lineNumber, null);
    boolean isStepBreak = stepBreak(3);
    if (((isStepBreak) || (breakpoint != null)) && 
      (sendBreakEvent(script, lineNumber, null, breakpoint, isStepBreak, false))) {
      suspendState();
    }
  }
  
  public synchronized void exceptionThrown(Throwable ex)
  {
    StackFrame frame = getTopFrame();
    if (sendExceptionEvent(frame.getScript(), frame.getLineNumber(), ex)) {
      suspendState();
    }
  }
  
  private boolean sendExceptionEvent(ScriptSource script, Integer lineNumber, Throwable ex)
  {
    EventPacket exceptionEvent = new EventPacket("exception");
    Map body = exceptionEvent.getBody();
    body.put("contextId", contextId);
    body.put("threadId", threadId);
    body.put("scriptId", script.getId());
    body.put("line", lineNumber);
    body.put("message", ex.getMessage());
    return debugger.sendEvent(exceptionEvent);
  }
  
  private boolean sendBreakEvent(ScriptSource script, Integer lineNumber, String functionName, Breakpoint breakpoint, boolean isStepBreak, boolean isDebuggerStatement)
  {
    EventPacket breakEvent = new EventPacket("break");
    Map body = breakEvent.getBody();
    body.put("threadId", threadId);
    body.put("contextId", contextId);
    body.put("scriptId", script.getId());
    if (functionName != null) {
      body.put("functionName", functionName);
    }
    body.put("line", lineNumber);
    if (breakpoint != null) {
      body.put("breakpoint", breakpointId);
    }
    if (isStepBreak)
    {
      String stepType;
      String stepType;
      if (stepState == 1)
      {
        stepType = "in";
      }
      else
      {
        String stepType;
        if (stepState == 2)
        {
          stepType = "next";
        }
        else
        {
          String stepType;
          if (stepState == 4) {
            stepType = "out";
          } else {
            stepType = "suspend";
          }
        }
      }
      body.put("step", stepType);
      stepState = 0;
    }
    body.put("debuggerStatement", Boolean.valueOf(isDebuggerStatement));
    return debugger.sendEvent(breakEvent);
  }
  
  public synchronized void scriptLoaded(ScriptSource script)
  {
    if (sendScriptEvent(script)) {
      suspendState();
    }
  }
  
  private boolean sendScriptEvent(ScriptSource script)
  {
    EventPacket scriptEvent = new EventPacket("script");
    Map body = scriptEvent.getBody();
    body.put("threadId", threadId);
    body.put("contextId", contextId);
    body.put("scriptId", script.getId());
    return debugger.sendEvent(scriptEvent);
  }
  
  public synchronized String getState()
  {
    return contextState == 0 ? "running" : "suspended";
  }
  
  public Long getThreadId()
  {
    return threadId;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.wst.jsdt.debug.internal.rhino.debugger.ContextData
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.jsdt.debug.internal.rhino.debugger;

import java.io.IOException;
import java.io.PrintStream;
import org.eclipse.wst.jsdt.debug.internal.rhino.transport.RhinoRequest;
import org.eclipse.wst.jsdt.debug.internal.rhino.transport.RhinoResponse;
import org.eclipse.wst.jsdt.debug.transport.Connection;
import org.eclipse.wst.jsdt.debug.transport.DebugSession;
import org.eclipse.wst.jsdt.debug.transport.ListenerKey;
import org.eclipse.wst.jsdt.debug.transport.TransportService;
import org.eclipse.wst.jsdt.debug.transport.exception.DisconnectedException;
import org.eclipse.wst.jsdt.debug.transport.exception.TimeoutException;

public class DebugSessionManager$DebugSessionThread
  extends Thread
{
  private ListenerKey listenerKey;
  private Connection connection;
  private RequestHandler requestHandler;
  final DebugSessionManager this$0;
  
  public DebugSessionManager$DebugSessionThread(DebugSessionManager paramDebugSessionManager, String name, RhinoDebuggerImpl debugger)
  {
    super(name);this$0 = paramDebugSessionManager;
    requestHandler = new RequestHandler(debugger);
  }
  
  public void run()
  {
    try
    {
      listenerKey = DebugSessionManager.access$0(this$0).startListening(DebugSessionManager.access$2(this$0));
      label123:
      while (!DebugSessionManager.access$3(this$0))
      {
        try
        {
          acceptConnection(10000L);
        }
        catch (IOException localIOException1)
        {
          if (connection != null) {
            break label123;
          }
        }
        continue;
        while ((!DebugSessionManager.access$3(this$0)) && (connection.isOpen())) {
          try
          {
            RhinoRequest request = (RhinoRequest)DebugSessionManager.access$4(this$0).receive("request", 1000);
            if (DebugSessionManager.access$5()) {
              System.out.println(request);
            }
            RhinoResponse response = requestHandler.handleRequest(request);
            if (DebugSessionManager.access$5()) {
              System.out.println(response);
            }
            DebugSessionManager.access$4(this$0).send(response);
          }
          catch (TimeoutException localTimeoutException) {}catch (DisconnectedException localDisconnectedException)
          {
            break;
          }
        }
        closeConnection();
      }
    }
    catch (IOException localIOException2)
    {
      DebugSessionManager.access$1(this$0);
    }
    finally
    {
      try
      {
        if (listenerKey != null) {
          DebugSessionManager.access$0(this$0).stopListening(listenerKey);
        }
      }
      catch (IOException localIOException3)
      {
        DebugSessionManager.access$1(this$0);
      }
    }
  }
  
  private void closeConnection()
    throws IOException
  {
    if (connection != null)
    {
      DebugSessionManager.access$6(this$0, null);
      connection.close();
      connection = null;
    }
  }
  
  private void acceptConnection(long timeout)
    throws IOException
  {
    if (connection == null)
    {
      connection = DebugSessionManager.access$0(this$0).accept(listenerKey, timeout, timeout);
      DebugSessionManager.access$6(this$0, new DebugSession(connection));
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.wst.jsdt.debug.internal.rhino.debugger.DebugSessionManager.DebugSessionThread
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.jsdt.debug.internal.rhino.debugger;

import java.io.IOException;
import java.io.PrintStream;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;
import org.eclipse.wst.jsdt.debug.internal.rhino.transport.EventPacket;
import org.eclipse.wst.jsdt.debug.internal.rhino.transport.RhinoRequest;
import org.eclipse.wst.jsdt.debug.internal.rhino.transport.RhinoResponse;
import org.eclipse.wst.jsdt.debug.internal.rhino.transport.RhinoTransportService;
import org.eclipse.wst.jsdt.debug.transport.Connection;
import org.eclipse.wst.jsdt.debug.transport.DebugSession;
import org.eclipse.wst.jsdt.debug.transport.ListenerKey;
import org.eclipse.wst.jsdt.debug.transport.TransportService;
import org.eclipse.wst.jsdt.debug.transport.exception.DisconnectedException;
import org.eclipse.wst.jsdt.debug.transport.exception.TimeoutException;

public class DebugSessionManager
{
  public class DebugSessionThread
    extends Thread
  {
    private ListenerKey listenerKey;
    private Connection connection;
    private RequestHandler requestHandler;
    
    public DebugSessionThread(String name, RhinoDebuggerImpl debugger)
    {
      super();
      requestHandler = new RequestHandler(debugger);
    }
    
    public void run()
    {
      try
      {
        listenerKey = transportService.startListening(address);
        label123:
        while (!shutdown)
        {
          try
          {
            acceptConnection(10000L);
          }
          catch (IOException localIOException1)
          {
            if (connection != null) {
              break label123;
            }
          }
          continue;
          while ((!shutdown) && (connection.isOpen())) {
            try
            {
              RhinoRequest request = (RhinoRequest)debugSession.receive("request", 1000);
              if (DebugSessionManager.DEBUG) {
                System.out.println(request);
              }
              RhinoResponse response = requestHandler.handleRequest(request);
              if (DebugSessionManager.DEBUG) {
                System.out.println(response);
              }
              debugSession.send(response);
            }
            catch (TimeoutException localTimeoutException) {}catch (DisconnectedException localDisconnectedException)
            {
              break;
            }
          }
          closeConnection();
        }
      }
      catch (IOException localIOException2)
      {
        DebugSessionManager.this.sendDeathEvent();
      }
      finally
      {
        try
        {
          if (listenerKey != null) {
            transportService.stopListening(listenerKey);
          }
        }
        catch (IOException localIOException3)
        {
          DebugSessionManager.this.sendDeathEvent();
        }
      }
    }
    
    private void closeConnection()
      throws IOException
    {
      if (connection != null)
      {
        DebugSessionManager.this.setDebugSession(null);
        connection.close();
        connection = null;
      }
    }
    
    private void acceptConnection(long timeout)
      throws IOException
    {
      if (connection == null)
      {
        connection = transportService.accept(listenerKey, timeout, timeout);
        DebugSessionManager.this.setDebugSession(new DebugSession(connection));
      }
    }
  }
  
  private static boolean DEBUG = false;
  private static final String ADDRESS = "address";
  private static final String SOCKET = "socket";
  private static final String TRANSPORT = "transport";
  private final TransportService transportService;
  private final String address;
  private final boolean startSuspended;
  private DebugSession debugSession;
  private Thread debuggerThread;
  private volatile boolean shutdown = false;
  
  public DebugSessionManager(TransportService transportService, String address, boolean startSuspended, boolean debug)
  {
    this.transportService = transportService;
    this.address = address;
    this.startSuspended = startSuspended;
    DEBUG = debug;
  }
  
  static DebugSessionManager create(String configString)
  {
    Map config = parseConfigString(configString);
    String transport = (String)config.get("transport");
    if (!"socket".equals(transport)) {
      throw new IllegalArgumentException("Transport service must be 'socket': " + transport);
    }
    TransportService parsedTransportService = new RhinoTransportService();
    String parsedAddress = (String)config.get("address");
    String suspend = (String)config.get("suspend");
    boolean parsedStartSuspended = false;
    if (suspend != null) {
      parsedStartSuspended = (Boolean.valueOf(suspend).booleanValue()) || (suspend.trim().equalsIgnoreCase("y"));
    }
    String debug = (String)config.get("trace");
    boolean debugging = false;
    if (debug != null) {
      debugging = (Boolean.valueOf(debug).booleanValue()) || (debug.trim().equalsIgnoreCase("y"));
    }
    return new DebugSessionManager(parsedTransportService, parsedAddress, parsedStartSuspended, debugging);
  }
  
  private static Map parseConfigString(String configString)
  {
    Map config = new HashMap();
    StringTokenizer tokenizer = new StringTokenizer(configString, ",");
    while (tokenizer.hasMoreTokens())
    {
      String token = tokenizer.nextToken();
      int equalsIndex = token.indexOf('=');
      if (equalsIndex == -1) {
        config.put(token, null);
      } else {
        config.put(token.substring(0, equalsIndex), token.substring(equalsIndex + 1));
      }
    }
    return config;
  }
  
  public boolean isStartSuspended()
  {
    return startSuspended;
  }
  
  public synchronized boolean isConnected()
  {
    return debugSession != null;
  }
  
  public synchronized void start(RhinoDebuggerImpl debugger)
  {
    debuggerThread = new DebugSessionThread("RhinoDebugger - RhinoRequest Handler", debugger);
    debuggerThread.start();
    if (startSuspended) {
      try
      {
        wait(300000L);
      }
      catch (InterruptedException localInterruptedException) {}
    }
  }
  
  public synchronized void stop()
  {
    shutdown = true;
    try
    {
      debuggerThread.interrupt();
      while (debuggerThread.isAlive()) {
        wait(1000L);
      }
      debuggerThread.join();
    }
    catch (InterruptedException localInterruptedException) {}
  }
  
  private synchronized void setDebugSession(DebugSession session)
  {
    if (debugSession != session)
    {
      if (debugSession != null) {
        debugSession.dispose();
      }
      debugSession = session;
      notify();
    }
  }
  
  public synchronized boolean sendEvent(EventPacket event)
  {
    try
    {
      if (debugSession != null)
      {
        if (DEBUG) {
          System.out.println(event);
        }
        debugSession.send(event);
        return true;
      }
    }
    catch (DisconnectedException e)
    {
      e.printStackTrace();
    }
    return false;
  }
  
  private void sendDeathEvent()
  {
    EventPacket event = new EventPacket("vmdeath");
    sendEvent(event);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.wst.jsdt.debug.internal.rhino.debugger.DebugSessionManager
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.jsdt.debug.internal.rhino.debugger;

public class FunctionSource
{
  final ScriptSource parent;
  final String name;
  String source;
  final int linenumber;
  
  public FunctionSource(ScriptSource script, String name, String source, int linenumber)
  {
    if (script == null) {
      throw new IllegalArgumentException("The parent script cannot be null");
    }
    parent = script;
    this.name = name;
    this.source = source;
    this.linenumber = linenumber;
  }
  
  public ScriptSource parent()
  {
    return parent;
  }
  
  public String name()
  {
    return name;
  }
  
  public String source()
  {
    return source;
  }
  
  public void setSource(String source)
  {
    this.source = source;
  }
  
  public int linenumber()
  {
    return linenumber;
  }
  
  public String toString()
  {
    StringBuffer buffer = new StringBuffer();
    buffer.append("FunctionSource: [name - ").append(name).append("] [linenumber - ").append(linenumber).append("]\n");
    buffer.append("\tparent: ").append(parent.getLocation());
    buffer.append("\tsource: ").append(source).append("\n");
    return buffer.toString();
  }
}

/* Location:
 * Qualified Name:     org.eclipse.wst.jsdt.debug.internal.rhino.debugger.FunctionSource
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.jsdt.debug.internal.rhino.debugger;

public class LineData
{
  Breakpoint breakpoint = null;
  FunctionSource function = null;
}

/* Location:
 * Qualified Name:     org.eclipse.wst.jsdt.debug.internal.rhino.debugger.LineData
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.jsdt.debug.internal.rhino.debugger;

import java.util.Collection;
import java.util.List;
import java.util.Map;
import org.eclipse.wst.jsdt.debug.internal.rhino.transport.RhinoRequest;
import org.eclipse.wst.jsdt.debug.internal.rhino.transport.RhinoResponse;

public class RequestHandler
{
  public static final String VERSION_1_6 = "1.6";
  private RhinoDebuggerImpl debugger;
  
  public RequestHandler(RhinoDebuggerImpl debugger)
  {
    this.debugger = debugger;
  }
  
  public RhinoResponse handleRequest(RhinoRequest request)
  {
    String command = request.getCommand();
    RhinoResponse response = new RhinoResponse(request.getSequence(), command);
    try
    {
      if (command.equals("version"))
      {
        handleVersionRequest(request, response);
      }
      else if (command.equals("suspend"))
      {
        handleSuspendRequest(request, response);
      }
      else if (command.equals("continue"))
      {
        handleContinueRequest(request, response);
      }
      else if (command.equals("dispose"))
      {
        handleDisposeRequest(request, response);
      }
      else if (command.equals("threads"))
      {
        handleThreadsRequest(request, response);
      }
      else if (command.equals("thread"))
      {
        handleThreadRequest(request, response);
      }
      else if (command.equals("frames"))
      {
        handleFramesRequest(request, response);
      }
      else if (command.equals("frame"))
      {
        handleFrameRequest(request, response);
      }
      else if (command.equals("scripts"))
      {
        handleScriptsRequest(request, response);
      }
      else if (command.equals("script"))
      {
        handleScriptRequest(request, response);
      }
      else if (command.equals("evaluate"))
      {
        handleEvaluateRequest(request, response);
      }
      else if (command.equals("lookup"))
      {
        handleLookupRequest(request, response);
      }
      else if (command.equals("breakpoints"))
      {
        handleBreakpointsRequest(request, response);
      }
      else if (command.equals("breakpoint"))
      {
        handleBreakpointRequest(request, response);
      }
      else if (command.equals("setbreakpoint"))
      {
        handleSetBreakpointRequest(request, response);
      }
      else if (command.equals("clearbreakpoint"))
      {
        handleClearBreakpointRequest(request, response);
      }
      else
      {
        response.setSuccess(false);
        response.setMessage("command not supported");
      }
    }
    catch (Throwable t)
    {
      response.setSuccess(false);
      response.setMessage(t.getClass().getName() + " - " + t.getMessage());
      t.printStackTrace();
    }
    return response;
  }
  
  private void handleClearBreakpointRequest(RhinoRequest request, RhinoResponse response)
  {
    Map arguments = request.getArguments();
    Long breakpointId = numberToLong((Number)arguments.get("breakpointId"));
    if (breakpointId == null)
    {
      response.setSuccess(false);
      response.setMessage(missingArgument("breakpointId"));
      return;
    }
    Breakpoint breakpoint = debugger.clearBreakpoint(breakpointId);
    if (breakpoint == null)
    {
      response.setSuccess(false);
      response.setMessage("not found");
      return;
    }
    response.getBody().put("breakpoint", breakpoint.toJSON());
  }
  
  private void handleSetBreakpointRequest(RhinoRequest request, RhinoResponse response)
  {
    Map arguments = request.getArguments();
    Long scriptId = numberToLong((Number)arguments.get("scriptId"));
    Integer line = numberToInteger((Number)arguments.get("line"));
    String function = (String)arguments.get("function");
    Long threadId = numberToLong((Number)arguments.get("threadId"));
    String condition = (String)arguments.get("condition");
    Breakpoint breakpoint = debugger.setBreakpoint(scriptId, line, function, condition, threadId);
    if (breakpoint != null) {
      response.getBody().put("breakpoint", breakpoint.toJSON());
    }
  }
  
  private void handleBreakpointRequest(RhinoRequest request, RhinoResponse response)
  {
    Map arguments = request.getArguments();
    Long breakpointId = numberToLong((Number)arguments.get("breakpointId"));
    if (breakpointId == null)
    {
      response.setSuccess(false);
      response.setMessage(missingArgument("breakpointId"));
      return;
    }
    Breakpoint breakpoint = debugger.getBreakpoint(breakpointId);
    if (breakpoint == null)
    {
      response.setSuccess(false);
      response.setMessage("not found");
      return;
    }
    response.getBody().put("breakpoint", breakpoint.toJSON());
  }
  
  private void handleBreakpointsRequest(RhinoRequest request, RhinoResponse response)
  {
    Collection breakpoints = debugger.getBreakpoints();
    response.getBody().put("breakpoints", breakpoints);
  }
  
  private void handleEvaluateRequest(RhinoRequest request, RhinoResponse response)
  {
    Map arguments = request.getArguments();
    Long threadId = numberToLong((Number)arguments.get("threadId"));
    if (threadId == null)
    {
      response.setSuccess(false);
      response.setMessage(missingArgument("threadId"));
      return;
    }
    Long frameId = numberToLong((Number)arguments.get("frameId"));
    if (frameId == null)
    {
      response.setSuccess(false);
      response.setMessage(missingArgument("frameId"));
      return;
    }
    String evaluate = (String)arguments.get("expression");
    if (evaluate == null)
    {
      response.setSuccess(false);
      response.setMessage(missingArgument("expression"));
      return;
    }
    StackFrame frame = debugger.getFrame(threadId, frameId);
    if (frame == null)
    {
      response.setSuccess(false);
      response.setMessage("not found");
      return;
    }
    Object result = frame.evaluate(evaluate);
    response.getBody().put("evaluate", result);
  }
  
  private void handleLookupRequest(RhinoRequest request, RhinoResponse response)
  {
    Map arguments = request.getArguments();
    Long threadId = numberToLong((Number)arguments.get("threadId"));
    if (threadId == null)
    {
      response.setSuccess(false);
      response.setMessage(missingArgument("threadId"));
      return;
    }
    Long frameId = numberToLong((Number)arguments.get("frameId"));
    if (frameId == null)
    {
      response.setSuccess(false);
      response.setMessage(missingArgument("frameId"));
      return;
    }
    Long handle = numberToLong((Number)arguments.get("ref"));
    if (handle == null)
    {
      response.setSuccess(false);
      response.setMessage(missingArgument("ref"));
      return;
    }
    StackFrame frame = debugger.getFrame(threadId, frameId);
    if (frame == null)
    {
      response.setSuccess(false);
      response.setMessage("not found");
      return;
    }
    Object result = frame.lookup(handle);
    response.getBody().put("lookup", result);
  }
  
  private void handleScriptRequest(RhinoRequest request, RhinoResponse response)
  {
    Map arguments = request.getArguments();
    Long scriptId = numberToLong((Number)arguments.get("scriptId"));
    if (scriptId == null)
    {
      response.setSuccess(false);
      response.setMessage(missingArgument("scriptId"));
      return;
    }
    ScriptSource script = debugger.getScript(scriptId);
    if (script == null)
    {
      response.setSuccess(false);
      response.setMessage("not found");
      return;
    }
    response.getBody().put("script", script.toJSON());
  }
  
  private void handleScriptsRequest(RhinoRequest request, RhinoResponse response)
  {
    List scriptIds = debugger.getScriptIds();
    response.getBody().put("scripts", scriptIds);
  }
  
  private void handleFrameRequest(RhinoRequest request, RhinoResponse response)
  {
    Map arguments = request.getArguments();
    Long threadId = numberToLong((Number)arguments.get("threadId"));
    if (threadId == null)
    {
      response.setSuccess(false);
      response.setMessage(missingArgument("threadId"));
      return;
    }
    Long frameId = numberToLong((Number)arguments.get("frameId"));
    if (frameId == null)
    {
      response.setSuccess(false);
      response.setMessage(missingArgument("frameId"));
      return;
    }
    StackFrame frame = debugger.getFrame(threadId, frameId);
    if (frame == null)
    {
      response.setSuccess(false);
      response.setMessage("not found");
      return;
    }
    response.getBody().put("frame", frame.toJSON());
  }
  
  private void handleFramesRequest(RhinoRequest request, RhinoResponse response)
  {
    Map arguments = request.getArguments();
    Long threadId = numberToLong((Number)arguments.get("threadId"));
    if (threadId == null)
    {
      response.setSuccess(false);
      response.setMessage(missingArgument("threadId"));
      return;
    }
    List frameIds = debugger.getFrameIds(threadId);
    response.getBody().put("frames", frameIds);
  }
  
  private void handleThreadRequest(RhinoRequest request, RhinoResponse response)
  {
    Map arguments = request.getArguments();
    Long threadId = numberToLong((Number)arguments.get("threadId"));
    if (threadId == null)
    {
      response.setSuccess(false);
      response.setMessage(missingArgument("threadId"));
      return;
    }
    ThreadData threadData = debugger.getThreadData(threadId);
    if (threadData == null)
    {
      response.setSuccess(false);
      response.setMessage("not found");
      return;
    }
    response.getBody().put("thread", threadData.toJSON());
  }
  
  private String missingArgument(String key)
  {
    return "Missing Argument: " + key;
  }
  
  private void handleThreadsRequest(RhinoRequest request, RhinoResponse response)
  {
    List threadIds = debugger.getThreadIds();
    response.getBody().put("threads", threadIds);
  }
  
  private void handleDisposeRequest(RhinoRequest request, RhinoResponse response)
  {
    debugger.disconnect();
  }
  
  private void handleContinueRequest(RhinoRequest request, RhinoResponse response)
  {
    Map arguments = request.getArguments();
    Long threadId = numberToLong((Number)arguments.get("threadId"));
    if (threadId == null)
    {
      debugger.resumeAll();
      return;
    }
    String stepType = (String)arguments.get("step");
    debugger.resume(threadId, stepType);
  }
  
  private void handleSuspendRequest(RhinoRequest request, RhinoResponse response)
  {
    Map arguments = request.getArguments();
    Long threadId = numberToLong((Number)arguments.get("threadId"));
    if (threadId == null)
    {
      debugger.suspendAll();
      return;
    }
    debugger.suspend(threadId);
  }
  
  private static Long numberToLong(Number number)
  {
    if (number == null) {
      return null;
    }
    return new Long(number.longValue());
  }
  
  private Integer numberToInteger(Number number)
  {
    if (number == null) {
      return null;
    }
    return new Integer(number.intValue());
  }
  
  private void handleVersionRequest(RhinoRequest request, RhinoResponse response)
  {
    Map body = response.getBody();
    body.put("javascript.version", "1.6");
    body.put("ecmascript.version", "3");
    body.put("javascript.vm.name", "Rhino");
    body.put("javascript.vm.version", "1.6");
    body.put("javascript.vm.vendor", "Mozilla");
  }
}

/* Location:
 * Qualified Name:     org.eclipse.wst.jsdt.debug.internal.rhino.debugger.RequestHandler
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.jsdt.debug.internal.rhino.debugger;

import java.io.File;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.eclipse.wst.jsdt.debug.internal.rhino.transport.EventPacket;
import org.eclipse.wst.jsdt.debug.internal.rhino.transport.JSONUtil;
import org.eclipse.wst.jsdt.debug.transport.TransportService;
import org.mozilla.javascript.Context;
import org.mozilla.javascript.ContextFactory.Listener;
import org.mozilla.javascript.debug.DebugFrame;
import org.mozilla.javascript.debug.DebuggableScript;
import org.mozilla.javascript.debug.Debugger;

public class RhinoDebuggerImpl
  implements Debugger, ContextFactory.Listener
{
  public static final DebuggableScript[] NO_SCRIPTS = new DebuggableScript[0];
  private static final String RHINO_SCHEME = "rhino";
  private final Map threadToThreadId = new HashMap();
  private final Map threadIdToData = new HashMap();
  private final Map breakpoints = new HashMap();
  private long currentThreadId = 0L;
  private long currentBreakpointId = 0L;
  private long currentScriptId = 0L;
  private ArrayList disabledThreads = new ArrayList();
  private HashMap uriToScript = new HashMap();
  private HashMap idToScript = new HashMap();
  private final DebugSessionManager sessionManager;
  
  public RhinoDebuggerImpl(String configString)
  {
    sessionManager = DebugSessionManager.create(configString);
  }
  
  public RhinoDebuggerImpl(TransportService transportService, String address, boolean startSuspended, boolean trace)
  {
    sessionManager = new DebugSessionManager(transportService, address, startSuspended, trace);
  }
  
  public synchronized DebugFrame getFrame(Context context, DebuggableScript debuggableScript)
  {
    ScriptSource script = getScript(debuggableScript);
    if ((script != null) && (!script.isStdIn()))
    {
      ContextData contextData = (ContextData)context.getDebuggerContextData();
      ThreadData thread = (ThreadData)threadIdToData.get(contextData.getThreadId());
      FunctionSource function = script.getFunction(debuggableScript);
      return thread.getFrame(context, function, script);
    }
    return null;
  }
  
  private ScriptSource getScript(DebuggableScript script)
  {
    synchronized (uriToScript)
    {
      DebuggableScript root = script;
      while (!root.isTopLevel()) {
        root = root.getParent();
      }
      URI uri = getSourceUri(root, parseSourceProperties(root.getSourceName()));
      if (uri != null) {
        return (ScriptSource)uriToScript.get(uri);
      }
    }
    return null;
  }
  
  public void handleCompilationDone(Context context, DebuggableScript script, String source)
  {
    if (!script.isTopLevel()) {
      return;
    }
    Map properties = parseSourceProperties(script.getSourceName());
    URI uri = getSourceUri(script, properties);
    if (uri == null) {
      return;
    }
    ScriptSource newscript = new ScriptSource(script, source, uri, script.isGeneratedScript(), properties);
    synchronized (uriToScript)
    {
      ScriptSource old = (ScriptSource)uriToScript.remove(uri);
      Long id = null;
      if (old != null)
      {
        id = old.getId();
        idToScript.remove(id);
        newscript.setId(id);
        
        old.clearBreakpoints(this);
      }
      else
      {
        id = scriptId();
        newscript.setId(id);
      }
      uriToScript.put(uri, newscript);
      idToScript.put(id, newscript);
    }
    ContextData contextData = (ContextData)context.getDebuggerContextData();
    contextData.scriptLoaded(newscript);
  }
  
  private URI getSourceUri(DebuggableScript script, Map properties)
  {
    String sourceName = script.getSourceName();
    if (properties != null)
    {
      String jsonName = (String)properties.get("name");
      if (jsonName != null) {
        sourceName = jsonName;
      }
    }
    if (sourceName == null) {
      return null;
    }
    if (sourceName.equals("<stdin>")) {
      sourceName = "stdin";
    }
    if (sourceName.equals("<command>"))
    {
      sourceName = "command";
    }
    else
    {
      File sourceFile = new File(sourceName);
      if (sourceFile.exists()) {
        return sourceFile.toURI();
      }
      try
      {
        return new URI(sourceName);
      }
      catch (URISyntaxException localURISyntaxException1) {}
    }
    try
    {
      if (sourceName.charAt(0) != '/') {
        sourceName = "/" + sourceName;
      }
      return new URI("rhino", null, sourceName, null);
    }
    catch (URISyntaxException localURISyntaxException2) {}
    return null;
  }
  
  Map parseSourceProperties(String sourceName)
  {
    if ((sourceName != null) && (sourceName.charAt(0) == '{')) {
      try
      {
        Object json = JSONUtil.read(sourceName);
        if ((json instanceof Map)) {
          return (Map)json;
        }
      }
      catch (RuntimeException localRuntimeException) {}
    }
    return null;
  }
  
  synchronized Long scriptId()
  {
    return new Long(currentScriptId++);
  }
  
  public synchronized void contextCreated(Context context)
  {
    Thread thread = Thread.currentThread();
    if (disabledThreads.contains(thread)) {
      return;
    }
    Long threadId = (Long)threadToThreadId.get(thread);
    if (threadId == null)
    {
      threadId = new Long(currentThreadId++);
      threadToThreadId.put(thread, threadId);
    }
    ThreadData threadData = (ThreadData)threadIdToData.get(threadId);
    if (threadData == null)
    {
      threadData = new ThreadData(threadId, this);
      threadIdToData.put(threadId, threadData);
      sendThreadEvent("enter", threadId);
    }
    threadData.contextCreated(context);
  }
  
  private void sendThreadEvent(String type, Long threadId)
  {
    EventPacket threadEvent = new EventPacket("thread");
    Map body = threadEvent.getBody();
    body.put("type", type);
    body.put("threadId", threadId);
    sendEvent(threadEvent);
  }
  
  public synchronized void contextReleased(Context context)
  {
    Thread thread = Thread.currentThread();
    if (disabledThreads.contains(thread)) {
      return;
    }
    Long threadId = (Long)threadToThreadId.get(thread);
    if (threadId == null) {
      return;
    }
    ThreadData threadData = (ThreadData)threadIdToData.get(threadId);
    threadData.contextReleased(context);
    if (!threadData.hasContext())
    {
      threadToThreadId.remove(thread);
      threadIdToData.remove(threadId);
      sendThreadEvent("exit", threadId);
    }
  }
  
  public synchronized void resume(Long threadId, String stepType)
  {
    ThreadData threadData = (ThreadData)threadIdToData.get(threadId);
    if (threadData != null) {
      threadData.resume(stepType);
    }
  }
  
  public synchronized void resumeAll()
  {
    for (Iterator it = threadIdToData.keySe
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