[jboss-svn-commits] JBL Code SVN: r12965 - in labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse: debug/core and 3 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Sat Jun 30 17:10:21 EDT 2007


Author: ahtik
Date: 2007-06-30 17:10:20 -0400 (Sat, 30 Jun 2007)
New Revision: 12965

Added:
   labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/debug/core/MVELStackFrame.java
   labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/debug/core/MVELThisVariable.java
Modified:
   labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/DRLInfo.java
   labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/debug/core/DroolsDebugModelPresentation.java
   labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/debug/core/DroolsDebugTarget.java
   labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/debug/core/DroolsLineBreakpoint.java
   labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/debug/core/DroolsStackFrame.java
   labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/debug/core/DroolsThread.java
   labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/DroolsLineBreakpointAdapter.java
   labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/launching/DroolsSourceLookupDirector.java
   labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/launching/DroolsSourceLookupParticipant.java
   labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/launching/DroolsVMDebugger.java
   labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/rulebuilder/editors/BrlPage.java
Log:
work in progress debugger code

Modified: labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/DRLInfo.java
===================================================================
--- labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/DRLInfo.java	2007-06-30 21:10:06 UTC (rev 12964)
+++ labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/DRLInfo.java	2007-06-30 21:10:20 UTC (rev 12965)
@@ -9,7 +9,10 @@
 import org.drools.lang.descr.FunctionDescr;
 import org.drools.lang.descr.PackageDescr;
 import org.drools.lang.descr.RuleDescr;
+import org.drools.rule.LineMappings;
 import org.drools.rule.Package;
