Source Code Cross Referenced for BuildContext.java in  » Rule-Engine » drolls-Rule-Engine » org » drools » reteoo » builder » 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.reteoo.builder 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2006 JBoss Inc
003:         * 
004:         * Licensed under the Apache License, Version 2.0 (the "License");
005:         * you may not use this file except in compliance with the License.
006:         * You may obtain a copy of the License at
007:         * 
008:         *      http://www.apache.org/licenses/LICENSE-2.0
009:         * 
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         */
016:
017:        package org.drools.reteoo.builder;
018:
019:        import java.util.HashMap;
020:        import java.util.LinkedList;
021:        import java.util.List;
022:        import java.util.ListIterator;
023:        import java.util.Map;
024:
025:        import org.drools.common.BetaConstraints;
026:        import org.drools.common.InternalRuleBase;
027:        import org.drools.common.InternalWorkingMemory;
028:        import org.drools.reteoo.ObjectSource;
029:        import org.drools.reteoo.ReteooBuilder;
030:        import org.drools.reteoo.ReteooRuleBase;
031:        import org.drools.reteoo.TupleSource;
032:        import org.drools.rule.RuleConditionElement;
033:
034:        /**
035:         * A build context for Reteoo Builder
036:         * 
037:         * @author etirelli
038:         */
039:        public class BuildContext {
040:
041:            // tuple source to attach next node to
042:            private TupleSource tupleSource;
043:
044:            // object source to attach next node to
045:            private ObjectSource objectSource;
046:
047:            // object type cache to check for cross products
048:            private LinkedList objectType;
049:
050:            // offset of the pattern
051:            private int currentPatternOffset;
052:
053:            // rule base to add rules to
054:            private InternalRuleBase rulebase;
055:
056:            // working memories attached to the given rulebase
057:            private InternalWorkingMemory[] workingMemories;
058:
059:            // id generator
060:            private ReteooBuilder.IdGenerator idGenerator;
061:
062:            // a build stack to track nested elements
063:            private LinkedList buildstack;
064:
065:            // beta constraints from the last pattern attached
066:            private List betaconstraints;
067:
068:            // alpha constraints from the last pattern attached
069:            private List alphaConstraints;
070:
071:            public BuildContext(final InternalRuleBase rulebase,
072:                    final ReteooBuilder.IdGenerator idGenerator) {
073:                this .rulebase = rulebase;
074:                this .workingMemories = (InternalWorkingMemory[]) this .rulebase
075:                        .getWorkingMemories();
076:                this .idGenerator = idGenerator;
077:
078:                this .objectType = new LinkedList();
079:                this .buildstack = new LinkedList();
080:
081:                this .tupleSource = null;
082:                this .objectSource = null;
083:
084:                this .currentPatternOffset = 0;
085:            }
086:
087:            /**
088:             * @return the currentPatternOffset
089:             */
090:            public int getCurrentPatternOffset() {
091:                return this .currentPatternOffset;
092:            }
093:
094:            /**
095:             * @param currentPatternOffset the currentPatternOffset to set
096:             */
097:            public void setCurrentPatternOffset(final int currentPatternIndex) {
098:                this .currentPatternOffset = currentPatternIndex;
099:                this .syncObjectTypesWithPatternOffset();
100:            }
101:
102:            public void syncObjectTypesWithPatternOffset() {
103:                while (this .objectType.size() > this .currentPatternOffset) {
104:                    this .objectType.removeLast();
105:                }
106:            }
107:
108:            /**
109:             * @return the objectSource
110:             */
111:            public ObjectSource getObjectSource() {
112:                return this .objectSource;
113:            }
114:
115:            /**
116:             * @param objectSource the objectSource to set
117:             */
118:            public void setObjectSource(final ObjectSource objectSource) {
119:                this .objectSource = objectSource;
120:            }
121:
122:            /**
123:             * @return the objectType
124:             */
125:            public LinkedList getObjectType() {
126:                return this .objectType;
127:            }
128:
129:            /**
130:             * @param objectType the objectType to set
131:             */
132:            public void setObjectType(final LinkedList objectType) {
133:                this .objectType = objectType;
134:            }
135:
136:            /**
137:             * @return the tupleSource
138:             */
139:            public TupleSource getTupleSource() {
140:                return this .tupleSource;
141:            }
142:
143:            /**
144:             * @param tupleSource the tupleSource to set
145:             */
146:            public void setTupleSource(final TupleSource tupleSource) {
147:                this .tupleSource = tupleSource;
148:            }
149:
150:            public void incrementCurrentPatternOffset() {
151:                this .currentPatternOffset++;
152:            }
153:
154:            public void decrementCurrentPatternOffset() {
155:                this .currentPatternOffset--;
156:                this .syncObjectTypesWithPatternOffset();
157:            }
158:
159:            /**
160:             * Returns context rulebase
161:             * @return
162:             */
163:            public InternalRuleBase getRuleBase() {
164:                return this .rulebase;
165:            }
166:
167:            /**
168:             * Return the array of working memories associated with the given
169:             * rulebase.
170:             * 
171:             * @return
172:             */
173:            public InternalWorkingMemory[] getWorkingMemories() {
174:                return this .workingMemories;
175:            }
176:
177:            /**
178:             * Returns an Id for the next node
179:             * @return
180:             */
181:            public int getNextId() {
182:                return this .idGenerator.getNextId();
183:            }
184:
185:            /**
186:             * Method used to undo previous id assignment
187:             */
188:            public void releaseLastId() {
189:                this .idGenerator.releaseLastId();
190:            }
191:
192:            /**
193:             * Adds the rce to the build stack
194:             * @param rce
195:             */
196:            public void push(final RuleConditionElement rce) {
197:                this .buildstack.addLast(rce);
198:            }
199:
200:            /**
201:             * Removes the top stack element
202:             * @return
203:             */
204:            public RuleConditionElement pop() {
205:                return (RuleConditionElement) this .buildstack.removeLast();
206:            }
207:
208:            /**
209:             * Returns the top stack element without removing it
210:             * @return
211:             */
212:            public RuleConditionElement peek() {
213:                return (RuleConditionElement) this .buildstack.getLast();
214:            }
215:
216:            /**
217:             * Returns a list iterator to iterate over the stacked elements
218:             * @return
219:             */
220:            public ListIterator stackIterator() {
221:                return this .buildstack.listIterator();
222:            }
223:
224:            /**
225:             * @return the betaconstraints
226:             */
227:            public List getBetaconstraints() {
228:                return this .betaconstraints;
229:            }
230:
231:            /**
232:             * @param betaconstraints the betaconstraints to set
233:             */
234:            public void setBetaconstraints(final List betaconstraints) {
235:                this .betaconstraints = betaconstraints;
236:            }
237:
238:            public int getNextSequence(String groupName) {
239:                //List list = new ArrayList();
240:
241:                Integer seq = (Integer) this .rulebase
242:                        .getAgendaGroupRuleTotals().get(groupName);
243:                if (seq == null) {
244:                    seq = new Integer(0);
245:                }
246:                Integer newSeq = new Integer(seq.intValue() + 1);
247:                this .rulebase.getAgendaGroupRuleTotals().put(groupName, newSeq);
248:
249:                return newSeq.intValue();
250:            }
251:
252:            /**
253:             * @return
254:             */
255:            public List getAlphaConstraints() {
256:                return alphaConstraints;
257:            }
258:
259:            public void setAlphaConstraints(List alphaConstraints) {
260:                this.alphaConstraints = alphaConstraints;
261:            }
262:
263:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.