1 |
| package org.drools.reteoo; |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| |
9 |
| |
10 |
| |
11 |
| |
12 |
| |
13 |
| |
14 |
| |
15 |
| |
16 |
| |
17 |
| |
18 |
| |
19 |
| |
20 |
| |
21 |
| |
22 |
| |
23 |
| |
24 |
| |
25 |
| |
26 |
| |
27 |
| |
28 |
| |
29 |
| |
30 |
| |
31 |
| |
32 |
| |
33 |
| |
34 |
| |
35 |
| |
36 |
| |
37 |
| |
38 |
| |
39 |
| |
40 |
| |
41 |
| |
42 |
| |
43 |
| import java.io.PrintStream; |
44 |
| import java.util.Iterator; |
45 |
| |
46 |
| import org.drools.RuleBase; |
47 |
| import org.drools.rule.Declaration; |
48 |
| |
49 |
| public class ReteooPrintDumpVisitor extends ReflectiveVisitor |
50 |
| { |
51 |
| private PrintStream out; |
52 |
| |
53 |
| private StringBuffer buffer; |
54 |
| |
55 |
| private int depth; |
56 |
| |
57 |
| private String indent; |
58 |
| |
59 |
0
| public ReteooPrintDumpVisitor(PrintStream out)
|
60 |
| { |
61 |
0
| this.out = out;
|
62 |
0
| this.indent = " ";
|
63 |
| } |
64 |
| |
65 |
0
| public ReteooPrintDumpVisitor(PrintStream out,
|
66 |
| String indent) |
67 |
| { |
68 |
0
| this.out = out;
|
69 |
0
| this.indent = indent;
|
70 |
| } |
71 |
| |
72 |
0
| public void visitRuleBase(RuleBase ruleBase)
|
73 |
| { |
74 |
0
| buffer = new StringBuffer( );
|
75 |
0
| visit( ((RuleBaseImpl) ruleBase).getRete( ) );
|
76 |
0
| out.println( buffer.toString( ) );
|
77 |
| } |
78 |
| |
79 |
0
| public void visitRete(Rete rete)
|
80 |
| { |
81 |
0
| buffer.append( "Rete" );
|
82 |
0
| buffer.append( newline );
|
83 |
0
| buffer.append( "----" );
|
84 |
0
| buffer.append( newline );
|
85 |
0
| Iterator it = rete.getObjectTypeNodeIterator( );
|
86 |
0
| int scopedDepth = depth;
|
87 |
0
| depth++;
|
88 |
0
| while ( it.hasNext( ) )
|
89 |
| { |
90 |
0
| visit( it.next( ) );
|
91 |
| } |
92 |
0
| depth = scopedDepth;
|
93 |
| } |
94 |
| |
95 |
0
| public void visitObjectTypeNode(ObjectTypeNode objectTypeNode)
|
96 |
| { |
97 |
0
| String indent = getIndent( depth );
|
98 |
0
| buffer.append( indent ).append( "ObjectTypeNode" );
|
99 |
0
| buffer.append( newline );
|
100 |
0
| buffer.append( indent ).append( "--------------" );
|
101 |
0
| buffer.append( newline );
|
102 |
0
| buffer.append( indent ).append( "objectType: " + objectTypeNode.getObjectType( ).toString( ) );
|
103 |
0
| buffer.append( newline );
|
104 |
0
| Iterator it = objectTypeNode.getParameterNodeIterator( );
|
105 |
0
| int scopedDepth = depth;
|
106 |
0
| depth++;
|
107 |
0
| while ( it.hasNext( ) )
|
108 |
| { |
109 |
0
| visit( it.next( ) );
|
110 |
| } |
111 |
0
| depth = scopedDepth;
|
112 |
| } |
113 |
| |
114 |
0
| public void visitParameterNode(ParameterNode parameterNode)
|
115 |
| { |
116 |
0
| String indent = getIndent( depth );
|
117 |
0
| buffer.append( indent ).append( "ParameterNode" );
|
118 |
0
| buffer.append( newline );
|
119 |
0
| buffer.append( indent ).append( "-------------" );
|
120 |
0
| buffer.append( newline );
|
121 |
0
| int scopedDepth = depth;
|
122 |
0
| depth++;
|
123 |
0
| visit( parameterNode.getDeclaration( ) );
|
124 |
0
| buffer.append( indent ).append( "tupleSink:" );
|
125 |
0
| buffer.append( newline );
|
126 |
| |
127 |
0
| Iterator it = parameterNode.getTupleSinks( ).iterator( );
|
128 |
0
| depth++;
|
129 |
0
| while ( it.hasNext() )
|
130 |
| { |
131 |
0
| visit( it.next() );
|
132 |
| } |
133 |
0
| depth = scopedDepth;
|
134 |
| } |
135 |
| |
136 |
0
| public void visitDeclaration(Declaration declaration)
|
137 |
| { |
138 |
0
| String indent = getIndent( depth );
|
139 |
0
| buffer.append( indent ).append( "Declaration" );
|
140 |
0
| buffer.append( newline );
|
141 |
0
| buffer.append( indent ).append( "-----------" );
|
142 |
0
| buffer.append( newline );
|
143 |
0
| buffer.append( indent ).append( "identifier: " );
|
144 |
0
| buffer.append( declaration.getIdentifier( ) );
|
145 |
0
| buffer.append( newline );
|
146 |
0
| buffer.append( indent ).append( "objectType: " );
|
147 |
0
| buffer.append( declaration.getObjectType( ) );
|
148 |
0
| buffer.append( newline );
|
149 |
| } |
150 |
| |
151 |
0
| public void visitConditionNode(ConditionNode conditionNode)
|
152 |
| { |
153 |
0
| String indent = getIndent( depth );
|
154 |
0
| buffer.append( indent ).append( "ConditionNode" );
|
155 |
0
| buffer.append( newline );
|
156 |
0
| buffer.append( indent ).append( "-------------" );
|
157 |
0
| buffer.append( newline );
|
158 |
0
| buffer.append( indent ).append( "condition: " );
|
159 |
0
| buffer.append( conditionNode.toString( ) );
|
160 |
0
| buffer.append( newline );
|
161 |
0
| buffer.append( indent ).append( "tupleSink:" );
|
162 |
0
| buffer.append( newline );
|
163 |
0
| int scopedDepth = depth;
|
164 |
0
| Iterator it = conditionNode.getTupleSinks( ).iterator( );
|
165 |
0
| depth++;
|
166 |
0
| while ( it.hasNext() )
|
167 |
| { |
168 |
0
| visit( it.next() );
|
169 |
| } |
170 |
0
| depth = scopedDepth;
|
171 |
| } |
172 |
| |
173 |
0
| public void visitJoinNodeInput(JoinNodeInput joinNodeInput)
|
174 |
| { |
175 |
0
| String indent = getIndent( depth );
|
176 |
0
| buffer.append( indent ).append( "JoinNodeInput" );
|
177 |
0
| buffer.append( newline );
|
178 |
0
| buffer.append( indent ).append( "-------------" );
|
179 |
0
| buffer.append( newline );
|
180 |
0
| buffer.append( indent ).append( joinNodeInput.toString( ) );
|
181 |
0
| buffer.append( newline );
|
182 |
0
| int scopedDepth = depth;
|
183 |
0
| Iterator it = joinNodeInput.getJoinNode( ).getTupleSinks( ).iterator( );
|
184 |
0
| depth++;
|
185 |
0
| while ( it.hasNext() )
|
186 |
| { |
187 |
0
| visit( it.next() );
|
188 |
| } |
189 |
0
| depth = scopedDepth;
|
190 |
| |
191 |
| } |
192 |
| |
193 |
0
| public void visitTerminalNode(TerminalNode terminalNode)
|
194 |
| { |
195 |
0
| String indent = getIndent( depth );
|
196 |
0
| buffer.append( indent ).append( "TerminalNode" );
|
197 |
0
| buffer.append( newline );
|
198 |
0
| buffer.append( indent ).append( "-------------" );
|
199 |
0
| buffer.append( newline );
|
200 |
0
| buffer.append( indent ).append( terminalNode.toString( ) );
|
201 |
0
| buffer.append( newline );
|
202 |
| } |
203 |
| |
204 |
0
| public void visitObject(Object object)
|
205 |
| { |
206 |
0
| buffer.append( "no visitor implementation for : " + object.getClass( ) + " : " + object );
|
207 |
0
| buffer.append( newline );
|
208 |
| } |
209 |
| |
210 |
0
| public void visitNull()
|
211 |
| { |
212 |
0
| buffer.append( "unable to visit null objects" );
|
213 |
0
| buffer.append( newline );
|
214 |
| } |
215 |
| |
216 |
0
| private String getIndent(int depth)
|
217 |
| { |
218 |
0
| StringBuffer indentBuffer = new StringBuffer( );
|
219 |
0
| for ( int i = 0; i < depth; i++ )
|
220 |
| { |
221 |
0
| indentBuffer.append( indent );
|
222 |
| } |
223 |
0
| return indentBuffer.toString( );
|
224 |
| } |
225 |
| } |