+import org.drools.rule.PackageCompilationData;
+import org.drools.rule.builder.Dialect;
 
 public class DRLInfo {
 
@@ -92,6 +95,7 @@
 	
 	public RuleInfo getRuleInfo(int drlLineNumber) {
 		RuleInfo[] ruleInfos = getRuleInfos();
+                
 		int ruleLine = -1;
 		RuleInfo result = null;
 		for (int i = 0; i < ruleInfos.length; i++) {
@@ -107,7 +111,7 @@
 	
 	public class RuleInfo {
 		
-		private RuleDescr ruleDescr;
+		private final RuleDescr ruleDescr;
 		// cached entries
 		private transient String className;
 		private transient int consequenceJavaLineNumber = -1;
@@ -119,6 +123,10 @@
 			this.ruleDescr = ruleDescr;
 		}
 
+        public Dialect getDialect() {
+            return ruleDescr.getDialect();
+        }
+        
 		public String getSourcePathName() {
 			return DRLInfo.this.getSourcePathName();
 		}
@@ -147,8 +155,17 @@
 				if (!isCompiled()) {
 					throw new IllegalArgumentException("Package has not been compiled");
 				}
-				consequenceJavaLineNumber = compiledPackage
-					.getPackageCompilationData().getLineMappings(className).getOffset();
+				PackageCompilationData data = compiledPackage
+                					.getPackageCompilationData();
+                
+                System.out.println("Getting mappings for "+getClassName());
+                
+                LineMappings mappings = data.getLineMappings(className);
+                consequenceJavaLineNumber = mappings.getOffset();
+                
+                System.out.println("Calculated consequence Source Line Number: "+consequenceJavaLineNumber);
+                System.out.println("LINE ITSELF "+mappings.getStartLine());
+                System.out.println("DRL LINE "+getConsequenceDrlLineNumber());
 			}
 			return consequenceJavaLineNumber;
 		}

Modified: labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/debug/core/DroolsDebugModelPresentation.java
===================================================================
--- labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/debug/core/DroolsDebugModelPresentation.java	2007-06-30 21:10:06 UTC (rev 12964)
+++ labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/debug/core/DroolsDebugModelPresentation.java	2007-06-30 21:10:20 UTC (rev 12965)
@@ -1,5 +1,6 @@
 package org.drools.eclipse.debug.core;
 
+import org.eclipse.core.runtime.CoreException;
 import org.eclipse.debug.core.model.IBreakpoint;
 import org.eclipse.jdt.internal.debug.ui.JDIModelPresentation;
 
@@ -7,8 +8,16 @@
 
 	protected String getBreakpointText(IBreakpoint breakpoint) {
 		if (breakpoint instanceof DroolsLineBreakpoint) {
-			int lineNumber = ((DroolsLineBreakpoint) breakpoint).getDRLLineNumber();
-			return breakpoint.getMarker().getResource().getName() + " [line: " + lineNumber + "]";
+			DroolsLineBreakpoint breakp = ((DroolsLineBreakpoint) breakpoint);
+            int lineNumber = breakp.getDRLLineNumber();
+            int real;
+            try {
+                real = breakp.getLineNumber();
+            } catch ( CoreException e ) {
+                return breakpoint.getMarker().getResource().getName() + " [line: " + lineNumber + "] real: NA!!"; 
+            }
+            
+			return breakpoint.getMarker().getResource().getName() + " [line: " + lineNumber + "] real: "+real;
 		}
 		return super.getBreakpointText(breakpoint);
 	}

Modified: labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/debug/core/DroolsDebugTarget.java
===================================================================
--- labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/debug/core/DroolsDebugTarget.java	2007-06-30 21:10:06 UTC (rev 12964)
+++ labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/debug/core/DroolsDebugTarget.java	2007-06-30 21:10:20 UTC (rev 12965)
@@ -1,541 +1,759 @@
-package org.drools.eclipse.debug.core;
-
-import java.text.MessageFormat;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import org.drools.eclipse.DroolsEclipsePlugin;
-import org.eclipse.core.resources.IMarkerDelta;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.debug.core.DebugEvent;
-import org.eclipse.debug.core.DebugException;
-import org.eclipse.debug.core.ILaunch;
-import org.eclipse.debug.core.model.IBreakpoint;
-import org.eclipse.debug.core.model.IProcess;
-import org.eclipse.debug.core.model.IThread;
-import org.eclipse.jdi.TimeoutException;
-import org.eclipse.jdt.internal.debug.core.IJDIEventListener;
-import org.eclipse.jdt.internal.debug.core.breakpoints.JavaBreakpoint;
-import org.eclipse.jdt.internal.debug.core.model.JDIDebugModelMessages;
-import org.eclipse.jdt.internal.debug.core.model.JDIDebugTarget;
-import org.eclipse.jdt.internal.debug.core.model.JDIThread;
-
-import com.sun.jdi.ObjectCollectedException;
-import com.sun.jdi.ThreadReference;
-import com.sun.jdi.VMDisconnectedException;
-import com.sun.jdi.VirtualMachine;
-import com.sun.jdi.event.Event;
-import com.sun.jdi.event.ThreadDeathEvent;
-import com.sun.jdi.event.ThreadStartEvent;
-import com.sun.jdi.event.VMStartEvent;
-import com.sun.jdi.request.EventRequest;
-import com.sun.jdi.request.EventRequestManager;
-
-public class DroolsDebugTarget extends JDIDebugTarget {
-
-	private ArrayList fThreads;
-	private ThreadStartHandler fThreadStartHandler = null;
-	private boolean fSuspended = true;
-	
-	public DroolsDebugTarget(ILaunch launch, VirtualMachine jvm, String name, boolean supportTerminate, boolean supportDisconnect, IProcess process, boolean resume) {
-		super(launch, jvm, name, supportTerminate, supportDisconnect, process, resume);
-	}
-	
-	public void breakpointAdded(IBreakpoint breakpoint) {
-		try {
-			if (breakpoint instanceof DroolsLineBreakpoint) {
-				((DroolsLineBreakpoint) breakpoint).setJavaBreakpointProperties();
-				// only add breakpoint if setting Java properties of DRL
-				// breakpoint does not generate an error
-				super.breakpointAdded(breakpoint);
-			} else {
-				super.breakpointAdded(breakpoint);
-			}
-		} catch (Throwable t) {
-			// Exception will be thrown when trying to use breakpoint
-			// on drl that is incorrect (cannot be parsed or compiled) 
-			DroolsEclipsePlugin.log(t);
-		}
-	}
-
-	protected synchronized void initialize() {
-		setThreadList(new ArrayList(5));
-		super.initialize();
-	}
-	
-	protected JDIThread createThread(ThreadReference thread) {
-		JDIThread jdiThread= null;
-		try {
-			jdiThread= new DroolsThread(this, thread);
-		} catch (ObjectCollectedException exception) {
-			// ObjectCollectionException can be thrown if the thread has already
-			// completed (exited) in the VM.
-			return null;
-		}
-		if (isDisconnected()) {
-			return null;
-		}
-		synchronized (fThreads) {
-			fThreads.add(jdiThread);
-		}
-		jdiThread.fireCreationEvent();
-		return jdiThread;
-	}
-	
-	private Iterator getThreadIterator() {
-		List threadList;
-		synchronized (fThreads) {
-			threadList= (List) fThreads.clone();
-		}
-		return threadList.iterator();
-	}
-
-	private boolean hasSuspendedThreads() {
-		Iterator it = getThreadIterator();
-		while(it.hasNext()){
-			IThread thread = (IThread)it.next();
-			if(thread.isSuspended())
-				return true;
-		}
-		return false;
-	}
-
-	public boolean canResume() {
-		return (isSuspended() || hasSuspendedThreads())
-		    && isAvailable() && !isPerformingHotCodeReplace();
-	}
-	
-	protected void resume(boolean fireNotification) throws DebugException {
-		if ((!isSuspended() && !hasSuspendedThreads()) 
-			|| !isAvailable()) {
-			return;
-		}
-		try {
-			setSuspended(false);
-			resumeThreads();
-			VirtualMachine vm = getVM();
-			if (vm != null) {
-				vm.resume();
-			}
-			if (fireNotification) {
-				fireResumeEvent(DebugEvent.CLIENT_REQUEST);
-			}
-		} catch (VMDisconnectedException e) {
-			disconnected();
-			return;
-		} catch (RuntimeException e) {
-			setSuspended(true);
-			fireSuspendEvent(DebugEvent.CLIENT_REQUEST);
-			targetRequestFailed(MessageFormat.format(JDIDebugModelMessages.JDIDebugTarget_exception_resume, new String[] {e.toString()}), e); 
-		}	
-	}
-
-	private void setSuspended(boolean suspended) {
-		fSuspended = suspended;
-	}
-	
-	public boolean isSuspended() {
-		return fSuspended;
-	}
-	
-	private void setThreadList(ArrayList threads) {
-		fThreads = threads;
-	}
-	
-	public IThread[] getThreads() {
-		synchronized (fThreads) {
-			return (IThread[])fThreads.toArray(new IThread[0]);
-		}
-	}
-
-	protected void removeAllThreads() {
-		Iterator itr= getThreadIterator();
-		while (itr.hasNext()) {
-			DroolsThread child= (DroolsThread) itr.next();
-			child.terminated();
-		}
-		synchronized (fThreads) {
-		    fThreads.clear();
-		}
-	}
-	
-	protected void initializeRequests() {
-		setThreadStartHandler(new ThreadStartHandler());
-		new ThreadDeathHandler();		
-	}
-	
-	class ThreadDeathHandler implements IJDIEventListener {
-		
-		protected ThreadDeathHandler() {
-			createRequest();
-		}
-		
-		/**
-		 * Creates and registers a request to listen to thread
-		 * death events.
-		 */
-		protected void createRequest() {
-			EventRequestManager manager = getEventRequestManager();
-			if (manager != null) {
-				try {
-					EventRequest req= manager.createThreadDeathRequest();
-					req.setSuspendPolicy(EventRequest.SUSPEND_NONE);
-					req.enable();
-					addJDIEventListener(this, req);	
-				} catch (RuntimeException e) {
-					logError(e);
-				}					
-			}
-		}
-				
-		/**
-		 * Locates the model thread associated with the underlying JDI thread
-		 * that has terminated, and removes it from the collection of
-		 * threads belonging to this debug target. A terminate event is
-		 * fired for the model thread.
-		 *
-		 * @param event a thread death event
-		 * @param target the target in which the thread died
-		 * @return <code>true</code> - the thread should be resumed
-		 */
-		public boolean handleEvent(Event event, JDIDebugTarget target) {
-			ThreadReference ref= ((ThreadDeathEvent)event).thread();
-			DroolsThread thread= (DroolsThread) findThread(ref);
-			if (thread != null) {
-				synchronized (fThreads) {
-					fThreads.remove(thread);
-				}
-				thread.terminated();
-			}
-			return true;
-		}
-		
-		/* (non-Javadoc)
-		 * @see org.eclipse.jdt.internal.debug.core.IJDIEventListener#wonSuspendVote(com.sun.jdi.event.Event, org.eclipse.jdt.internal.debug.core.model.JDIDebugTarget)
-		 */
-		public void wonSuspendVote(Event event, JDIDebugTarget target) {
-			// do nothing
-		}
-	
-	}
-	
-	class ThreadStartHandler implements IJDIEventListener {
-		
-		protected EventRequest fRequest;
-		
-		protected ThreadStartHandler() {
-			createRequest();
-		} 
-		
-		/**
-		 * Creates and registers a request to handle all thread start
-		 * events
-		 */
-		protected void createRequest() {
-			EventRequestManager manager = getEventRequestManager();
-			if (manager != null) {			
-				try {
-					EventRequest req= manager.createThreadStartRequest();
-					req.setSuspendPolicy(EventRequest.SUSPEND_NONE);
-					req.enable();
-					addJDIEventListener(this, req);
-					setRequest(req);
-				} catch (RuntimeException e) {
-					logError(e);
-				}
-			}
-		}
-
-		/**
-		 * Creates a model thread for the underlying JDI thread
-		 * and adds it to the collection of threads for this 
-		 * debug target. As a side effect of creating the thread,
-		 * a create event is fired for the model thread.
-		 * The event is ignored if the underlying thread is already
-		 * marked as collected.
-		 * 
-		 * @param event a thread start event
-		 * @param target the target in which the thread started
-		 * @return <code>true</code> - the thread should be resumed
-		 */
-		public boolean handleEvent(Event event, JDIDebugTarget target) {
-			ThreadReference thread= ((ThreadStartEvent)event).thread();
-			try {
-				if (thread.isCollected()) {
-					return false;
-				}
-			} catch (VMDisconnectedException exception) {
-				return false;
-			} catch (ObjectCollectedException e) {
-				return false;
-			} catch (TimeoutException e) {
-				// continue - attempt to create the thread
-			}
-			DroolsThread jdiThread= (DroolsThread) findThread(thread);
-			if (jdiThread == null) {
-				jdiThread = (DroolsThread) createThread(thread);
-				if (jdiThread == null) {
-					return false;
-				}
-			} else {
-				jdiThread.disposeStackFrames();
-				jdiThread.fireChangeEvent(DebugEvent.CONTENT);
-			}
-			return !jdiThread.isSuspended();
-		}
-
-		/* (non-Javadoc)
-		 * @see org.eclipse.jdt.internal.debug.core.IJDIEventListener#wonSuspendVote(com.sun.jdi.event.Event, org.eclipse.jdt.internal.debug.core.model.JDIDebugTarget)
-		 */
-		public void wonSuspendVote(Event event, JDIDebugTarget target) {
-			// do nothing
-		}
-		
-		/**
-		 * Deregisters this event listener.
-		 */
-		protected void deleteRequest() {
-			if (getRequest() != null) {
-				removeJDIEventListener(this, getRequest());
-				setRequest(null);
-			}
-		}
-		
-		protected EventRequest getRequest() {
-			return fRequest;
-		}
-
-		protected void setRequest(EventRequest request) {
-			fRequest = request;
-		}
-	}
-	
-	private void disposeThreadHandler() {
-		ThreadStartHandler handler = getThreadStartHandler2();
-		if (handler != null) {
-			handler.deleteRequest();
-		}
-	}
-
-	public boolean hasThreads() {
-		return fThreads.size() > 0;
-	}
-	
-	protected ThreadStartHandler getThreadStartHandler2() {
-		return fThreadStartHandler;
-	}
-
-	protected void setThreadStartHandler(ThreadStartHandler threadStartHandler) {
-		fThreadStartHandler = threadStartHandler;
-	}
-	
-	public boolean isOutOfSynch() throws DebugException {
-		Iterator threads= getThreadIterator();
-		while (threads.hasNext()) {
-			JDIThread thread= (JDIThread)threads.next();
-			if (thread.isOutOfSynch()) {
-				return true;
-			}
-		}
-		return false;
-	}
-	
-	public boolean mayBeOutOfSynch() {
-		Iterator threads= getThreadIterator();
-		while (threads.hasNext()) {
-			JDIThread thread= (JDIThread)threads.next();
-			if (thread.mayBeOutOfSynch()) {
-				return true;
-			}
-		}
-		return false;
-	}
-	
-	public JDIThread findThread(ThreadReference tr) {
-		Iterator iter= getThreadIterator();
-		while (iter.hasNext()) {
-			JDIThread thread = (JDIThread) iter.next();
-			if (thread.getUnderlyingThread().equals(tr))
-				return thread;
-		}
-		return null;
-	}
-	
-	public void breakpointRemoved(IBreakpoint breakpoint, IMarkerDelta delta) {
-		if (!isAvailable()) {
-			return;
-		}		
-		if (supportsBreakpoint(breakpoint)) {
-			try {
-				((JavaBreakpoint)breakpoint).removeFromTarget(this);
-				getBreakpoints().remove(breakpoint);
-				Iterator threads = getThreadIterator();
-				while (threads.hasNext()) {
-					((DroolsThread)threads.next()).removeCurrentBreakpoint(breakpoint);
-				}
-			} catch (CoreException e) {
-				logError(e);
-			}
-		}
-	}
-
-	protected void suspendThreads() {
-		Iterator threads = getThreadIterator();
-		while (threads.hasNext()) {
-			((DroolsThread)threads.next()).suspendedByVM();
-		}
-	}
-
-	protected void resumeThreads() throws DebugException {
-		Iterator threads = getThreadIterator();
-		while (threads.hasNext()) {
-			((DroolsThread)threads.next()).resumedByVM();
-		}
-	}
-	
-	public void disconnect() throws DebugException {
-
-		if (!isAvailable()) {
-			// already done
-			return;
-		}
-
-		if (!canDisconnect()) {
-			notSupported(JDIDebugModelMessages.JDIDebugTarget_does_not_support_disconnect); 
-		}
-
-		try {
-			disposeThreadHandler();
-			VirtualMachine vm = getVM();
-			if (vm != null) {
-				vm.dispose();
-			}
-		} catch (VMDisconnectedException e) {
-			// if the VM disconnects while disconnecting, perform
-			// normal disconnect handling
-			disconnected();
-		} catch (RuntimeException e) {
-			targetRequestFailed(MessageFormat.format(JDIDebugModelMessages.JDIDebugTarget_exception_disconnecting, new String[] {e.toString()}), e); 
-		}
-
-	}
-
-	public void terminate() throws DebugException {
-		if (!isAvailable()) {
-			return;
-		}
-		if (!supportsTerminate()) {
-			notSupported(JDIDebugModelMessages.JDIDebugTarget_does_not_support_termination); 
-		}
-		try {
-			setTerminating(true);
-			disposeThreadHandler();
-			VirtualMachine vm = getVM();
-			if (vm != null) {
-				vm.exit(1);
-			}
-			IProcess process= getProcess();
-			if (process != null) {
-				process.terminate();
-			}
-		} catch (VMDisconnectedException e) {
-			// if the VM disconnects while exiting, perform 
-			// normal termination processing
-			terminated();
-		} catch (TimeoutException exception) {
-			// if there is a timeout see if the associated process is terminated
-			IProcess process = getProcess();
-			if (process != null && process.isTerminated()) {
-				terminated();
-			} else {
-				// All we can do is disconnect
-				disconnected();
-			}
-		} catch (RuntimeException e) {
-			targetRequestFailed(MessageFormat.format(JDIDebugModelMessages.JDIDebugTarget_exception_terminating, new String[] {e.toString()}), e); 
-		}
-	}
-	
-	public void handleVMStart(VMStartEvent event) {
-		if (isResumeOnStartup()) {
-			try {
-				setSuspended(true);
-				resume();
-			} catch (DebugException e) {
-				logError(e);
-			}
-		}
-		// If any threads have resumed since thread collection was initialized,
-		// update their status (avoid concurrent modification - use #getThreads())
-		IThread[] threads = getThreads();
-		for (int i = 0; i < threads.length; i++) {
-			DroolsThread thread = (DroolsThread) threads[i];
-			if (thread.isSuspended()) {
-				try {
-					boolean suspended = thread.getUnderlyingThread().isSuspended();
-					if (!suspended) {
-						thread.setRunning(true);
-						thread.fireResumeEvent(DebugEvent.CLIENT_REQUEST);
-					}
-				} catch (VMDisconnectedException e) {
-				} catch (ObjectCollectedException e){
-				} catch (RuntimeException e) {
-					logError(e);
-				}				
-			}
-		}
-	}
-	
-	protected void initializeState() {
-
-		List threads= null;
-		VirtualMachine vm = getVM();
-		if (vm != null) {
-			try {
-				threads= vm.allThreads();
-			} catch (RuntimeException e) {
-				internalError(e);
-			}
-			if (threads != null) {
-				Iterator initialThreads= threads.iterator();
-				while (initialThreads.hasNext()) {
-					createThread((ThreadReference) initialThreads.next());
-				}
-			}			
-		}
-		
-		if (isResumeOnStartup()) {
-			setSuspended(false);
-		}
-	}
-	
-	public void suspend() throws DebugException {
-		if (isSuspended()) {
-			return;
-		}
-		try {
-			VirtualMachine vm = getVM();
-			if (vm != null) {
-				vm.suspend();
-			}
-			suspendThreads();
-			setSuspended(true);
-			fireSuspendEvent(DebugEvent.CLIENT_REQUEST);
-		} catch (RuntimeException e) {
-			setSuspended(false);
-			fireResumeEvent(DebugEvent.CLIENT_REQUEST);
-			targetRequestFailed(MessageFormat.format(JDIDebugModelMessages.JDIDebugTarget_exception_suspend, new String[] {e.toString()}), e); 
-		}
-	}
-	
-	public void prepareToSuspendByBreakpoint(JavaBreakpoint breakpoint) {
-		setSuspended(true);
-		suspendThreads();
-	}
-	
-	protected void cancelSuspendByBreakpoint(JavaBreakpoint breakpoint) throws DebugException {
-		setSuspended(false);
-		resumeThreads();
-	}	
-}
+package org.drools.eclipse.debug.core;
+
+import java.text.MessageFormat;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.drools.eclipse.DroolsEclipsePlugin;
+import org.drools.rule.builder.dialect.mvel.MVELDialect;
+import org.eclipse.core.resources.IMarkerDelta;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.debug.core.DebugEvent;
+import org.eclipse.debug.core.DebugException;
+import org.eclipse.debug.core.ILaunch;
+import org.eclipse.debug.core.model.IBreakpoint;
+import org.eclipse.debug.core.model.IProcess;
+import org.eclipse.debug.core.model.IThread;
+import org.eclipse.jdi.TimeoutException;
+import org.eclipse.jdi.internal.MirrorImpl;
+import org.eclipse.jdi.internal.VirtualMachineImpl;
+import org.eclipse.jdi.internal.jdwp.JdwpCommandPacket;
+import org.eclipse.jdi.internal.jdwp.JdwpPacket;
+import org.eclipse.jdt.internal.debug.core.IJDIEventListener;
+import org.eclipse.jdt.internal.debug.core.breakpoints.JavaBreakpoint;
+import org.eclipse.jdt.internal.debug.core.breakpoints.JavaMethodEntryBreakpoint;
+import org.eclipse.jdt.internal.debug.core.model.JDIDebugModelMessages;
+import org.eclipse.jdt.internal.debug.core.model.JDIDebugTarget;
+import org.eclipse.jdt.internal.debug.core.model.JDIThread;
+
+import com.sun.jdi.AbsentInformationException;
+import com.sun.jdi.Field;
+import com.sun.jdi.ObjectCollectedException;
+import com.sun.jdi.ReferenceType;
+import com.sun.jdi.ThreadReference;
+import com.sun.jdi.VMDisconnectedException;
+import com.sun.jdi.Value;
+import com.sun.jdi.VirtualMachine;
+import com.sun.jdi.event.ClassPrepareEvent;
+import com.sun.jdi.event.Event;
+import com.sun.jdi.event.MethodEntryEvent;
+import com.sun.jdi.event.ThreadDeathEvent;
+import com.sun.jdi.event.ThreadStartEvent;
+import com.sun.jdi.event.VMStartEvent;
+import com.sun.jdi.request.ClassPrepareRequest;
+import com.sun.jdi.request.EventRequest;
+import com.sun.jdi.request.EventRequestManager;
+import com.sun.jdi.request.MethodEntryRequest;
+
+public class DroolsDebugTarget extends JDIDebugTarget {
+
+    private ArrayList fThreads;
+    private ThreadStartHandler fThreadStartHandler = null;
+    private boolean fSuspended = true;
+    
+    private List mvelBreakpoints = new ArrayList();
+    
+    public DroolsDebugTarget(ILaunch launch, VirtualMachine jvm, String name, boolean supportTerminate, boolean supportDisconnect, IProcess process, boolean resume) {
+        super(launch, jvm, name, supportTerminate, supportDisconnect, process, resume);
+        
+/*
+        JdwpCommandPacket packet = new JdwpCommandPacket(JdwpCommandPacket.E_COMPOSITE);
+        //packet.setData(data)
+        ((VirtualMachineImpl)jvm).packetSendManager().sendPacket(packet);
+        
+        ((MirrorImpl)jvm).requestVM(JdwpCommandPacket.E_COMPOSITE, data);
+    */  
+    }
+    
+    public void breakpointAdded(IBreakpoint breakpoint) {
+        try {
+            if (breakpoint instanceof DroolsLineBreakpoint) {
+                ((DroolsLineBreakpoint) breakpoint).setJavaBreakpointProperties();
+                                
+                DroolsLineBreakpoint d = (DroolsLineBreakpoint) breakpoint;
+                System.out.println("Got dialect "+d.getDialectName());
+
+                if (d.getDialectName().equals(MVELDialect.ID)) {                    
+                    System.out.println("Adding MVEL breakpoint");
+                    System.out.println("Line number "+d.getLineNumber());
+                    System.out.println("Line2nr "+d.getDRLLineNumber());
+                    //getBreakpoints().add( breakpoint );
+                    //super.breakpointAdded(breakpoint);
+                    mvelBreakpoints.add(breakpoint);
+                    
+                    System.out.println("BREAKPOINT LINE NUMBER: "+d.getLineNumber());
+                    
+                } else {
+                    System.out.println("Adding Java breakpoint");    
+                    // only add breakpoint if setting Java properties of DRL
+                    // breakpoint does not generate an error
+                    super.breakpointAdded(breakpoint);
+               }
+                
+            } else {
+                super.breakpointAdded(breakpoint);
+            }
+        } catch (Throwable t) {
+            // Exception will be thrown when trying to use breakpoint
+            // on drl that is incorrect (cannot be parsed or compiled) 
+            DroolsEclipsePlugin.log(t);
+        }
+    }
+
+    protected synchronized void initialize() {
+        setThreadList(new ArrayList(5));
+        super.initialize();
+    }
+    
+    protected JDIThread createThread(ThreadReference thread) {
+        JDIThread jdiThread= null;
+        try {
+            jdiThread= new DroolsThread(this, thread);            
+        } catch (ObjectCollectedException exception) {
+            // ObjectCollectionException can be thrown if the thread has already
+            // completed (exited) in the VM.
+            return null;
+        }
+        if (isDisconnected()) {
+            return null;
+        }
+        synchronized (fThreads) {
+            fThreads.add(jdiThread);
+        }
+        jdiThread.fireCreationEvent();
+        return jdiThread;
+    }
+    
+    private Iterator getThreadIterator() {
+        List threadList;
+        synchronized (fThreads) {
+            threadList= (List) fThreads.clone();
+        }
+        return threadList.iterator();
+    }
+
+    private boolean hasSuspendedThreads() {
+        Iterator it = getThreadIterator();
+        while(it.hasNext()){
+            IThread thread = (IThread)it.next();
+            if(thread.isSuspended())
+                return true;
+        }
+        return false;
+    }
+
+    public boolean canResume() {
+        return (isSuspended() || hasSuspendedThreads())
+            && isAvailable() && !isPerformingHotCodeReplace();
+    }
+    
+    protected void resume(boolean fireNotification) throws DebugException {
+        if ((!isSuspended() && !hasSuspendedThreads()) 
+            || !isAvailable()) {
+            return;
+        }
+        try {
+            setSuspended(false);
+            resumeThreads();
+            VirtualMachine vm = getVM();
+            if (vm != null) {
+                vm.resume();
+            }
+            if (fireNotification) {
+                fireResumeEvent(DebugEvent.CLIENT_REQUEST);
+            }
+        } catch (VMDisconnectedException e) {
+            disconnected();
+            return;
+        } catch (RuntimeException e) {
+            setSuspended(true);
+            fireSuspendEvent(DebugEvent.CLIENT_REQUEST);
+            targetRequestFailed(MessageFormat.format(JDIDebugModelMessages.JDIDebugTarget_exception_resume, new String[] {e.toString()}), e); 
+        }   
+    }
+
+    private void setSuspended(boolean suspended) {
+        fSuspended = suspended;
+    }
+    
+    public boolean isSuspended() {
+        return fSuspended;
+    }
+    
+    private void setThreadList(ArrayList threads) {
+        fThreads = threads;
+    }
+    
+    public IThread[] getThreads() {
+        synchronized (fThreads) {
+            return (IThread[])fThreads.toArray(new IThread[0]);
+        }
+    }
+
+    protected void removeAllThreads() {
+        Iterator itr= getThreadIterator();
+        while (itr.hasNext()) {
+            DroolsThread child= (DroolsThread) itr.next();
+            child.terminated();
+        }
+        synchronized (fThreads) {
+            fThreads.clear();
+        }
+    }
+    
+    protected void initializeRequests() {
+        setThreadStartHandler(new ThreadStartHandler());
+        new ThreadDeathHandler();       
+        new MVELTraceHandler();
+    }
+    
+    class ThreadDeathHandler implements IJDIEventListener {
+        
+        protected ThreadDeathHandler() {
+            createRequest();
+        }
+        
+        /**
+         * Creates and registers a request to listen to thread
+         * death events.
+         */
+        protected void createRequest() {
+            EventRequestManager manager = getEventRequestManager();
+            if (manager != null) {
+                try {
+                    EventRequest req= manager.createThreadDeathRequest();
+                    req.setSuspendPolicy(EventRequest.SUSPEND_NONE);
+                    req.enable();
+                    addJDIEventListener(this, req); 
+                } catch (RuntimeException e) {
+                    logError(e);
+                }                   
+            }
+        }
+                
+        /**
+         * Locates the model thread associated with the underlying JDI thread
+         * that has terminated, and removes it from the collection of
+         * threads belonging to this debug target. A terminate event is
+         * fired for the model thread.
+         *
+         * @param event a thread death event
+         * @param target the target in which the thread died
+         * @return <code>true</code> - the thread should be resumed
+         */
+        public boolean handleEvent(Event event, JDIDebugTarget target) {
+            ThreadReference ref= ((ThreadDeathEvent)event).thread();
+            DroolsThread thread= (DroolsThread) findThread(ref);
+            if (thread != null) {
+                synchronized (fThreads) {
+                    fThreads.remove(thread);
+                }
+                thread.terminated();
+            }
+            return true;
+        }
+        
+        /* (non-Javadoc)
+         * @see org.eclipse.jdt.internal.debug.core.IJDIEventListener#wonSuspendVote(com.sun.jdi.event.Event, org.eclipse.jdt.internal.debug.core.model.JDIDebugTarget)
+         */
+        public void wonSuspendVote(Event event, JDIDebugTarget target) {
+            // do nothing
+        }
+    
+    }
+    
+    class ThreadStartHandler implements IJDIEventListener {
+        
+        protected EventRequest fRequest;
+        
+        protected ThreadStartHandler() {
+            createRequest();
+        } 
+        
+        /**
+         * Creates and registers a request to handle all thread start
+         * events
+         */
+        protected void createRequest() {
+            EventRequestManager manager = getEventRequestManager();
+            if (manager != null) {          
+                try {
+                    EventRequest req= manager.createThreadStartRequest();
+                    req.setSuspendPolicy(EventRequest.SUSPEND_NONE);
+                    req.enable();
+                    addJDIEventListener(this, req);
+                    setRequest(req);
+                } catch (RuntimeException e) {
+                    logError(e);
+                }
+            }
+        }
+
+        /**
+         * Creates a model thread for the underlying JDI thread
+         * and adds it to the collection of threads for this 
+         * debug target. As a side effect of creating the thread,
+         * a create event is fired for the model thread.
+         * The event is ignored if the underlying thread is already
+         * marked as collected.
+         * 
+         * @param event a thread start event
+         * @param target the target in which the thread started
+         * @return <code>true</code> - the thread should be resumed
+         */
+        public boolean handleEvent(Event event, JDIDebugTarget target) {
+            ThreadReference thread= ((ThreadStartEvent)event).thread();
+            try {
+                if (thread.isCollected()) {
+                    return false;
+                }
+            } catch (VMDisconnectedException exception) {
+                return false;
+            } catch (ObjectCollectedException e) {
+                return false;
+            } catch (TimeoutException e) {
+                // continue - attempt to create the thread
+            }
+            DroolsThread jdiThread= (DroolsThread) findThread(thread);
+            if (jdiThread == null) {
+                jdiThread = (DroolsThread) createThread(thread);
+                if (jdiThread == null) {
+                    return false;
+                }
+            } else {
+                jdiThread.disposeStackFrames();
+                jdiThread.fireChangeEvent(DebugEvent.CONTENT);
+            }
+            return !jdiThread.isSuspended();
+        }
+
+        /* (non-Javadoc)
+         * @see org.eclipse.jdt.internal.debug.core.IJDIEventListener#wonSuspendVote(com.sun.jdi.event.Event, org.eclipse.jdt.internal.debug.core.model.JDIDebugTarget)
+         */
+        public void wonSuspendVote(Event event, JDIDebugTarget target) {
+            // do nothing
+        }
+        
+        /**
+         * Deregisters this event listener.
+         */
+        protected void deleteRequest() {
+            if (getRequest() != null) {
+                removeJDIEventListener(this, getRequest());
+                setRequest(null);
+            }
+        }
+        
+        protected EventRequest getRequest() {
+            return fRequest;
+        }
+
+        protected void setRequest(EventRequest request) {
+            fRequest = request;
+        }
+    }
+    
+    private void disposeThreadHandler() {
+        ThreadStartHandler handler = getThreadStartHandler2();
+        if (handler != null) {
+            handler.deleteRequest();
+        }
+    }
+
+    public boolean hasThreads() {
+        return fThreads.size() > 0;
+    }
+    
+    protected ThreadStartHandler getThreadStartHandler2() {
+        return fThreadStartHandler;
+    }
+
+    protected void setThreadStartHandler(ThreadStartHandler threadStartHandler) {
+        fThreadStartHandler = threadStartHandler;
+    }
+    
+    public boolean isOutOfSynch() throws DebugException {
+        Iterator threads= getThreadIterator();
+        while (threads.hasNext()) {
+            JDIThread thread= (JDIThread)threads.next();
+            if (thread.isOutOfSynch()) {
+                return true;
+            }
+        }
+        return false;
+    }
+    
+    public boolean mayBeOutOfSynch() {
+        Iterator threads= getThreadIterator();
+        while (threads.hasNext()) {
+            JDIThread thread= (JDIThread)threads.next();
+            if (thread.mayBeOutOfSynch()) {
+                return true;
+            }
+        }
+        return false;
+    }
+    
+    public JDIThread findThread(ThreadReference tr) {
+        Iterator iter= getThreadIterator();
+        while (iter.hasNext()) {
+            JDIThread thread = (JDIThread) iter.next();
+            if (thread.getUnderlyingThread().equals(tr))
+                return thread;
+        }
+        return null;
+    }
+    
+    public void breakpointRemoved(IBreakpoint breakpoint, IMarkerDelta delta) {
+        if (!isAvailable()) {
+            return;
+        }       
+        if (supportsBreakpoint(breakpoint)) {
+            try {
+                ((JavaBreakpoint)breakpoint).removeFromTarget(this);
+                getBreakpoints().remove(breakpoint);
+                Iterator threads = getThreadIterator();
+                while (threads.hasNext()) {
+                    ((DroolsThread)threads.next()).removeCurrentBreakpoint(breakpoint);
+                }
+            } catch (CoreException e) {
+                logError(e);
+            }
+        }
+    }
+
+    protected void suspendThreads() {
+        Iterator threads = getThreadIterator();
+        while (threads.hasNext()) {
+            ((DroolsThread)threads.next()).suspendedByVM();
+        }
+    }
+
+    protected void resumeThreads() throws DebugException {
+        Iterator threads = getThreadIterator();
+        while (threads.hasNext()) {
+            ((DroolsThread)threads.next()).resumedByVM();
+        }
+    }
+    
+    public void disconnect() throws DebugException {
+
+        if (!isAvailable()) {
+            // already done
+            return;
+        }
+
+        if (!canDisconnect()) {
+            notSupported(JDIDebugModelMessages.JDIDebugTarget_does_not_support_disconnect); 
+        }
+
+        try {
+            disposeThreadHandler();
+            VirtualMachine vm = getVM();
+            if (vm != null) {
+                vm.dispose();
+            }
+        } catch (VMDisconnectedException e) {
+            // if the VM disconnects while disconnecting, perform
+            // normal disconnect handling
+            disconnected();
+        } catch (RuntimeException e) {
+            targetRequestFailed(MessageFormat.format(JDIDebugModelMessages.JDIDebugTarget_exception_disconnecting, new String[] {e.toString()}), e); 
+        }
+
+    }
+
+    public void terminate() throws DebugException {
+        if (!isAvailable()) {
+            return;
+        }
+        if (!supportsTerminate()) {
+            notSupported(JDIDebugModelMessages.JDIDebugTarget_does_not_support_termination); 
+        }
+        try {
+            setTerminating(true);
+            disposeThreadHandler();
+            VirtualMachine vm = getVM();
+            if (vm != null) {
+                vm.exit(1);
+            }
+            IProcess process= getProcess();
+            if (process != null) {
+                process.terminate();
+            }
+        } catch (VMDisconnectedException e) {
+            // if the VM disconnects while exiting, perform 
+            // normal termination processing
+            terminated();
+        } catch (TimeoutException exception) {
+            // if there is a timeout see if the associated process is terminated
+            IProcess process = getProcess();
+            if (process != null && process.isTerminated()) {
+                terminated();
+            } else {
+                // All we can do is disconnect
+                disconnected();
+            }
+        } catch (RuntimeException e) {
+            targetRequestFailed(MessageFormat.format(JDIDebugModelMessages.JDIDebugTarget_exception_terminating, new String[] {e.toString()}), e); 
+        }
+    }
+    
+    public void handleVMStart(VMStartEvent event) {
+        if (isResumeOnStartup()) {
+            try {
+                setSuspended(true);
+                resume();
+            } catch (DebugException e) {
+                logError(e);
+            }
+        }
+        // If any threads have resumed since thread collection was initialized,
+        // update their status (avoid concurrent modification - use #getThreads())
+        IThread[] threads = getThreads();
+        for (int i = 0; i < threads.length; i++) {
+            DroolsThread thread = (DroolsThread) threads[i];
+            if (thread.isSuspended()) {
+                try {
+                    boolean suspended = thread.getUnderlyingThread().isSuspended();
+                    if (!suspended) {
+                        thread.setRunning(true);
+                        thread.fireResumeEvent(DebugEvent.CLIENT_REQUEST);
+                    }
+                } catch (VMDisconnectedException e) {
+                } catch (ObjectCollectedException e){
+                } catch (RuntimeException e) {
+                    logError(e);
+                }               
+            }
+        }
+    }
+    
+    protected void initializeState() {
+
+        List threads= null;
+        VirtualMachine vm = getVM();
+        if (vm != null) {
+            try {
+                threads= vm.allThreads();
+            } catch (RuntimeException e) {
+                internalError(e);
+            }
+            if (threads != null) {
+                Iterator initialThreads= threads.iterator();
+                while (initialThreads.hasNext()) {
+                    createThread((ThreadReference) initialThreads.next());
+                }
+            }           
+        }
+        
+        if (isResumeOnStartup()) {
+            setSuspended(false);
+        }
+    }
+    
+    public void suspend() throws DebugException {
+        if (isSuspended()) {
+            return;
+        }
+        try {
+            VirtualMachine vm = getVM();
+            if (vm != null) {
+                vm.suspend();
+            }
+            suspendThreads();
+            setSuspended(true);
+            fireSuspendEvent(DebugEvent.CLIENT_REQUEST);
+        } catch (RuntimeException e) {
+            setSuspended(false);
+            fireResumeEvent(DebugEvent.CLIENT_REQUEST);
+            targetRequestFailed(MessageFormat.format(JDIDebugModelMessages.JDIDebugTarget_exception_suspend, new String[] {e.toString()}), e); 
+        }
+    }
+    
+    public void prepareToSuspendByBreakpoint(JavaBreakpoint breakpoint) {
+        setSuspended(true);
+        suspendThreads();
+    }
+    
+    protected void cancelSuspendByBreakpoint(JavaBreakpoint breakpoint) throws DebugException {
+        setSuspended(false);
+        resumeThreads();
+    }   
+
+    class MVELTraceHandler implements IJDIEventListener {
+        
+        protected MVELTraceHandler() {
+            createRequest();
+        }
+        
+        /**
+         * Creates and registers a request to listen to thread
+         * death events.
+         */
+        protected void createRequest() {
+            EventRequestManager manager = getEventRequestManager();
+            if (manager != null) {
+                try {
+/*                    String className = "com.sample.DroolsTest";
+                    
+                    List list = getVM().classesByName(className);
+                    List alllist = getVM().allClasses();
+                    
+                    System.out.println("Number of classes "+alllist.size());
+                    System.out.println("they are:");
+                    
+                    Iterator iter = alllist.iterator();
+                    while (iter.hasNext()) {
+                        Object o = (Object) iter.next();
+                        System.out.println("allclass: "+o);
+                    }
+                
+                    System.out.println("Found classes "+list.size());
+                    if (list.size()>0) {
+                        System.out.println(". first "+iter.next());
+                    }
+*/
+                    ClassPrepareRequest req= manager.createClassPrepareRequest();
+                    req.addClassFilter("org.drools.base.mvel.MVELDebugHandler");
+                    req.setSuspendPolicy(EventRequest.SUSPEND_ALL);
+                    req.enable();
+                    addJDIEventListener(MVELTraceHandler.this, req); 
+                    
+                } catch (RuntimeException e) {
+                    logError(e);
+                }                   
+            }
+        }
+                
+        /**
+         * Locates the model thread associated with the underlying JDI thread
+         * that has terminated, and removes it from the collection of
+         * threads belonging to this debug target. A terminate event is
+         * fired for the model thread.
+         *
+         * @param event a thread death event
+         * @param target the target in which the thread died
+         * @return <code>true</code> - the thread should be resumed
+         */
+        public boolean handleEvent(Event event, JDIDebugTarget target) {
+            String name = ((ClassPrepareEvent)event).referenceType().name();
+            System.out.println("LOADING "+name);
+
+            System.out.println( "dialect class loaded: " + name );
+
+            MethodEntryRequest req = getEventRequestManager().createMethodEntryRequest();
+            req.addClassFilter( ((ClassPrepareEvent) event).referenceType() );
+
+            //breakpointCatched
+
+            /*field= type.fieldByName(getFieldName());
+             Field field;
+             EventRequest req= manager.createModificationWatchpointRequest(field);
+             */
+            req.setSuspendPolicy( EventRequest.SUSPEND_ALL );
+            req.enable();
+
+            addJDIEventListener( new IJDIEventListener() {
+
+                                     public boolean handleEvent(Event event,
+                                                                JDIDebugTarget target) {
+                                         MethodEntryEvent entryEvent = (MethodEntryEvent) event;
+
+                                         String name2 = entryEvent.method().name();
+                                         System.out.println( "Got MVELConsequence call for " + name2 );
+
+                                         if ( !name2.equals("onBreak" ) && !name2.equals( "receiveBreakpoints" )) {
+                                             System.out.println( "Wrong method, resuming" );
+                                             //event.virtualMachine().resume();
+                                             return true;
+                                         }
+
+                                         System.out.println("Suspending threads");
+     
+                                         JDIThread thr = findThread( entryEvent.thread() );
+                                         try {
+                                            thr.suspend();
+                                        } catch ( DebugException e ) {
+                                            // TODO Auto-generated catch block
+                                            e.printStackTrace();
+                                        }
+                                         
+                                         System.out.println("Thread is "+entryEvent.thread().getClass());
+                                         if (thr instanceof DroolsThread) {
+                                             System.out.println("Drools Thread!!");
+                                             ((DroolsThread)thr).suspendedByVM();
+                                         }
+                                         //suspendThreads();
+                                         //suspendedByBreakpoint( null, false);
+                                         
+                                         
+
+/*                                         try {
+                                            suspend();
+                                        } catch ( DebugException e ) {
+                                            // TODO Auto-generated catch block
+                                            e.printStackTrace();
+                                        }
+*/                                         System.out.println( "Stopping thread, inspecting remote vars" );
+
+/*                                         ReferenceType declaringType = entryEvent.location().declaringType();
+                                         Field varsField = declaringType.fieldByName( "frameLocalVars" );
+                                         
+                                         System.out.println("Field is "+varsField);
+                                         
+                                         Value value = declaringType.getValue( varsField );
+                                         
+                                         System.out.println( "Got Value: " + value );
+*/
+                                         return true;
+
+                                     }
+
+                                     public void wonSuspendVote(Event event,
+                                                                JDIDebugTarget target) {
+                                         // TODO Auto-generated method stub
+
+                                     }
+
+                                 },
+                                 req );    
+
+
+            //getVM().resume();
+/*          try {
+                resumeThreads();
+            } catch (DebugException e) {
+                // TODO Auto-generated catch block
+                e.printStackTrace();
+            }
+*/          
+/*          try {
+                String path = ((MethodEntryEvent)event).location().sourcePath();
+                if (path.startsWith("org.drools")) {
+                    System.out.println("Path "+path);
+                }
+            } catch (AbsentInformationException e) {
+                // TODO Auto-generated catch block
+                e.printStackTrace();
+            }
+*/          
+            //System.out.println("WOW! Got entry! "+method);
+            return true;
+        }
+        
+        /* (non-Javadoc)
+         * @see org.eclipse.jdt.internal.debug.core.IJDIEventListener#wonSuspendVote(com.sun.jdi.event.Event, org.eclipse.jdt.internal.debug.core.model.JDIDebugTarget)
+         */
+        public void wonSuspendVote(Event event, JDIDebugTarget target) {
+            // do nothing
+        }
+    
+    }
+
+    public Object getFirstDroolsBreakpoint() {
+        return mvelBreakpoints.iterator().next();
+    }
+    
+}

Modified: labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/debug/core/DroolsLineBreakpoint.java
===================================================================
--- labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/debug/core/DroolsLineBreakpoint.java	2007-06-30 21:10:06 UTC (rev 12964)
+++ labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/debug/core/DroolsLineBreakpoint.java	2007-06-30 21:10:20 UTC (rev 12965)
@@ -15,96 +15,152 @@
 import org.eclipse.jdt.internal.debug.core.breakpoints.JavaLineBreakpoint;
 
 public class DroolsLineBreakpoint extends JavaLineBreakpoint {
-	
-	/**
-	 * Default constructor is required for the breakpoint manager
-	 * to re-create persisted breakpoints. After instantiating a breakpoint,
-	 * the <code>setMarker(...)</code> method is called to restore
-	 * this breakpoint's attributes.
-	 */
-	public DroolsLineBreakpoint() {
-	}
-	
-	/**
-	 * Constructs a line breakpoint on the given resource at the given
-	 * line number.
-	 * 
-	 * @param resource file on which to set the breakpoint
-	 * @param lineNumber line number of the breakpoint
-	 * @throws CoreException if unable to create the breakpoint
-	 */
-	public DroolsLineBreakpoint(IResource resource, int lineNumber)
-			throws CoreException {
-   		super(resource, "", -1,  -1, -1, 0, true, 
-			createAttributesMap(lineNumber), IDroolsDebugConstants.DROOLS_MARKER_TYPE);
-	}
-	
-	private static Map createAttributesMap(int lineNumber) {
-		Map map = new HashMap();
-		map.put(IDroolsDebugConstants.DRL_LINE_NUMBER, new Integer(lineNumber));
-		return map;
-	}
-	
-	public int getDRLLineNumber() {
-		return getMarker().getAttribute(IDroolsDebugConstants.DRL_LINE_NUMBER, -1);
-	}
-	
-	public String getModelIdentifier() {
-		return IDroolsDebugConstants.ID_DROOLS_DEBUG_MODEL;
-	}
-	
-	public void setJavaBreakpointProperties() throws CoreException {
-		IMarker marker = getMarker();
-		int drlLineNumber = getDRLLineNumber();
-		if (marker.exists()) {
-			marker.setAttribute(TYPE_NAME, getRuleClassName(marker.getResource(), drlLineNumber));
-			marker.setAttribute(IMarker.LINE_NUMBER, getRuleLineNumber(getMarker().getResource(), drlLineNumber));
-		}
-	}
-	
-	private String getRuleClassName(IResource resource, int lineNumber) throws CoreException {
-		try {
-			DRLInfo drlInfo = DroolsEclipsePlugin.getDefault().parseResource(resource, true);
-			if (drlInfo != null) {
-				RuleInfo ruleInfo = drlInfo.getRuleInfo(lineNumber);
-				if (ruleInfo != null) {
-					return ruleInfo.getClassName();
-				}
-				FunctionInfo functionInfo = drlInfo.getFunctionInfo(lineNumber);
-				if (functionInfo != null) {
-					return functionInfo.getClassName();
-				}
-			}
-			throw new CoreException(new Status(IStatus.ERROR, DroolsEclipsePlugin.getUniqueIdentifier(), 0,
-				"Cannot determine ruleClassName for " + resource + " " + lineNumber, null));
-		} catch (Throwable t) {
-			throw new CoreException(new Status(IStatus.ERROR, DroolsEclipsePlugin.getUniqueIdentifier(), 0,
-				"Cannot determine ruleClassName for " + resource + " " + lineNumber, t));
-		}
-	}
-	
-	private int getRuleLineNumber(IResource resource, int lineNumber) throws CoreException {
-		try {
-			DRLInfo drlInfo = DroolsEclipsePlugin.getDefault().parseResource(resource, true);
-			if (drlInfo != null) {
-				RuleInfo ruleInfo = drlInfo.getRuleInfo(lineNumber);
-				if (ruleInfo != null) {
-					if (ruleInfo.getConsequenceDrlLineNumber() < lineNumber) {
-						return ruleInfo.getConsequenceJavaLineNumber()
-							+ (lineNumber - ruleInfo.getConsequenceDrlLineNumber() + 1);
-					}
-				}
-				FunctionInfo functionInfo = drlInfo.getFunctionInfo(lineNumber);
-				if (functionInfo != null) {
-					return functionInfo.getJavaLineNumber()
-						+ (lineNumber - functionInfo.getDrlLineNumber());
-				}
-			}
-			throw new CoreException(new Status(IStatus.ERROR, DroolsEclipsePlugin.getUniqueIdentifier(), 0,
-				"Cannot determine ruleLineNumber for " + resource + " " + lineNumber, null));
-		} catch(Throwable t) {
-			throw new CoreException(new Status(IStatus.ERROR, DroolsEclipsePlugin.getUniqueIdentifier(), 0,
-				"Cannot determine ruleLineNumber for " + resource + " " + lineNumber, t));
-		}
-	}
+
+    private static final String DIALECT = "org.drools.eclipse.debug.core.breakpointDialect";
+
+
+    /**
+     * Default constructor is required for the breakpoint manager
+     * to re-create persisted breakpoints. After instantiating a breakpoint,
+     * the <code>setMarker(...)</code> method is called to restore
+     * this breakpoint's attributes.
+     */
+    public DroolsLineBreakpoint() {
+        super();
+    }
+
+    /**
+     * Constructs a line breakpoint on the given resource at the given
+     * line number.
+     * 
+     * @param resource file on which to set the breakpoint
+     * @param lineNumber line number of the breakpoint
+     * @throws CoreException if unable to create the breakpoint
+     */
+    public DroolsLineBreakpoint(IResource resource,
+                                int lineNumber) throws CoreException {
+        super( resource,
+               "",
+               -1,
+               -1,
+               -1,
+               0,
+               true,
+               createAttributesMap( lineNumber ),
+               IDroolsDebugConstants.DROOLS_MARKER_TYPE );
+        setJavaBreakpointProperties();
+    }
+
+    private static Map createAttributesMap(int lineNumber) {
+        Map map = new HashMap();
+        map.put( IDroolsDebugConstants.DRL_LINE_NUMBER,
+                 new Integer( lineNumber ) );
+        return map;
+    }
+
+    public int getDRLLineNumber() {
+        return getMarker().getAttribute( IDroolsDebugConstants.DRL_LINE_NUMBER,
+                                         -1 );
+    }
+
+    public String getModelIdentifier() {
+        return IDroolsDebugConstants.ID_DROOLS_DEBUG_MODEL;
+    }
+
+    public String getDialectName() {
+        return getMarker().getAttribute( DIALECT,
+                                         "Unknown");
+    }
+    
+    public void setJavaBreakpointProperties() throws CoreException {
+        IMarker marker = getMarker();
+        int drlLineNumber = getDRLLineNumber();
+        if ( marker.exists() ) {
+            try {
+
+                DRLInfo drlInfo = DroolsEclipsePlugin.getDefault().parseResource( marker.getResource(),
+                                                                                  true );
+
+                marker.setAttribute( TYPE_NAME,
+                                     getRuleClassName( drlInfo,
+                                                       marker.getResource().toString(),
+                                                       drlLineNumber ) );
+                marker.setAttribute( IMarker.LINE_NUMBER,
+                                     getRuleLineNumber( drlInfo,
+                                                        marker.getResource().toString(),
+                                                        drlLineNumber ) );
+                marker.setAttribute( DIALECT,
+                                     getDialect( drlInfo,
+                                                 drlLineNumber ) );
+
+            } catch ( Throwable t ) {
+                throw new CoreException( new Status( IStatus.ERROR,
+                                                     DroolsEclipsePlugin.getUniqueIdentifier(),
+                                                     0,
+                                                     "Cannot determine ruleInfo " + marker.getResource() + " " + drlLineNumber,
+                                                     t ) );
+            }
+
+        }
+    }
+
+    private String getDialect(DRLInfo info,
+                              int drlLineNumber) {
+
+        if ( info != null ) {
+            return info.getRuleInfo( drlLineNumber ).getDialect().getId();
+        }
+        
+        return null;
+    }
+
+    private String getRuleClassName(DRLInfo drlInfo,
+                                    String resource,
+                                    int lineNumber) throws CoreException {
+
+        if ( drlInfo != null ) {
+            RuleInfo ruleInfo = drlInfo.getRuleInfo( lineNumber );
+            if ( ruleInfo != null ) {
+                return ruleInfo.getClassName();
+            }
+            FunctionInfo functionInfo = drlInfo.getFunctionInfo( lineNumber );
+            if ( functionInfo != null ) {
+                return functionInfo.getClassName();
+            }
+        }
+        throw new CoreException( new Status( IStatus.ERROR,
+                                             DroolsEclipsePlugin.getUniqueIdentifier(),
+                                             0,
+                                             "Cannot determine ruleClassName for " + resource + " " + lineNumber,
+                                             null ) );
+    }
+
+    private int getRuleLineNumber(DRLInfo drlInfo,
+                                  String resource,
+                                  int lineNumber) throws CoreException {
+
+        if ( drlInfo != null ) {
+            RuleInfo ruleInfo = drlInfo.getRuleInfo( lineNumber );
+
+            if ( ruleInfo != null ) {
+                if ( ruleInfo.getConsequenceDrlLineNumber() < lineNumber ) {
+                    return ruleInfo.getConsequenceJavaLineNumber() + (lineNumber - ruleInfo.getConsequenceDrlLineNumber() + 1);
+                }
+            }
+            FunctionInfo functionInfo = drlInfo.getFunctionInfo( lineNumber );
+            if ( functionInfo != null ) {
+                return functionInfo.getJavaLineNumber() + (lineNumber - functionInfo.getDrlLineNumber());
+            }
+        }
+        throw new CoreException( new Status( IStatus.ERROR,
+                                             DroolsEclipsePlugin.getUniqueIdentifier(),
+                                             0,
+                                             "Cannot determine ruleLineNumber for " + resource + " " + lineNumber,
+                                             null ) );
+    }
+/*
+    public void setMarker(IMarker marker) throws CoreException {
+        super.setMarker( marker );
+        setJavaBreakpointProperties();
+    }*/
 }
\ No newline at end of file

Modified: labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/debug/core/DroolsStackFrame.java
===================================================================
--- labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/debug/core/DroolsStackFrame.java	2007-06-30 21:10:06 UTC (rev 12964)
+++ labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/debug/core/DroolsStackFrame.java	2007-06-30 21:10:20 UTC (rev 12965)
@@ -74,10 +74,13 @@
 			String methodName = getMethodName();
 			String signature = getSignature();
 			String type = getDeclaringTypeName();
-			if ("consequence".equals(methodName) && signature.startsWith(CONSEQUENCE_SIGNATURE)) {
+            System.out.println("Getting EXECUTING RULE INFO: type="+type+" methodName="+methodName+" signature"+signature);
+                        
+            if ("consequence".equals(methodName) && signature.startsWith(CONSEQUENCE_SIGNATURE)) {
 				return DroolsEclipsePlugin.getDefault().getRuleInfoByClass(type);
 			}
-		} catch (DebugException exc) {
+            
+            } catch (DebugException exc) {
 			DroolsEclipsePlugin.log(exc);
 		}
 		return null;
@@ -97,13 +100,16 @@
 		synchronized (fThread) {
 			RuleInfo ruleInfo = getExecutingRuleInfo();
 			if (ruleInfo != null) {
-				return ruleInfo.getConsequenceDrlLineNumber() + (getInternalLineNumber() - ruleInfo.getConsequenceJavaLineNumber() - 1);
+                
+				int ruleline = ruleInfo.getConsequenceDrlLineNumber() + (getInternalLineNumber() - ruleInfo.getConsequenceJavaLineNumber() - 1);
+                return ruleline;
 			}
 			FunctionInfo functionInfo = getExecutingFunctionInfo();
 			if (functionInfo != null) {
 				return functionInfo.getDrlLineNumber() + (getInternalLineNumber() - functionInfo.getJavaLineNumber());
 			}
 		}
+        
 		return getInternalLineNumber();
 	}
 	
