Source Code Cross Referenced for AgendaViewContentProvider.java in  » Rule-Engine » drolls-Rule-Engine » org » drools » eclipse » debug » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Rule Engine » drolls Rule Engine » org.drools.eclipse.debug 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.drools.eclipse.debug;
002:
003:        import java.util.ArrayList;
004:        import java.util.List;
005:
006:        import org.drools.eclipse.DroolsEclipsePlugin;
007:        import org.eclipse.debug.core.DebugException;
008:        import org.eclipse.debug.core.model.IValue;
009:        import org.eclipse.debug.core.model.IVariable;
010:        import org.eclipse.jdt.debug.core.IJavaArray;
011:        import org.eclipse.jdt.debug.core.IJavaObject;
012:        import org.eclipse.jdt.debug.core.IJavaValue;
013:        import org.eclipse.jdt.debug.core.IJavaVariable;
014:
015:        /**
016:         * The Agenda View content provider.
017:         * 
018:         * @author <a href="mailto:kris_verlaenen@hotmail.com">kris verlaenen </a>
019:         */
020:        public class AgendaViewContentProvider extends
021:                DroolsDebugViewContentProvider {
022:
023:            private DroolsDebugEventHandlerView view;
024:
025:            public AgendaViewContentProvider(DroolsDebugEventHandlerView view) {
026:                this .view = view;
027:            }
028:
029:            protected String getEmptyString() {
030:                return "The selected working memory has an empty agenda.";
031:            }
032:
033:            public Object[] getChildren(Object obj) {
034:                try {
035:                    Object[] variables = null;
036:                    if (obj != null
037:                            && obj instanceof  IJavaObject
038:                            && "org.drools.reteoo.ReteooStatefulSession"
039:                                    .equals(((IJavaObject) obj)
040:                                            .getReferenceTypeName())) {
041:                        variables = getAgendaElements((IJavaObject) obj);
042:                    } else if (obj instanceof  IVariable) {
043:                        if (view.isShowLogicalStructure()) {
044:                            IValue value = getLogicalValue(((IVariable) obj)
045:                                    .getValue(), new ArrayList());
046:                            variables = value.getVariables();
047:                        }
048:                        if (variables == null) {
049:                            variables = ((IVariable) obj).getValue()
050:                                    .getVariables();
051:                        }
052:                    }
053:                    if (variables == null) {
054:                        return new Object[0];
055:                    } else {
056:                        cache(obj, variables);
057:                        return variables;
058:                    }
059:                } catch (DebugException e) {
060:                    DroolsEclipsePlugin.log(e);
061:                    return new Object[0];
062:                }
063:            }
064:
065:            private Object[] getAgendaElements(IJavaObject workingMemoryImpl)
066:                    throws DebugException {
067:                List result = new ArrayList();
068:                IValue agendaGroupObjects = DebugUtil.getValueByExpression(
069:                        "return getAgenda().getAgendaGroups();",
070:                        workingMemoryImpl);
071:                IValue focus = DebugUtil.getValueByExpression(
072:                        "return getAgenda().getFocus();", workingMemoryImpl);
073:                if (agendaGroupObjects instanceof  IJavaArray) {
074:                    IJavaArray agendaGroupArray = (IJavaArray) agendaGroupObjects;
075:                    IJavaValue[] agendaGroupValueArray = agendaGroupArray
076:                            .getValues();
077:                    for (int i = 0; i < agendaGroupValueArray.length; i++) {
078:                        IJavaValue agendaGroup = agendaGroupValueArray[i];
079:                        String name = "";
080:                        List activationsResult = new ArrayList();
081:                        IVariable[] agendaGroupVarArray = agendaGroup
082:                                .getVariables();
083:                        for (int j = 0; j < agendaGroupVarArray.length; j++) {
084:                            IVariable agendaGroupVar = agendaGroupVarArray[j];
085:                            if ("name".equals(agendaGroupVar.getName())) {
086:                                name = agendaGroupVar.getValue()
087:                                        .getValueString();
088:                                break;
089:                            }
090:                        }
091:                        IJavaArray activations = (IJavaArray) DebugUtil
092:                                .getValueByExpression(
093:                                        "return getActivations();", agendaGroup);
094:                        IJavaValue[] activationArray = activations.getValues();
095:                        for (int l = 0; l < activationArray.length; l++) {
096:                            IJavaValue activation = activationArray[l];
097:                            if (activation.getJavaType() != null) {
098:                                activationsResult.add(new VariableWrapper("["
099:                                        + l + "]", new LazyActivationWrapper(
100:                                        activations, activation,
101:                                        workingMemoryImpl)));
102:                            }
103:                        }
104:                        boolean active = false;
105:                        if (agendaGroup.equals(focus)) {
106:                            active = true;
107:                        }
108:                        // because the debug view does not handle spaces well, all spaces
109:                        // in the agenda group name are replaced with '_'s.
110:                        name = replaceSpaces(name);
111:                        result
112:                                .add(new MyVariableWrapper(
113:                                        name
114:                                                + "["
115:                                                + (active ? "focus" : "nofocus")
116:                                                + "]",
117:                                        new ObjectWrapper(
118:                                                (IJavaObject) agendaGroup,
119:                                                (IJavaVariable[]) activationsResult
120:                                                        .toArray(new IJavaVariable[activationsResult
121:                                                                .size()]))));
122:                    }
123:                }
124:                return result.toArray(new IVariable[0]);
125:            }
126:
127:            private String replaceSpaces(String name) {
128:                return name.replace(' ', '_');
129:            }
130:
131:            private class LazyActivationWrapper extends ObjectWrapper {
132:
133:                private IJavaValue activation;
134:                private IJavaValue workingMemoryImpl;
135:
136:                public LazyActivationWrapper(IJavaObject object,
137:                        IJavaValue activation, IJavaObject workingMemoryImpl) {
138:                    super (object, null);
139:                    this .activation = activation;
140:                    this .workingMemoryImpl = workingMemoryImpl;
141:                }
142:
143:                public IVariable[] getVariables() {
144:                    IVariable[] result = super .getVariables();
145:                    if (result == null) {
146:                        try {
147:                            List variables = new ArrayList();
148:                            variables
149:                                    .add(new VariableWrapper(
150:                                            "ruleName",
151:                                            (IJavaValue) DebugUtil
152:                                                    .getValueByExpression(
153:                                                            "return getRule().getName();",
154:                                                            activation)));
155:                            String activationId = null;
156:                            IVariable[] activationVarArray = activation
157:                                    .getVariables();
158:                            for (int j = 0; j < activationVarArray.length; j++) {
159:                                IVariable activationVar = activationVarArray[j];
160:                                if ("activationNumber".equals(activationVar
161:                                        .getName())) {
162:                                    activationId = activationVar.getValue()
163:                                            .getValueString();
164:                                    break;
165:                                }
166:                            }
167:                            if (activationId != null) {
168:                                IValue objects = DebugUtil
169:                                        .getValueByExpression(
170:                                                "return getActivationParameters("
171:                                                        + activationId + ");",
172:                                                workingMemoryImpl);
173:                                if (objects instanceof  IJavaArray) {
174:                                    IJavaArray array = (IJavaArray) objects;
175:                                    IJavaValue[] javaVals = array.getValues();
176:                                    for (int k = 0; k < javaVals.length; k++) {
177:                                        IJavaValue mapEntry = javaVals[k];
178:                                        String key = null;
179:                                        IJavaValue value = null;
180:
181:                                        IVariable[] vars = mapEntry
182:                                                .getVariables();
183:                                        for (int j = 0; j < vars.length; j++) {
184:                                            IVariable var = vars[j];
185:                                            if ("key".equals(var.getName())) {
186:                                                key = var.getValue()
187:                                                        .getValueString();
188:                                            } else if ("value".equals(var
189:                                                    .getName())) {
190:                                                value = (IJavaValue) var
191:                                                        .getValue();
192:                                            }
193:                                        }
194:                                        variables.add(new VariableWrapper(key,
195:                                                value));
196:                                    }
197:                                    result = (IJavaVariable[]) variables
198:                                            .toArray(new IJavaVariable[variables
199:                                                    .size()]);
200:                                }
201:                            }
202:                        } catch (Throwable t) {
203:                            DroolsEclipsePlugin.log(t);
204:                        }
205:                        if (result == null) {
206:                            result = new IJavaVariable[0];
207:                        }
208:                        setVariables((IJavaVariable[]) result);
209:                    }
210:                    return result;
211:                }
212:
213:                public boolean hasVariables() {
214:                    return true;
215:                }
216:
217:                public String getValueString() throws DebugException {
218:                    return "Activation";
219:                }
220:
221:                public String getReferenceTypeName() throws DebugException {
222:                    return "";
223:                }
224:            }
225:
226:            /**
227:             * Special VariableWrapper that considers variables with the same name
228:             * as equal.
229:             */
230:            private class MyVariableWrapper extends VariableWrapper {
231:
232:                public MyVariableWrapper(String name, IJavaValue value) {
233:                    super (name, value);
234:                }
235:
236:                public boolean equals(Object obj) {
237:                    if (obj instanceof  VariableWrapper) {
238:                        VariableWrapper var = (VariableWrapper) obj;
239:                        return var.getName().equals(getName());
240:                    }
241:                    return false;
242:                }
243:
244:                public int hashCode() {
245:                    return getName().hashCode();
246:                }
247:
248:            }
249:
250:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.