01: package org.drools.eclipse.debug;
02:
03: import java.util.ArrayList;
04: import java.util.List;
05:
06: import org.drools.eclipse.DroolsEclipsePlugin;
07: import org.eclipse.debug.core.DebugException;
08: import org.eclipse.debug.core.model.IValue;
09: import org.eclipse.debug.core.model.IVariable;
10: import org.eclipse.jdt.debug.core.IJavaArray;
11: import org.eclipse.jdt.debug.core.IJavaObject;
12: import org.eclipse.jdt.debug.core.IJavaValue;
13:
14: /**
15: * The Application Data View content provider.
16: *
17: * @author <a href="mailto:kris_verlaenen@hotmail.com">kris verlaenen </a>
18: */
19: public class ApplicationDataViewContentProvider extends
20: DroolsDebugViewContentProvider {
21:
22: private DroolsDebugEventHandlerView view;
23:
24: public ApplicationDataViewContentProvider(
25: DroolsDebugEventHandlerView view) {
26: this .view = view;
27: }
28:
29: protected String getEmptyString() {
30: return "The selected working memory has no globals defined.";
31: }
32:
33: public Object[] getChildren(Object obj) {
34: try {
35: IVariable[] variables = null;
36: if (obj != null
37: && obj instanceof IJavaObject
38: && "org.drools.reteoo.ReteooStatefulSession"
39: .equals(((IJavaObject) obj)
40: .getReferenceTypeName())) {
41: variables = getApplicationDataElements((IJavaObject) obj);
42: } else if (obj instanceof IVariable) {
43: if (view.isShowLogicalStructure()) {
44: IValue value = getLogicalValue(((IVariable) obj)
45: .getValue(), new ArrayList());
46: variables = value.getVariables();
47: }
48: if (variables == null) {
49: variables = ((IVariable) obj).getValue()
50: .getVariables();
51: }
52: }
53: if (variables == null) {
54: return new Object[0];
55: } else {
56: cache(obj, variables);
57: return variables;
58: }
59: } catch (DebugException e) {
60: DroolsEclipsePlugin.log(e);
61: return new Object[0];
62: }
63: }
64:
65: private IVariable[] getApplicationDataElements(IJavaObject stackObj)
66: throws DebugException {
67: IValue objects = DebugUtil
68: .getValueByExpression(
69: "return ((org.drools.base.MapGlobalResolver) getGlobalResolver()).getGlobals();",
70: stackObj);
71: if (objects instanceof IJavaArray) {
72: IJavaArray array = (IJavaArray) objects;
73: List result = new ArrayList();
74: IJavaValue[] javaVals = array.getValues();
75: for (int i = 0; i < javaVals.length; i++) {
76: IJavaValue mapEntry = javaVals[i];
77: String key = null;
78: IJavaValue value = null;
79:
80: IVariable[] vars = mapEntry.getVariables();
81: for (int j = 0; j < vars.length; j++) {
82: IVariable var = vars[j];
83: if ("key".equals(var.getName())) {
84: key = var.getValue().getValueString();
85: } else if ("value".equals(var.getName())) {
86: value = (IJavaValue) var.getValue();
87: }
88: }
89: result.add(new VariableWrapper(key, value));
90: }
91: return (IVariable[]) result.toArray(new IVariable[result
92: .size()]);
93: }
94: return null;
95: }
96: }
|