@@ -197,46 +203,53 @@
 		}
 	}
 	
-	protected JDIStackFrame bind(StackFrame frame, int depth) {
-		if (initialized) {
-			synchronized (fThread) {
-				if (fDepth == -2) {
-					// first initialization
-					fStackFrame = frame;
-					fDepth = depth;
-					fLocation = frame.location();
-					return this;
-				} else if (depth == -1) {
-					// mark as invalid
-					fDepth = -1;
-					fStackFrame = null;
-					return null;
-				} else if (fDepth == depth) {
-					Location location = frame.location();
-					Method method = location.method();
-					if (method.equals(fLocation.method())) {
-						try {
-							if (method.declaringType().defaultStratum().equals("Java") || //$NON-NLS-1$
-							    equals(getSourceName(location), getSourceName(fLocation))) {
-								// TODO: what about receiving type being the same?
-								fStackFrame = frame;
-								fLocation = location;
-								clearCachedData();
-								return this;
-							}
-						} catch (DebugException e) {
-						}
-					}
-				}
-				// invalidate this franme
-				bind(null, -1);
-				// return a new frame
-				return new DroolsStackFrame(fThread, frame, depth);
-			}
-		} else {
-			return null;
-		}
-	}
+    protected JDIStackFrame bind(StackFrame frame, int depth) {
+        if (initialized) {
+            synchronized (fThread) {
+                if (fDepth == -2) {
+                    // first initialization
+                    fStackFrame = frame;
+                    fDepth = depth;
+                    fLocation = frame.location();
+                    return this;
+                } else if (depth == -1) {
+                    // mark as invalid
+                    fDepth = -1;
+                    fStackFrame = null;
+                    return null;
+                } else if (fDepth == depth) {
+                    Location location = frame.location();
+                    Method method = location.method();
+                    if (method.equals(fLocation.method())) {
+                        try {
+                            if (method.declaringType().defaultStratum().equals("Java") || //$NON-NLS-1$
+                                equals(getSourceName(location), getSourceName(fLocation))) {
+                                // TODO: what about receiving type being the same?
+                                fStackFrame = frame;
+                                fLocation = location;
+                                clearCachedData();
+                                return this;
+                            }
+                        } catch (DebugException e) {
+                        }
+                    }
+                }
+                // invalidate this frame
+                bind(null, -1);
+                // return a new frame
+                return createNewDroolsFrame( frame,
+                                      depth );
+            }
+        } else {
+            return null;
+        }
+    }
+
+    protected DroolsStackFrame createNewDroolsFrame(StackFrame frame,
+                                                  int depth) {
+        return new DroolsStackFrame(fThread, frame, depth);
+    }
+    
 	
 	public IThread getThread() {
 		return fThread;
@@ -569,4 +582,5 @@
 		return locals;
 	}
 	
+
 }

Modified: labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/debug/core/DroolsThread.java
===================================================================
--- labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/debug/core/DroolsThread.java	2007-06-30 21:10:06 UTC (rev 12964)
+++ labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/debug/core/DroolsThread.java	2007-06-30 21:10:20 UTC (rev 12965)
@@ -15,8 +15,10 @@
 import org.eclipse.jdt.internal.debug.core.model.JDIDebugTarget;
 import org.eclipse.jdt.internal.debug.core.model.JDIThread;
 
+import com.sun.jdi.AbsentInformationException;
 import com.sun.jdi.IncompatibleThreadStateException;
 import com.sun.jdi.InvalidStackFrameException;
+import com.sun.jdi.Location;
 import com.sun.jdi.ObjectCollectedException;
 import com.sun.jdi.StackFrame;
 import com.sun.jdi.ThreadReference;
@@ -55,7 +57,25 @@
 				int newFrames = newSize - oldSize; // number of frames to create, if any
 				int depth = oldSize;
 				for (int i = newFrames - 1; i >= 0; i--) {
-					fStackFrames.add(0, new DroolsStackFrame(this, (StackFrame) frames.get(i), depth));
+				    
+                    StackFrame currentFrame = (StackFrame) frames.get(i);
+                    
+                    Location loc = currentFrame.location();
+
+                    if ( loc.declaringType().name().equals( "org.drools.rule.builder.dialect.mvel.MVELDebugger" ) && loc.method().name().equals( "fireBreakpoint" ) ) {
+
+                        fStackFrames.add( 0,
+                                          new MVELStackFrame( this,
+                                                              currentFrame,
+                                                              depth ) );
+
+                    } else {
+                        fStackFrames.add( 0,
+                                          new DroolsStackFrame( this,
+                                                                currentFrame,
+                                                                depth ) );
+                    }
+                    
 					depth++;
 				}
 				int numToRebind = Math.min(newSize, oldSize); // number of frames to attempt to rebind

Added: labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/debug/core/MVELStackFrame.java
===================================================================
--- labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/debug/core/MVELStackFrame.java	                        (rev 0)
+++ labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/debug/core/MVELStackFrame.java	2007-06-30 21:10:20 UTC (rev 12965)
@@ -0,0 +1,202 @@
+package org.drools.eclipse.debug.core;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.drools.eclipse.DRLInfo;
+import org.drools.eclipse.DroolsEclipsePlugin;
+import org.drools.eclipse.DRLInfo.RuleInfo;
+import org.eclipse.debug.core.DebugException;
+import org.eclipse.debug.core.model.IVariable;
+import org.eclipse.debug.internal.core.WatchExpression;
+import org.eclipse.jdi.internal.ObjectReferenceImpl;
+import org.eclipse.jdt.internal.debug.core.model.JDIDebugTarget;
+import org.eclipse.jdt.internal.debug.core.model.JDIFieldVariable;
+import org.eclipse.jdt.internal.debug.core.model.JDILocalVariable;
+import org.eclipse.jdt.internal.debug.core.model.JDIObjectValue;
+import org.eclipse.jdt.internal.debug.core.model.JDIThisVariable;
+
+import com.sun.jdi.Field;
+import com.sun.jdi.Method;
+import com.sun.jdi.ObjectReference;
+import com.sun.jdi.ReferenceType;
+import com.sun.jdi.StackFrame;
+import com.sun.jdi.ThreadReference;
+import com.sun.jdi.Value;
+
+public class MVELStackFrame extends DroolsStackFrame {
+
+    public MVELStackFrame(DroolsThread thread,
+                          StackFrame frame,
+                          int depth) {
+        super( thread,
+               frame,
+               depth );
+        System.out.println( "MVELStackFrame created for depth " + depth + " thread=" + thread );
+
+    }
+
+    public IVariable[] getVariables() throws DebugException {
+        /*        IVariable[] variables = super.getVariables();
+         List result = new ArrayList((variables.length - 1)/2);
+         for (int i = 0; i < variables.length; i++) {
+         String name = variables[i].getName();
+         if (!(name.equals("drools")) && !(name.endsWith("__Handle__"))) {
+         result.add(variables[i]);
+         }
+         }
+         */
+
+        List result = new ArrayList( 0 );
+
+        Method method = getUnderlyingMethod();
+        //System.out.println("Underlying method is "+method.name());
+        ReferenceType type = method.declaringType();
+        //System.out.println("Declaring type is "+type.name());
+
+        ;
+
+        /*        ReferenceType declaringType = .location().declaringType();
+         
+         Field varsField = declaringType.fieldByName("frameLocalVars");
+         
+         System.out.println("field is "+varsField);
+         
+         Value value = declaringType.getValue(varsField);
+         
+         System.out.println("value is "+value);
+         
+         ObjectReferenceImpl valueImpl = (ObjectReferenceImpl) value;
+         
+         JDIFieldVariable var = new JDIFieldVariable((JDIDebugTarget)getDebugTarget(), varsField, valueImpl);       
+
+         System.out.println("Got Value for Stack Frame!!: "+value+" with impl class "+value.getClass());
+
+         result.add(var);
+         */
+
+        JDIFieldVariable vars = (JDIFieldVariable) getThis().getField( "frameLocalVars",
+                                                                       false );
+
+        JDIObjectValue val = (JDIObjectValue) vars.getValue();
+
+        try {
+
+            System.out.println( "Trying to get the map values" );
+
+            //            System.out.println("Declating type222 is "+vars.getDeclaringType());
+            //System.out.println("VAL type is "+vars.getReferenceType();
+
+            ObjectReference mapObj = ((JDIObjectValue) vars.getValue()).getUnderlyingObject();
+            ReferenceType t = mapObj.referenceType();
+
+            List allmethods = t.allMethods();
+
+            Method m2 = (Method) t.methodsByName( "entrySet" ).iterator().next();
+
+            System.out.println( "Got method " + m2 );
+
+            ThreadReference thread = ((DroolsThread) getThread()).getUnderlyingThread();
+            System.out.println( ". thread is . " + thread.getClass() + "; " + thread );
+            Value mapentries = mapObj.invokeMethod( thread,
+                                                    m2,
+                                                    new ArrayList(),
+                                                    0 );
+
+            //ObjectReference iteratorObj = ((JDIObjectValue)mapentries).getUnderlyingObject();
+            ObjectReferenceImpl entries = (ObjectReferenceImpl) mapentries;
+
+            Method m3 = (Method) entries.referenceType().methodsByName( "iterator" ).iterator().next();
+            Value iter = entries.invokeMethod( thread,
+                                               m3,
+                                               new ArrayList(),
+                                               0 );
+
+            /*             Method m2 = (Method) t.methodsByName( "i" ).iterator().next();
+             Value mapiter = ((JDIObjectValue)mapentries).getUnderlyingObject().invokeMethod( ((DroolsThread)getThread()).getUnderlyingThread(), m3, new ArrayList(), 0);
+             */
+
+            ObjectReferenceImpl valueImpl = (ObjectReferenceImpl) iter;
+
+            //boolean hasNext = hasNext(iter);
+            //ObjectReferenceImpl next = getNext(iter);
+
+            Field varsField;
+
+            IVariable var1 = new MVELThisVariable( getJavaDebugTarget(),
+                                                   valueImpl,
+                                                   "label1" );
+            IVariable var2 = new MVELThisVariable( getJavaDebugTarget(),
+                                                   valueImpl,
+                                                   "label2" );
+
+            //JDIFieldVariable var = new JDIFieldVariable((JDIDebugTarget)getDebugTarget(), varsField, valueImpl);
+            //JDILocalVariable var2 = new JDILocalVariable()
+            result.add( var1 );
+            result.add( var2 );
+
+            //            WatchExpression ex = new WatchExpression("frameLocalVars.entrySet().iterator()");
+            //            WatchExpression ex = new WatchExpression( "ttw12e4" );
+            //            ex.setExpressionContext( this );
+            //            System.out.println( "got expression value " + ex.getValue() );
+
+            //System.out.println("Got value "+mapentries);
+
+        } catch ( Throwable t ) {
+            t.printStackTrace();
+        }
+
+        IVariable[] vararr = (IVariable[]) result.toArray( new IVariable[result.size()] );
+
+        System.out.println( "Returning list of visible vars: count " + vararr.length );
+
+        return vararr;
+    }
+
+    protected DroolsStackFrame createNewDroolsFrame(StackFrame frame,
+                                                    int depth) {
+        return new MVELStackFrame( (DroolsThread) getThread(),
+                                   frame,
+                                   depth );
+    }
+
+    public String getReceivingTypeName() throws DebugException {
+        return "phph";
+    }
+
+    /*    public int getLineNumber() throws DebugException {
+     return 123;
+     }
+     
+     */
+    public String getMethodName() throws DebugException {
+        return "urr";
+    }
+
+/*    public String getDeclaringTypeName() throws DebugException {
+        return "MVELRunner";
+    }
+*/
+    public int getLineNumber() throws DebugException {
+/*        DRLInfo drlInfo = DroolsEclipsePlugin.getDefault().parseResource( marker.getResource(),
+                                                                          true );*/
+        System.out.println("LOCAL INFO LINE NR: "+getUnderlyingStackFrame().location().lineNumber());
+        return getUnderlyingStackFrame().location().lineNumber();
+    }
+
+    public RuleInfo getExecutingRuleInfo() {
+        try {
+            String methodName = getMethodName();
+            String signature = getSignature();
+            String type = getDeclaringTypeName();
+            System.out.println( "Getting EXECUTING RULE INFO: type=" + type + " methodName=" + methodName + " signature" + signature );
+
+            return DroolsEclipsePlugin.getDefault().getRuleInfoByClass( type );
+
+        } catch ( DebugException exc ) {
+            DroolsEclipsePlugin.log( exc );
+        }
+        return null;
+    }
+
+}

Added: labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/debug/core/MVELThisVariable.java
===================================================================
--- labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/debug/core/MVELThisVariable.java	                        (rev 0)
+++ labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/debug/core/MVELThisVariable.java	2007-06-30 21:10:20 UTC (rev 12965)
@@ -0,0 +1,35 @@
+package org.drools.eclipse.debug.core;
+
+import org.eclipse.debug.core.DebugException;
+import org.eclipse.jdi.internal.ObjectReferenceImpl;
+import org.eclipse.jdt.internal.debug.core.model.JDIDebugTarget;
+import org.eclipse.jdt.internal.debug.core.model.JDILocalVariable;
+import org.eclipse.jdt.internal.debug.core.model.JDIStackFrame;
+import org.eclipse.jdt.internal.debug.core.model.JDIThisVariable;
+
+import com.sun.jdi.ClassNotLoadedException;
+import com.sun.jdi.LocalVariable;
+import com.sun.jdi.ObjectReference;
+import com.sun.jdi.StackFrame;
+import com.sun.jdi.Type;
+import com.sun.jdi.VirtualMachine;
+
+public class MVELThisVariable extends JDIThisVariable {
+
+    private String label;
+
+    public MVELThisVariable(JDIDebugTarget target,
+                             ObjectReference object, String label) {
+        super( target,
+               object );
+        this.label = label;
+    }
+
+    public String getName() {
+        return label;
+    }
+   
+    public boolean isPublic() throws DebugException {
+        return true;
+    }
+}

Modified: labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/DroolsLineBreakpointAdapter.java
===================================================================
--- labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/DroolsLineBreakpointAdapter.java	2007-06-30 21:10:06 UTC (rev 12964)
+++ labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/editors/DroolsLineBreakpointAdapter.java	2007-06-30 21:10:20 UTC (rev 12965)
@@ -75,11 +75,36 @@
 			}
 			// TODO: drools breakpoints can only be created in functions and consequences
 			DroolsLineBreakpoint lineBreakpoint = new DroolsLineBreakpoint(resource, lineNumber + 1);
+
+            //RuleInfo ruleInfo = getRuleInfo(part, selection);
+            //System.out.println("SETTING RULEINFO "+ruleInfo.getDialect());
+            //lineBreakpoint.setRuleInfo(ruleInfo);
+            
 			DebugPlugin.getDefault().getBreakpointManager().addBreakpoint(lineBreakpoint);
+            
 		}
 	}
 
-	public void toggleMethodBreakpoints(IWorkbenchPart part, ISelection selection) throws CoreException {
+	private RuleInfo getRuleInfo(IWorkbenchPart part,
+                              ISelection selection) {
+        if (part instanceof IEditorPart && selection instanceof ITextSelection) {
+            IEditorPart editor = (IEditorPart) part;
+            IResource resource = (IResource) editor.getEditorInput().getAdapter(IResource.class);
+            ITextSelection textSelection = (ITextSelection) selection;
+            int lineNumber = textSelection.getStartLine();
+            try {
+                DRLInfo drlInfo = DroolsEclipsePlugin.getDefault().parseResource(resource, false);
+                if (drlInfo != null) {
+                    return drlInfo.getRuleInfo(lineNumber);
+                }
+            } catch (Throwable t) {
+                DroolsEclipsePlugin.log(t);
+            }
+        }
+        return null;
+    }
+
+    public void toggleMethodBreakpoints(IWorkbenchPart part, ISelection selection) throws CoreException {
 		// do nothing
 	}
 

Modified: labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/launching/DroolsSourceLookupDirector.java
===================================================================
--- labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/launching/DroolsSourceLookupDirector.java	2007-06-30 21:10:06 UTC (rev 12964)
+++ labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/launching/DroolsSourceLookupDirector.java	2007-06-30 21:10:20 UTC (rev 12965)
@@ -1,11 +1,57 @@
 package org.drools.eclipse.launching;
 
+import org.drools.eclipse.debug.core.DroolsDebugTarget;
+import org.drools.eclipse.debug.core.MVELStackFrame;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.debug.core.model.IDebugTarget;
 import org.eclipse.debug.core.sourcelookup.AbstractSourceLookupDirector;
+import org.eclipse.debug.core.sourcelookup.ISourceLookupDirector;
 import org.eclipse.debug.core.sourcelookup.ISourceLookupParticipant;
 
 public class DroolsSourceLookupDirector extends AbstractSourceLookupDirector {
 
 	public void initializeParticipants() {
+        addParticipants(new ISourceLookupParticipant[] {
+                                                        new ISourceLookupParticipant() {
+
+                                                            public void dispose() {
+                                                                // TODO Auto-generated method stub
+                                                                
+                                                            }
+
+                                                            public Object[] findSourceElements(Object object) throws CoreException {
+                                                                System.out.println("Searching for "+object);
+                                                                if (object instanceof MVELStackFrame) {
+                                                                    MVELStackFrame frame = (MVELStackFrame) object;
+                                                                    IDebugTarget target = frame.getDebugTarget();
+                                                                    if (target instanceof DroolsDebugTarget) {
+                                                                        DroolsDebugTarget droolsTarget = (DroolsDebugTarget)target;
+                                                                        System.out.println("Returning breakpoint as source element");
+                                                                        return new Object[] {droolsTarget.getFirstDroolsBreakpoint()};
+                                                                    }
+                                                                }
+                                                                return null;
+                                                            }
+
+                                                            public String getSourceName(Object object) throws CoreException {
+                                                                System.out.println("Getting source name:");
+                                                                return null;
+                                                            }
+
+                                                            public void init(ISourceLookupDirector director) {
+                                                                // TODO Auto-generated method stub
+                                                                
+                                                            }
+
+                                                            public void sourceContainersChanged(ISourceLookupDirector director) {
+                                                                // TODO Auto-generated method stub
+                                                                
+                                                            }
+                                                            
+                                                        }
+                                                        
+        } );
+        
 		addParticipants(new ISourceLookupParticipant[]{new DroolsSourceLookupParticipant()});
 	}
 

Modified: labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/launching/DroolsSourceLookupParticipant.java
===================================================================
--- labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/launching/DroolsSourceLookupParticipant.java	2007-06-30 21:10:06 UTC (rev 12964)
+++ labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/launching/DroolsSourceLookupParticipant.java	2007-06-30 21:10:20 UTC (rev 12965)
@@ -12,7 +12,10 @@
 		if (object instanceof DroolsStackFrame) {
 			RuleInfo ruleInfo = ((DroolsStackFrame) object).getExecutingRuleInfo();
 			if (ruleInfo != null) {
-				return ruleInfo.getSourcePathName();
+                
+                String p = ruleInfo.getSourcePathName();
+                System.out.println("RETURNING SOURCE LOOKUP SOURCE PATH "+ p);
+				return p;
 			}
 			FunctionInfo functionInfo = ((DroolsStackFrame) object).getExecutingFunctionInfo();
 			if (functionInfo != null) {

Modified: labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/launching/DroolsVMDebugger.java
===================================================================
--- labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/launching/DroolsVMDebugger.java	2007-06-30 21:10:06 UTC (rev 12964)
+++ labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/launching/DroolsVMDebugger.java	2007-06-30 21:10:20 UTC (rev 12965)
@@ -119,6 +119,9 @@
 			arguments.add("-Xnoagent"); //$NON-NLS-1$
 		}
 		
+        //System.out.println("ADDING DEBUGGING FLAG");
+        //arguments.add("-Dmvel.advanced_debugging=true");
+        
 		//check if java 1.4 or greater
 		if (version < 1.4) {
 			arguments.add("-Djava.compiler=NONE"); //$NON-NLS-1$

Modified: labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/rulebuilder/editors/BrlPage.java
===================================================================
--- labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/rulebuilder/editors/BrlPage.java	2007-06-30 21:10:06 UTC (rev 12964)
+++ labs/jbossrules/branches/mvel-tooling-2007-06-30/drools-eclipse/drools-eclipse-plugin/src/main/java/org/drools/eclipse/rulebuilder/editors/BrlPage.java	2007-06-30 21:10:20 UTC (rev 12965)
@@ -41,7 +41,7 @@
     }
 
     public void setModelXML(String xml) {
-        model = BRXMLPersistence.getInstance().unmarshal( xml );
+        model = BRXMLPersistence.getInstance().unmarshal( xml );        
         modeller.setModel( model );
         modeller.reloadWidgets();
     }




More information about the jboss-svn-commits mailing list