From: <jbo...@li...> - 2006-01-09 02:07:13
|
Author: mar...@jb... Date: 2006-01-08 21:07:00 -0500 (Sun, 08 Jan 2006) New Revision: 2028 Added: trunk/labs/jbossrules/drools-core/src/main/java/org/drools/ReteooJungViewer.java trunk/labs/jbossrules/drools-core/src/main/java/org/drools/reteoo/ReteooToJungVisitor.java Removed: trunk/labs/jbossrules/drools-core/src/test/java/org/drools/examples/manners/Seat.java Modified: trunk/labs/jbossrules/drools-core/pom.xml trunk/labs/jbossrules/drools-core/src/main/java/org/drools/reteoo/Builder.java trunk/labs/jbossrules/drools-core/src/main/java/org/drools/reteoo/ObjectTypeNode.java trunk/labs/jbossrules/drools-core/src/main/java/org/drools/reteoo/TerminalNode.java trunk/labs/jbossrules/drools-core/src/main/java/org/drools/rule/Column.java trunk/labs/jbossrules/drools-core/src/main/java/org/drools/rule/Rule.java trunk/labs/jbossrules/drools-core/src/main/java/org/drools/rule/RuleSet.java trunk/labs/jbossrules/drools-core/src/main/java/org/drools/spi/ClassObjectType.java trunk/labs/jbossrules/drools-core/src/test/java/org/drools/event/WorkingMemoryEventSupportTest.java trunk/labs/jbossrules/drools-core/src/test/java/org/drools/examples/manners/Context.java trunk/labs/jbossrules/drools-core/src/test/java/org/drools/examples/manners/Guest.java trunk/labs/jbossrules/drools-core/src/test/java/org/drools/examples/manners/Hobby.java trunk/labs/jbossrules/drools-core/src/test/java/org/drools/examples/manners/LastSeat.java trunk/labs/jbossrules/drools-core/src/test/java/org/drools/examples/manners/MannersTest.java trunk/labs/jbossrules/drools-core/src/test/java/org/drools/examples/manners/Path.java trunk/labs/jbossrules/drools-core/src/test/java/org/drools/examples/manners/Seating.java trunk/labs/jbossrules/drools-core/src/test/java/org/drools/examples/manners/Sex.java Log: -Added Jung based reteviewer with temporary example. Modified: trunk/labs/jbossrules/drools-core/pom.xml =================================================================== --- trunk/labs/jbossrules/drools-core/pom.xml 2006-01-08 23:45:28 UTC (rev 2027) +++ trunk/labs/jbossrules/drools-core/pom.xml 2006-01-09 02:07:00 UTC (rev 2028) @@ -11,5 +11,13 @@ <name>Drools :: Rete-OO Core</name> <version>3.0-M1-dev</version> + + <dependencies> + <dependency> + <groupId>jung</groupId> + <artifactId>jung</artifactId> + <version>1.7.2</version> + </dependency> + </dependencies> </project> \ No newline at end of file Added: trunk/labs/jbossrules/drools-core/src/main/java/org/drools/ReteooJungViewer.java =================================================================== --- trunk/labs/jbossrules/drools-core/src/main/java/org/drools/ReteooJungViewer.java 2006-01-08 23:45:28 UTC (rev 2027) +++ trunk/labs/jbossrules/drools-core/src/main/java/org/drools/ReteooJungViewer.java 2006-01-09 02:07:00 UTC (rev 2028) @@ -0,0 +1,185 @@ +package org.drools; + +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Container; +import java.awt.Dimension; +import java.awt.GridLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.MouseEvent; + +import javax.swing.BorderFactory; +import javax.swing.JButton; +import javax.swing.JEditorPane; +import javax.swing.JFrame; +import javax.swing.JPanel; +import javax.swing.JScrollPane; + +import org.drools.reteoo.ReteooToJungVisitor; +import org.drools.reteoo.ReteooToJungVisitor.ReteooNodeVertex; + +import edu.uci.ics.jung.graph.Graph; +import edu.uci.ics.jung.graph.Vertex; +import edu.uci.ics.jung.graph.decorators.DefaultToolTipFunction; +import edu.uci.ics.jung.graph.decorators.EdgeShape; +import edu.uci.ics.jung.graph.decorators.EllipseVertexShapeFunction; +import edu.uci.ics.jung.graph.decorators.PickableEdgePaintFunction; +import edu.uci.ics.jung.graph.decorators.PickableVertexPaintFunction; +import edu.uci.ics.jung.graph.impl.SparseGraph; +import edu.uci.ics.jung.graph.impl.SparseTree; +import edu.uci.ics.jung.visualization.DefaultGraphLabelRenderer; +import edu.uci.ics.jung.visualization.GraphMouseListener; +import edu.uci.ics.jung.visualization.GraphZoomScrollPane; +import edu.uci.ics.jung.visualization.Layout; +import edu.uci.ics.jung.visualization.PluggableRenderer; +import edu.uci.ics.jung.visualization.ShapePickSupport; +import edu.uci.ics.jung.visualization.VisualizationViewer; +import edu.uci.ics.jung.visualization.contrib.DAGLayout; +import edu.uci.ics.jung.visualization.contrib.TreeLayout; +import edu.uci.ics.jung.visualization.control.CrossoverScalingControl; +import edu.uci.ics.jung.visualization.control.CrossoverScalingGraphMousePlugin; +import edu.uci.ics.jung.visualization.control.PickingGraphMousePlugin; +import edu.uci.ics.jung.visualization.control.PluggableGraphMouse; +import edu.uci.ics.jung.visualization.control.ScalingControl; +import edu.uci.ics.jung.visualization.control.ViewScalingGraphMousePlugin; + +import samples.graph.TreeLayoutDemo; + +public class ReteooJungViewer extends JFrame { + + /** + * the graph + */ + Graph graph; + + /** + * the visual component and renderer for the graph + */ + VisualizationViewer vv; + + // public static void main(String[] args) { + // javax.swing.SwingUtilities.invokeLater(new Runnable() { + // public void run() { + // createAndShowGUI(); + // } + // }); + // } + + public static void createAndShowGUI(RuleBase ruleBase) { + ReteooJungViewer viewer = new ReteooJungViewer(ruleBase);; + } + + public ReteooJungViewer(RuleBase ruleBase) { + ReteooToJungVisitor visitor = new ReteooToJungVisitor(); + visitor.visit( ruleBase ); + this.graph = visitor.getGraph(); + this.graph.g + + final PluggableRenderer pr = new PluggableRenderer(); + + pr.setVertexPaintFunction( new PickableVertexPaintFunction( pr, + Color.black, + Color.white, + Color.yellow ) ); + pr.setEdgePaintFunction( new PickableEdgePaintFunction( pr, + Color.black, + Color.cyan ) ); + pr.setGraphLabelRenderer( new DefaultGraphLabelRenderer( Color.cyan, + Color.cyan ) ); + + pr.setVertexShapeFunction( new EllipseVertexShapeFunction() ); + + Layout layout = new DAGLayout( this.graph ); + + this.vv = new VisualizationViewer( layout, + pr, + new Dimension( 600, + 600 ) ); + this.vv.setPickSupport( new ShapePickSupport() ); + pr.setEdgeShapeFunction( new EdgeShape.QuadCurve() ); + this.vv.setBackground( Color.white ); + + // add a listener for ToolTips + this.vv.setToolTipFunction( new DefaultToolTipFunction() ); + + Container content = getContentPane(); + final GraphZoomScrollPane panel = new GraphZoomScrollPane( this.vv ); + content.add( panel ); + + final PluggableGraphMouse graphMouse = new PluggableGraphMouse(); + graphMouse.add( new PickingGraphMousePlugin() ); + graphMouse.add( new ViewScalingGraphMousePlugin() ); + graphMouse.add( new CrossoverScalingGraphMousePlugin() ); + + this.vv.setGraphMouse( graphMouse ); + + final ScalingControl scaler = new CrossoverScalingControl(); + + JButton plus = new JButton( "+" ); + plus.addActionListener( new ActionListener() { + public void actionPerformed(ActionEvent e) { + scaler.scale( ReteooJungViewer.this.vv, + 1.1f, + ReteooJungViewer.this.vv.getCenter() ); + } + } ); + JButton minus = new JButton( "-" ); + minus.addActionListener( new ActionListener() { + public void actionPerformed(ActionEvent e) { + scaler.scale( ReteooJungViewer.this.vv, + 0.9f, + ReteooJungViewer.this.vv.getCenter() ); + } + } ); + + JPanel scaleGrid = new JPanel( new GridLayout( 1, + 0 ) ); + scaleGrid.setBorder( BorderFactory.createTitledBorder( "Zoom" ) ); + + JPanel controls = new JPanel(); + scaleGrid.add( plus ); + scaleGrid.add( minus ); + controls.add( scaleGrid ); + content.add( controls, + BorderLayout.SOUTH ); + + final JEditorPane editorPane = new JEditorPane(); + editorPane.setEditable( false ); + editorPane.setContentType( "text/html" ); + + this.vv.addGraphMouseListener( new GraphMouseListener() { + + public void graphClicked(Vertex vertex, + MouseEvent e) { + System.out.println( vertex ); + editorPane.setText( ((HtmlContent)vertex).getHtml() ); + } + + public void graphPressed(Vertex vertex, + MouseEvent e) { + } + + public void graphReleased(Vertex vertex, + MouseEvent e) { + } + + } ); + + // Put the editor pane in a scroll pane. + JScrollPane editorScrollPane = new JScrollPane( editorPane ); + editorScrollPane.setPreferredSize( new Dimension( 250, + 145 ) ); + editorScrollPane.setMinimumSize( new Dimension( 10, + 10 ) ); + content.add( editorScrollPane, + BorderLayout.EAST ); + + pack(); + setVisible( true ); + } + + public interface HtmlContent { + public String getHtml(); + } +} Modified: trunk/labs/jbossrules/drools-core/src/main/java/org/drools/reteoo/Builder.java =================================================================== --- trunk/labs/jbossrules/drools-core/src/main/java/org/drools/reteoo/Builder.java 2006-01-08 23:45:28 UTC (rev 2027) +++ trunk/labs/jbossrules/drools-core/src/main/java/org/drools/reteoo/Builder.java 2006-01-09 02:07:00 UTC (rev 2028) @@ -142,12 +142,14 @@ addRule( and[i], rule ); } - TerminalNode node = new TerminalNode( this.tupleSource, + TerminalNode node = new TerminalNode( ++this.id, + this.tupleSource, rule ); } private void addRule(And and, Rule rule) { + this.objectSource = null; for ( Iterator it = and.getChildren().iterator(); it.hasNext(); ) { Object object = it.next(); @@ -222,7 +224,7 @@ private BetaNodeBinder attachColumn(Column column, ConditionalElement parent) { - addDeclarations( column ); +// addDeclarations( column ); List predicates = attachAlphaNodes( column ); @@ -237,20 +239,20 @@ return binder; } - private void addDeclarations(Column column) { - for ( Iterator it = column.getDeclarations().iterator(); it.hasNext(); ) { - Declaration declaration = (Declaration) it.next(); - this.declarations.put( declaration.getIdentifier(), - declaration ); - } +// private void addDeclarations(Column column) { +// for ( Iterator it = column.getDeclarations().iterator(); it.hasNext(); ) { +// Declaration declaration = (Declaration) it.next(); +// this.declarations.put( declaration.getIdentifier(), +// declaration ); +// } +// +// if ( column.getBinding() != null ) { +// Binding binding = column.getBinding(); +// this.declarations.put( binding.getIdentifier(), +// binding ); +// } +// } - if ( column.getBinding() != null ) { - Binding binding = column.getBinding(); - this.declarations.put( binding.getIdentifier(), - binding ); - } - } - public List attachAlphaNodes(Column column) { List constraints = column.getConstraints(); Modified: trunk/labs/jbossrules/drools-core/src/main/java/org/drools/reteoo/ObjectTypeNode.java =================================================================== --- trunk/labs/jbossrules/drools-core/src/main/java/org/drools/reteoo/ObjectTypeNode.java 2006-01-08 23:45:28 UTC (rev 2027) +++ trunk/labs/jbossrules/drools-core/src/main/java/org/drools/reteoo/ObjectTypeNode.java 2006-01-09 02:07:00 UTC (rev 2028) @@ -218,6 +218,10 @@ return new PrimitiveLongMap( 32, 8 ); } + + public String toString() { + return "[ObjectTypeNode objectType=" + this.objectType + "]"; + } public boolean equals(Object object) { if ( this == object ) { @@ -228,6 +232,10 @@ return false; } - return this.objectType.equals( ((ObjectTypeNode) object).getObjectType() ); + return this.objectType.equals( this.objectType ); } + + public int hashCode() { + return this.objectType.hashCode(); + } } Added: trunk/labs/jbossrules/drools-core/src/main/java/org/drools/reteoo/ReteooToJungVisitor.java =================================================================== --- trunk/labs/jbossrules/drools-core/src/main/java/org/drools/reteoo/ReteooToJungVisitor.java 2006-01-08 23:45:28 UTC (rev 2027) +++ trunk/labs/jbossrules/drools-core/src/main/java/org/drools/reteoo/ReteooToJungVisitor.java 2006-01-09 02:07:00 UTC (rev 2028) @@ -0,0 +1,545 @@ +package org.drools.reteoo; + +/* + * $Id: ReteooToJungVisitor.java,v 1.11 2005/02/02 00:23:22 mproctor Exp $ + * + * Copyright 2004-2004 (C) The Werken Company. All Rights Reserved. + * + * Redistribution and use of this software and associated documentation + * ("Software"), with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain copyright statements and + * notices. Redistributions must also contain a copy of this document. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The name "drools" must not be used to endorse or promote products derived + * from this Software without prior written permission of The Werken Company. + * For written permission, please contact bo...@we.... + * + * 4. Products derived from this Software may not be called "drools" nor may + * "drools" appear in their names without prior written permission of The Werken + * Company. "drools" is a trademark of The Werken Company. + * + * 5. Due credit should be given to The Werken Company. (http://werken.com/) + * + * THIS SOFTWARE IS PROVIDED BY THE WERKEN COMPANY AND CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE WERKEN COMPANY OR ITS CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + */ + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Map; +import java.util.Set; + +import edu.uci.ics.jung.graph.Graph; +import edu.uci.ics.jung.graph.Vertex; +import edu.uci.ics.jung.graph.impl.DirectedSparseEdge; +import edu.uci.ics.jung.graph.impl.DirectedSparseGraph; +import edu.uci.ics.jung.graph.impl.DirectedSparseVertex; +import edu.uci.ics.jung.graph.impl.SparseGraph; +import edu.uci.ics.jung.graph.impl.UndirectedSparseEdge; +import edu.uci.ics.jung.visualization.VisualizationViewer; +import org.drools.ReteooJungViewer.HtmlContent; + +/** + * Produces a graph in GraphViz DOT format. + * + * @see http://www.research.att.com/sw/tools/graphviz/ + * @see http://www.pixelglow.com/graphviz/ + * + * @author Andy Barnett + */ +public class ReteooToJungVisitor extends ReflectiveVisitor { + /** String displayed for Null values. */ + private static final String NULL_STRING = "<NULL>"; + + /** Amount of indention for Node and Edge lines. */ + private static final String INDENT = " "; + + /** + * Keeps track of visited JoinNode DOT IDs. This mapping allows the visitor + * to recognize JoinNodes it has already visited and as a consequence link + * existing nodes back together. This is vital to the Visitor being able to + * link two JoinNodeInputs together through their common JoinNode. + */ + private Map visitedNodes = new HashMap(); + + Graph graph; + + VisualizationViewer vv; + + Vertex rootVertex; + + Vertex parentVertex; + + /** + * Constructor. + */ + public ReteooToJungVisitor() { + } + + public Graph getGraph() { + return this.graph; + } + + /** + * Default visitor if an unknown object is visited. + */ + public void visitObject(Object object) { + Vertex vertex = this.graph.addVertex( new UnkownVertex() ); + this.graph.addEdge( new DroolsDirectedEdge( this.parentVertex, + vertex ) ); + } + + /** + * Null visitor if a NULL object gets visited. Unique String objects are + * generated to ensure every NULL object is distinct. + */ + public void visitNull() { + Vertex vertex = this.graph.addVertex( new UnkownVertex() ); + this.graph.addEdge( new DroolsDirectedEdge( this.parentVertex, + vertex ) ); + } + + /** + * RuleBaseImpl visits its Rete. + */ + public void visitRuleBaseImpl(RuleBaseImpl ruleBase) { + visit( ((RuleBaseImpl) ruleBase).getRete() ); + } + + /** + * Rete visits each of its ObjectTypeNodes. + */ + public void visitRete(Rete rete) { + this.rootVertex = (ReteNodeVertex) this.visitedNodes.get( dotId( rete ) ); + if ( this.rootVertex == null ) { + this.rootVertex = new ReteNodeVertex( rete ); + this.visitedNodes.put( dotId( rete ), + this.rootVertex ); + } + + this.graph = new DirectedSparseGraph(); + this.graph.addVertex( this.rootVertex ); + this.parentVertex = this.rootVertex; + for ( Iterator i = rete.getObjectTypeNodeIterator(); i.hasNext(); ) { + Object nextNode = i.next(); + visitNode( nextNode ); + } + } + + /** + * ObjectTypeNode displays its objectType and then visits each of its + * ParameterNodes. + */ + public void visitObjectTypeNode(ObjectTypeNode node) { + Vertex vertex = (ObjectTypeNodeVertex) this.visitedNodes.get( dotId( node ) ); + if ( vertex == null ) { + vertex = new ObjectTypeNodeVertex( node ); + this.graph.addVertex( vertex ); + this.visitedNodes.put( dotId( node ), + vertex ); + this.graph.addEdge( new DroolsDirectedEdge( this.parentVertex, + vertex ) ); + Vertex oldParentVertex = this.parentVertex; + this.parentVertex = vertex; + + //makeNode( node, + // "ObjectTypeNode", + // "objectType: " + node.getObjectType( ) ); + for ( Iterator i = node.getObjectSinks().iterator(); i.hasNext(); ) { + Object nextNode = i.next(); + visitNode( nextNode ); + } + this.parentVertex = oldParentVertex; + } else { + this.graph.addEdge( new DroolsDirectedEdge( this.parentVertex, + vertex ) ); + } + } + + public void visitAlphaNode(AlphaNode node) { + Vertex vertex = (AlphaNodeVertex) this.visitedNodes.get( dotId( node ) ); + if ( vertex == null ) { + vertex = new AlphaNodeVertex( node ); + this.graph.addVertex( vertex ); + this.visitedNodes.put( dotId( node ), + vertex ); + this.graph.addEdge( new DroolsDirectedEdge( this.parentVertex, + vertex ) ); + Vertex oldParentVertex = this.parentVertex; + this.parentVertex = vertex; + + for ( Iterator i = node.getObjectSinks().iterator(); i.hasNext(); ) { + Object nextNode = i.next(); + visitNode( nextNode ); + } + this.parentVertex = oldParentVertex; + } else { + this.graph.addEdge( new DroolsDirectedEdge( this.parentVertex, + vertex ) ); + } + } + + public void visitRightInputAdapterNode(RightInputAdapterNode node) { + Vertex vertex = (RightInputAdapterNodeVertex) this.visitedNodes.get( dotId( node ) ); + if ( vertex == null ) { + vertex = new RightInputAdapterNodeVertex( node ); + this.graph.addVertex( vertex ); + this.visitedNodes.put( dotId( node ), + vertex ); + this.graph.addEdge( new DroolsDirectedEdge( this.parentVertex, + vertex ) ); + Vertex oldParentVertex = this.parentVertex; + this.parentVertex = vertex; + + for ( Iterator i = node.getObjectSinks().iterator(); i.hasNext(); ) { + Object nextNode = i.next(); + visitNode( nextNode ); + } + this.parentVertex = oldParentVertex; + } else { + this.graph.addEdge( new DroolsDirectedEdge( this.parentVertex, + vertex ) ); + } + } + + public void visitLeftInputAdapterNode(LeftInputAdapterNode node) { + Vertex vertex = (LeftInputAdapterNodeVertex) this.visitedNodes.get( dotId( node ) ); + if ( vertex == null ) { + vertex = new LeftInputAdapterNodeVertex( node ); + this.graph.addVertex( vertex ); + this.visitedNodes.put( dotId( node ), + vertex ); + this.graph.addEdge( new DroolsDirectedEdge( this.parentVertex, + vertex ) ); + Vertex oldParentVertex = this.parentVertex; + this.parentVertex = vertex; + + for ( Iterator i = node.getTupleSinks().iterator(); i.hasNext(); ) { + Object nextNode = i.next(); + visitNode( nextNode ); + } + this.parentVertex = oldParentVertex; + } else { + this.graph.addEdge( new DroolsDirectedEdge( this.parentVertex, + vertex ) ); + } + } + + public void visitJoinNode(JoinNode node) { + Vertex vertex = (JoinNodeVertex) this.visitedNodes.get( dotId( node ) ); + if ( vertex == null ) { + vertex = new JoinNodeVertex( node ); + this.graph.addVertex( vertex ); + this.visitedNodes.put( dotId( node ), + vertex ); + this.graph.addEdge( new DroolsDirectedEdge( this.parentVertex, + vertex ) ); + Vertex oldParentVertex = this.parentVertex; + this.parentVertex = vertex; + + for ( Iterator i = node.getTupleSinks().iterator(); i.hasNext(); ) { + Object nextNode = i.next(); + visitNode( nextNode ); + } + this.parentVertex = oldParentVertex; + } else { + this.graph.addEdge( new DroolsDirectedEdge( this.parentVertex, + vertex ) ); + } + } + + public void visitNotNode(NotNode node) { + Vertex vertex = (NotNodeVertex) this.visitedNodes.get( dotId( node ) ); + if ( vertex == null ) { + vertex = new NotNodeVertex( node ); + this.graph.addVertex( vertex ); + this.visitedNodes.put( dotId( node ), + vertex ); + this.graph.addEdge( new DroolsDirectedEdge( this.parentVertex, + vertex ) ); + Vertex oldParentVertex = this.parentVertex; + this.parentVertex = vertex; + + for ( Iterator i = node.getTupleSinks().iterator(); i.hasNext(); ) { + Object nextNode = i.next(); + visitNode( nextNode ); + } + this.parentVertex = oldParentVertex; + } else { + this.graph.addEdge( new DroolsDirectedEdge( this.parentVertex, + vertex ) ); + } + } + + public void visitTestNode(TestNode node) { + Vertex vertex = (TestNodeVertex) this.visitedNodes.get( dotId( node ) ); + if ( vertex == null ) { + vertex = new TestNodeVertex( node ); + this.graph.addVertex( vertex ); + this.visitedNodes.put( dotId( node ), + vertex ); + this.graph.addEdge( new DroolsDirectedEdge( this.parentVertex, + vertex ) ); + Vertex oldParentVertex = this.parentVertex; + this.parentVertex = vertex; + + for ( Iterator i = node.getTupleSinks().iterator(); i.hasNext(); ) { + Object nextNode = i.next(); + visitNode( nextNode ); + } + this.parentVertex = oldParentVertex; + } else { + this.graph.addEdge( new DroolsDirectedEdge( this.parentVertex, + vertex ) ); + } + } + + // /** + // * ConditionNode displays its condition and tuple Declarations and then + // * visits its TupleSink. + // */ + // public void visitConditionNode(ConditionNode node) + // { + // makeTupleSourceNode( node, + // "ConditionNode", + // "TupleSource/TupleSink", + // "condition: " + node.getCondition( ) + newline + format( node.getTupleDeclarations( ), + // "tuple" ) ); + // } + + /** + * TerminalNode displays its rule. + */ + public void visitTerminalNode(TerminalNode node) { + Vertex vertex = this.graph.addVertex( new TerminalNodeVertex( node ) ); + this.graph.addEdge( new DroolsDirectedEdge( this.parentVertex, + vertex ) ); + + // makeNode( node, + // "TerminalNode", + // "TupleSink", + // "rule: " + node.getRule( ).getName( ) ); + } + + /** + * Helper method to ensure nodes are not visited more than once. + */ + private void visitNode(Object node) { + visit( node ); + } + + /** + * The identity hashCode for the given object is used as its unique DOT + * identifier. + */ + private static String dotId(Object object) { + return Integer.toHexString( System.identityHashCode( object ) ).toUpperCase(); + } + + class DroolsDirectedEdge extends DirectedSparseEdge { + public DroolsDirectedEdge(Vertex v1, + Vertex v2) { + super( v1, + v2 ); + } + + // public String toString() { + // return null; + // } + } + + class ReteNodeVertex extends ReteooNodeVertex { + private final Rete node; + + public ReteNodeVertex(Rete node) { + super(); + this.node = node; + } + + public String getHtml() { + return "Rete : " + this.node.getId(); + } + + public String toString() { + return "Rete"; + } + } + + class ObjectTypeNodeVertex extends ReteooNodeVertex { + private final ObjectTypeNode node; + + public ObjectTypeNodeVertex(ObjectTypeNode node) { + super(); + this.node = node; + } + + public String getHtml() { + return "ObjectTypeNode : " + this.node.getId(); + } + + public String toString() { + return "ObjectTypeNode"; + } + } + + class AlphaNodeVertex extends ReteooNodeVertex { + private final AlphaNode node; + + public AlphaNodeVertex(AlphaNode node) { + super(); + this.node = node; + } + + public String getHtml() { + return "AlphaNode : " + this.node.getId(); + } + + public String toString() { + return "AlphaNode"; + } + } + + class LeftInputAdapterNodeVertex extends ReteooNodeVertex { + private final LeftInputAdapterNode node; + + public LeftInputAdapterNodeVertex(LeftInputAdapterNode node) { + super(); + this.node = node; + } + + public String getHtml() { + return "LeftInputAdapterNode : " + this.node.getId(); + } + + public String toString() { + return "leftInputAdapter"; + } + } + + class RightInputAdapterNodeVertex extends ReteooNodeVertex { + private final RightInputAdapterNode node; + + public RightInputAdapterNodeVertex(RightInputAdapterNode node) { + super(); + this.node = node; + } + + public String getHtml() { + return "RightInputAdapterNodeVertex : " + this.node.getId(); + } + + public String toString() { + return "RightInputAdapterNodeVertex"; + } + } + + class JoinNodeVertex extends ReteooNodeVertex { + private final JoinNode node; + + public JoinNodeVertex(JoinNode node) { + super(); + this.node = node; + } + + public String getHtml() { + return "JoinNode : " + this.node.getId(); + } + + public String toString() { + return "JoinNode"; + } + } + + class NotNodeVertex extends ReteooNodeVertex { + private final NotNode node; + + public NotNodeVertex(NotNode node) { + super(); + this.node = node; + } + + public String getHtml() { + return "NotNode : " + this.node.getId(); + } + + public String toString() { + return "NotNode"; + } + } + + class TestNodeVertex extends ReteooNodeVertex { + private final TestNode node; + + public TestNodeVertex(TestNode node) { + super(); + this.node = node; + } + + public String getHtml() { + return "TestNode : " + this.node.getId(); + } + + public String toString() { + return "TestNode"; + } + } + + class TerminalNodeVertex extends ReteooNodeVertex { + private final TerminalNode node; + + public TerminalNodeVertex(TerminalNode node) { + super(); + this.node = node; + } + + public String getHtml() { + return "TerminalNode : " + this.node.getId(); + } + + public String toString() { + return "TerminalNode"; + } + } + + class UnkownVertex extends ReteooNodeVertex { + + public UnkownVertex() { + super(); + } + + public String getHtml() { + return "Uknown"; + } + + public String toString() { + return "Unknown"; + } + } + + public static abstract class ReteooNodeVertex extends DirectedSparseVertex + implements + HtmlContent { + public ReteooNodeVertex() { + super(); + } + + public abstract String getHtml(); + } +} Modified: trunk/labs/jbossrules/drools-core/src/main/java/org/drools/reteoo/TerminalNode.java =================================================================== --- trunk/labs/jbossrules/drools-core/src/main/java/org/drools/reteoo/TerminalNode.java 2006-01-08 23:45:28 UTC (rev 2027) +++ trunk/labs/jbossrules/drools-core/src/main/java/org/drools/reteoo/TerminalNode.java 2006-01-09 02:07:00 UTC (rev 2028) @@ -53,7 +53,7 @@ * * @author <a href="mailto:bo...@en...">bob mcwhirter </a> */ -final class TerminalNode +final class TerminalNode extends BaseNode implements TupleSink { // ------------------------------------------------------------ @@ -75,8 +75,10 @@ * @param rule * The rule. */ - TerminalNode(TupleSource inputSource, + TerminalNode(int id, + TupleSource inputSource, Rule rule) { + super(id); this.rule = rule; inputSource.addTupleSink( this ); @@ -143,4 +145,20 @@ // TODO Auto-generated method stub } + + public void attach() { + // TODO Auto-generated method stub + + } + + public void remove() { + // TODO Auto-generated method stub + + } + + public void updateNewNode(WorkingMemoryImpl workingMemory, + PropagationContext context) throws FactException { + // TODO Auto-generated method stub + + } } Modified: trunk/labs/jbossrules/drools-core/src/main/java/org/drools/rule/Column.java =================================================================== --- trunk/labs/jbossrules/drools-core/src/main/java/org/drools/rule/Column.java 2006-01-08 23:45:28 UTC (rev 2027) +++ trunk/labs/jbossrules/drools-core/src/main/java/org/drools/rule/Column.java 2006-01-09 02:07:00 UTC (rev 2028) @@ -8,8 +8,7 @@ public class Column { private final ObjectType objectType; - private List constraints = Collections.EMPTY_LIST; - private List declarations = Collections.EMPTY_LIST; + private List constraints = Collections.EMPTY_LIST; private final ColumnBinding binding; private final int index; @@ -40,17 +39,6 @@ return this.objectType; } - public List getDeclarations() { - return Collections.unmodifiableList( this.declarations ); - } - - public void addDeclaration(Declaration declaration) { - if ( this.declarations == Collections.EMPTY_LIST ) { - this.declarations = new ArrayList( 1 ); - } - this.declarations.add( declaration ); - } - public List getConstraints() { return Collections.unmodifiableList( this.constraints ); } Modified: trunk/labs/jbossrules/drools-core/src/main/java/org/drools/rule/Rule.java =================================================================== --- trunk/labs/jbossrules/drools-core/src/main/java/org/drools/rule/Rule.java 2006-01-08 23:45:28 UTC (rev 2027) +++ trunk/labs/jbossrules/drools-core/src/main/java/org/drools/rule/Rule.java 2006-01-09 02:07:00 UTC (rev 2028) @@ -519,5 +519,28 @@ public String getModule() { return this.module; } + + public String toString() { + return "[Rule name=" + this.name + ", module=" + this.module + ", salience=" + this.salience + ", no-loop=" + this.noLoop + "]"; + } + + public boolean equals(Object object) { + if ( this == object ) { + return true; + } + + if (object == null||!(object instanceof Rule)) { + return false; + } + + Rule other = (Rule) object; + + return (this.name.equals(other.name) && this.module.equals( other.module ) && this.salience == other.salience && this.noLoop == other.noLoop); + } + + public int hashCode() { + return this.name.hashCode(); + } + } Modified: trunk/labs/jbossrules/drools-core/src/main/java/org/drools/rule/RuleSet.java =================================================================== --- trunk/labs/jbossrules/drools-core/src/main/java/org/drools/rule/RuleSet.java 2006-01-08 23:45:28 UTC (rev 2027) +++ trunk/labs/jbossrules/drools-core/src/main/java/org/drools/rule/RuleSet.java 2006-01-09 02:07:00 UTC (rev 2028) @@ -266,4 +266,26 @@ public RuleBaseContext getRuleBaseContext() { return this.ruleBaseContext; } + + public String toString() { + return "[RuleSet name=" + this.name + "]"; + } + + public boolean equals(Object object) { + if ( this == object ) { + return true; + } + + if (object == null||!(object instanceof RuleSet)) { + return false; + } + + RuleSet other = (RuleSet) object; + + return (this.name.equals(other.name)); + } + + public int hashCode() { + return this.name.hashCode(); + } } Modified: trunk/labs/jbossrules/drools-core/src/main/java/org/drools/spi/ClassObjectType.java =================================================================== --- trunk/labs/jbossrules/drools-core/src/main/java/org/drools/spi/ClassObjectType.java 2006-01-08 23:45:28 UTC (rev 2027) +++ trunk/labs/jbossrules/drools-core/src/main/java/org/drools/spi/ClassObjectType.java 2006-01-09 02:07:00 UTC (rev 2028) @@ -115,15 +115,6 @@ // java.lang.Object // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - /** - * Produce the hash of this object. - * - * @return The hash. - */ - public int hashCode() { - return getClassType().hashCode(); - } - protected void setValueType(Class clazz) { if ( clazz == Character.class ) { this.valueType = Evaluator.CHAR_TYPE; @@ -147,6 +138,10 @@ this.valueType = Evaluator.OBJECT_TYPE; } } + + public String toString() { + return "[ClassObjectType class=" + getClassType().getName() + "]"; + } /** * Determine if another object is equal to this. @@ -168,8 +163,10 @@ return this.objectTypeClass == ( (ClassObjectType) object).objectTypeClass; } - - public String toString() { - return getClassType().getName(); + + public int hashCode() { + return this.objectTypeClass.hashCode(); } + + } Modified: trunk/labs/jbossrules/drools-core/src/test/java/org/drools/event/WorkingMemoryEventSupportTest.java =================================================================== --- trunk/labs/jbossrules/drools-core/src/test/java/org/drools/event/WorkingMemoryEventSupportTest.java 2006-01-08 23:45:28 UTC (rev 2027) +++ trunk/labs/jbossrules/drools-core/src/test/java/org/drools/event/WorkingMemoryEventSupportTest.java 2006-01-09 02:07:00 UTC (rev 2028) @@ -12,5 +12,5 @@ assertTrue( Serializable.class.isAssignableFrom( WorkingMemoryEventSupport.class ) ); } - // TODO: Need more tests but I'm tired! Need sleep. + // TODO: Need more tests but I'M tired! Need sleep. } \ No newline at end of file Modified: trunk/labs/jbossrules/drools-core/src/test/java/org/drools/examples/manners/Context.java =================================================================== --- trunk/labs/jbossrules/drools-core/src/test/java/org/drools/examples/manners/Context.java 2006-01-08 23:45:28 UTC (rev 2027) +++ trunk/labs/jbossrules/drools-core/src/test/java/org/drools/examples/manners/Context.java 2006-01-09 02:07:00 UTC (rev 2028) @@ -51,11 +51,17 @@ public static final int ASSIGN_SEATS = 1; public static final int MAKE_PATH = 2; public static final int CHECK_DONE = 3; - public static final int PRINT_RESULTS = 4; - + public static final int PRINT_RESULTS = 4; + private int state; - //private Path path; + public Context(String state) { + if ("start".equals( state ) ) { + this.state = Context.START_UP; + } else { + throw new RuntimeException("Context '" + state + "' does not exist for Context Enum" ); + } + } public Context(int state) { this.state = state; @@ -71,9 +77,25 @@ public int getState() { return this.state; - } + } + + public String getStringValue() { + switch (this.state) { + case 0: + return "START_UP"; + case 1: + return "ASSIGN_SEATS"; + case 2: + return "MAKE_PATH"; + case 3: + return "CHECK_DONE"; + case 4: + return "PRINT_RESULTS"; + } + return ""; + } public String toString() { - return "{state=" + this.state + "}"; + return "[Context state=" + getStringValue() + "]"; } } \ No newline at end of file Modified: trunk/labs/jbossrules/drools-core/src/test/java/org/drools/examples/manners/Guest.java =================================================================== --- trunk/labs/jbossrules/drools-core/src/test/java/org/drools/examples/manners/Guest.java 2006-01-08 23:45:28 UTC (rev 2027) +++ trunk/labs/jbossrules/drools-core/src/test/java/org/drools/examples/manners/Guest.java 2006-01-09 02:07:00 UTC (rev 2028) @@ -75,6 +75,6 @@ } public String toString() { - return "{name=" + this.name + ",sex=" + this.sex + ",hobbies=" + this.hobby + "}"; + return "[Guest name=" + this.name + ", sex=" + this.sex + ", hobbies=" + this.hobby + "]"; } } \ No newline at end of file Modified: trunk/labs/jbossrules/drools-core/src/test/java/org/drools/examples/manners/Hobby.java =================================================================== --- trunk/labs/jbossrules/drools-core/src/test/java/org/drools/examples/manners/Hobby.java 2006-01-08 23:45:28 UTC (rev 2027) +++ trunk/labs/jbossrules/drools-core/src/test/java/org/drools/examples/manners/Hobby.java 2006-01-09 02:07:00 UTC (rev 2028) @@ -1,9 +1,9 @@ package org.drools.examples.manners; public class Hobby { - public static final Hobby h1 = new Hobby( 1 ); - public static final Hobby h2 = new Hobby( 2 ); - public static final Hobby h3 = new Hobby( 3 ); + public static final Hobby H1 = new Hobby( 1 ); + public static final Hobby H2 = new Hobby( 2 ); + public static final Hobby H3 = new Hobby( 3 ); public static final String stringH1 = "h1"; public static final String stringH2 = "h2"; @@ -15,7 +15,7 @@ this.hobby = hobby; } - public String getValue() { + public String getHobby() { switch ( this.hobby ) { case 1 : return stringH1; @@ -28,8 +28,20 @@ } } + public static Hobby resolve(String hobby) { + if (stringH1.equals( hobby ) ) { + return Hobby.H1; + } else if (stringH2.equals( hobby ) ) { + return Hobby.H2; + } else if (stringH3.equals( hobby ) ) { + return Hobby.H3; + } else { + throw new RuntimeException("Hobby '" + hobby + "' does not exist for Hobby Enum" ); + } + } + public String toString() { - return getValue(); + return getHobby(); } public boolean equals(Object object) { Modified: trunk/labs/jbossrules/drools-core/src/test/java/org/drools/examples/manners/LastSeat.java =================================================================== --- trunk/labs/jbossrules/drools-core/src/test/java/org/drools/examples/manners/LastSeat.java 2006-01-08 23:45:28 UTC (rev 2027) +++ trunk/labs/jbossrules/drools-core/src/test/java/org/drools/examples/manners/LastSeat.java 2006-01-09 02:07:00 UTC (rev 2028) @@ -57,6 +57,6 @@ } public String toString() { - return "{seat=" + this.seat + "}"; + return "[LastSeat seat=" + this.seat + "]"; } } \ No newline at end of file Modified: trunk/labs/jbossrules/drools-core/src/test/java/org/drools/examples/manners/MannersTest.java =================================================================== --- trunk/labs/jbossrules/drools-core/src/test/java/org/drools/examples/manners/MannersTest.java 2006-01-08 23:45:28 UTC (rev 2027) +++ trunk/labs/jbossrules/drools-core/src/test/java/org/drools/examples/manners/MannersTest.java 2006-01-09 02:07:00 UTC (rev 2028) @@ -11,6 +11,7 @@ import java.io.StringWriter; import java.util.ArrayList; import java.util.HashMap; +import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Random; @@ -20,6 +21,7 @@ import org.drools.Cheese; import org.drools.FactException; +import org.drools.ReteooJungViewer; import org.drools.RuleBase; import org.drools.RuleIntegrationException; import org.drools.RuleSetIntegrationException; @@ -106,9 +108,9 @@ this.booleanNotEqualEvaluator = EvaluatorFactory.getInstance().getEvaluator( Evaluator.BOOLEAN_TYPE, Evaluator.NOT_EQUAL ); - } + } - public void test1() throws DuplicateRuleNameException, InvalidRuleException, IntrospectionException, RuleIntegrationException, RuleSetIntegrationException, InvalidPatternException, FactException { + public void test1() throws DuplicateRuleNameException, InvalidRuleException, IntrospectionException, RuleIntegrationException, RuleSetIntegrationException, InvalidPatternException, FactException, IOException, InterruptedException { RuleSet ruleSet = new RuleSet( "Miss Manners" ); ruleSet.addRule( getAssignFirstSeatRule() ); // ruleSet.addRule( getMakePath() ); @@ -118,17 +120,34 @@ // ruleSet.addRule( getContinueProcessing() ); // ruleSet.addRule( getAllDone() ); - RuleBaseImpl ruleBase = new RuleBaseImpl(); + final RuleBaseImpl ruleBase = new RuleBaseImpl(); ruleBase.addRuleSet( ruleSet ); - WorkingMemory workingMemory = ruleBase.newWorkingMemory(); - workingMemory.assertObject( new Context( Context.START_UP ) ); - workingMemory.assertObject( new Guest("mark", Sex.m, Hobby.h1) ); - workingMemory.assertObject( new Count(0) ); + javax.swing.SwingUtilities.invokeLater(new Runnable() { + public void run() { + ReteooJungViewer.createAndShowGUI(ruleBase); + } + }); - workingMemory.fireAllRules(); + while (true) { + Thread.sleep( 1000 ); + } - System.out.println( "ttt" ); + +// +// WorkingMemory workingMemory = ruleBase.newWorkingMemory(); +// +// InputStream is = getClass().getResourceAsStream( "/manners16.dat" ); +// List list = getInputObjects(is); +// for (Iterator it = list.iterator(); it.hasNext(); ) { +// workingMemory.assertObject( it.next() ); +// } +// //System.out.println( list ); +// +// workingMemory.assertObject( new Count(0) ); +// +// workingMemory.fireAllRules(); + } /** @@ -234,7 +253,7 @@ context.setState( Context.ASSIGN_SEATS ); drools.modifyObject( tuple.getFactHandleForDeclaration( contextDeclaration ), context ); - System.out.println( "assigned first seat : " + guestName ); + System.out.println( "assigned first seat : " + guest ); } catch ( Exception e ) { throw new ConsequenceException( e ); @@ -368,9 +387,13 @@ String guestName = (String) tuple.get( pathGuestNameDeclaration ); int seat = ((Integer) tuple.get( pathSeatDeclaration )).intValue(); - drools.assertObject( new Path( id, - seat, - guestName ) ); + Path path = new Path( id, + seat, + guestName ); + + drools.assertObject( path ); + + System.out.println( path ); } catch ( Exception e ) { throw new ConsequenceException( e ); } @@ -396,7 +419,7 @@ * when { * context : Context( state == Context.ASSIGN_SEATS ) * Seating( seatingId:id, seatingPid:pid, pathDone == true - * seatingRightGuestName:rightGuestName ) + * seatingRightSeat:rightSeat seatingRightGuestName:rightGuestName ) * Guest( name == seatingRightGuestName, rightGuestSex:sex, rightGuestHobby:hobby ) * Guest( leftGuestName:name , sex != rightGuestSex, hobby == rightGuestHobby ) * @@ -444,8 +467,7 @@ // ------------------------------- // Seating( seatingId:id, seatingPid:pid, pathDone == true - // seatingRightSeat:rightSeat - // seatingRightGuestName:rightGuestName ) + // seatingRightSeat:rightSeat seatingRightGuestName:rightGuestName ) // ------------------------------- Column seatingColumn = new Column( 1, seatingType ); @@ -474,8 +496,7 @@ final Declaration seatingRightGuestNameDeclaration = rule.getDeclaration( "seatingRightGuestName" ); final Declaration seatingRightSeatDeclaration = rule.getDeclaration( "seatingRightSeat" ); // -------------- - // Guest( name == seatingRightGuestName, rightGuestSex:sex, - // rightGuestHobby:hobby ) + // Guest( name == seatingRightGuestName, rightGuestSex:sex, rightGuestHobby:hobby ) // --------------- Column rightGuestColumn = new Column( 2, guestType ); @@ -533,7 +554,6 @@ // -------------- // not ( Path( id == seatingId, guestName == leftGuestName) ) - // not ( Chosen( id == seatingId, guestName == leftGuestName, hobby == rightGuestHobby) ) // -------------- Column notPathColumn = new Column( 3, pathType ); @@ -549,7 +569,7 @@ objectEqualEvaluator ) ); Not notPath = new Not(); notPath.addChild( notPathColumn ); - notPathColumn.addConstraint( notPath ); + rule.addPattern( notPath ); // ------------ // not ( Chosen( id == seatingId, guestName == leftGuestName, hobby == rightGuestHobby ) ) // ------------ @@ -606,13 +626,14 @@ String rightGuestName = (String) tuple.get( seatingRightGuestNameDeclaration ); Hobby rightGuestHobby = (Hobby) tuple.get( rightGuestHobbyDeclaration ); - drools.assertObject( new Seating( count.getValue(), - seatId, - false, - seatingRightSeat, - leftGuestName, - seatingRightSeat + 1, - rightGuestName ) ); + Seating seating = new Seating( count.getValue(), + seatId, + false, + seatingRightSeat, + leftGuestName, + seatingRightSeat + 1, + rightGuestName ); + drools.assertObject( seating ); drools.assertObject( new Path( count.getValue(), seatingRightSeat + 1, @@ -630,6 +651,8 @@ drools.modifyObject( tuple.getFactHandleForDeclaration( contextDeclaration ), context ); + System.out.println( seating ); + } catch ( Exception e ) { throw new ConsequenceException( e ); } @@ -938,80 +961,74 @@ return rule; } -// /** -// * Convert the facts from the <code>InputStream</code> to a list of -// * objects. -// */ -// private List getInputObjects(InputStream inputStream) throws IOException -// { -// List list = new ArrayList( ); -// -// BufferedReader br = new BufferedReader( new InputStreamReader( inputStream ) ); -// -// String line; -// while ( (line = br.readLine( )) != null ) -// { -// if ( line.trim( ).length( ) == 0 || line.trim( ).startsWith( ";" ) ) -// { -// continue; -// } -// StringTokenizer st = new StringTokenizer( line, -// "() " ); -// String type = st.nextToken( ); -// -// if ( "guest".equals( type ) ) -// { -// if ( !"name".equals( st.nextToken( ) ) ) -// { -// throw new IOException( "expected 'name' in: " + line ); -// } -// String name = st.nextToken( ); -// if ( !"sex".equals( st.nextToken( ) ) ) -// { -// throw new IOException( "expected 'sex' in: " + line ); -// } -// String sex = st.nextToken( ); -// if ( !"hobby".equals( st.nextToken( ) ) ) -// { -// throw new IOException( "expected 'hobby' in: " + line ); -// } -// String hobby = st.nextToken( ); -// -// Guest guest = (Guest) guests.get( name ); -// if ( guest == null ) -// { -// guest = new Guest( name, -// sex.charAt( 0 ) -// Hobby); -// guests.put( name, -// guest ); -// list.add( guest ); -// } -// guest.addHobby( hobby ); -// } -// -// if ( "last_seat".equals( type ) ) -// { -// if ( !"seat".equals( st.nextToken( ) ) ) -// { -// throw new IOException( "expected 'seat' in: " + line ); -// } -// list.add( new LastSeat( new Integer( st.nextToken( ) ).intValue( ) ) ); -// } -// -// if ( "context".equals( type ) ) -// { -// if ( !"state".equals( st.nextToken( ) ) ) -// { -// throw new IOException( "expected 'state' in: " + line ); -// } -// list.add( new Context( st.nextToken( ) ) ); -// } -// } -// inputStream.close( ); -// -// return list; -// } + /** + * Convert the facts from the <code>InputStream</code> to a list of + * objects. + */ + private List getInputObjects(InputStream inputStream) throws IOException + { + List list = new ArrayList( ); + + BufferedReader br = new BufferedReader( new InputStreamReader( inputStream ) ); + + String line; + while ( (line = br.readLine( )) != null ) + { + if ( line.trim( ).length( ) == 0 || line.trim( ).startsWith( ";" ) ) + { + continue; + } + StringTokenizer st = new StringTokenizer( line, + "() " ); + String type = st.nextToken( ); + + if ( "guest".equals( type ) ) + { + if ( !"name".equals( st.nextToken( ) ) ) + { + throw new IOException( "expected 'name' in: " + line ); + } + String name = st.nextToken( ); + if ( !"sex".equals( st.nextToken( ) ) ) + { + throw new IOException( "expected 'sex' in: " + line ); + } + String sex = st.nextToken( ); + if ( !"hobby".equals( st.nextToken( ) ) ) + { + throw new IOException( "expected 'hobby' in: " + line ); + } + String hobby = st.nextToken( ); + + Guest guest = new Guest( name, + Sex.resolve(sex), + Hobby.resolve(hobby)); + + list.add( guest ); + } + + if ( "last_seat".equals( type ) ) + { + if ( !"seat".equals( st.nextToken( ) ) ) + { + throw new IOException( "expected 'seat' in: " + line ); + } + list.add( new LastSeat( new Integer( st.nextToken( ) ).intValue( ) ) ); + } + + if ( "context".equals( type ) ) + { + if ( !"state".equals( st.nextToken( ) ) ) + { + throw new IOException( "expected 'state' in: " + line ); + } + list.add( new Context( st.nextToken( ) ) ); + } + } + inputStream.close( ); + + return list; + } private InputStream generateData() { final String LINE_SEPARATOR = System.getProperty( "line.separator" ); Modified: trunk/labs/jbossrules/drools-core/src/test/java/org/drools/examples/manners/Path.java =================================================================== --- trunk/labs/jbossrules/drools-core/src/test/java/org/drools/examples/manners/Path.java 2006-01-08 23:45:28 UTC (rev 2027) +++ trunk/labs/jbossrules/drools-core/src/test/java/org/drools/examples/manners/Path.java 2006-01-09 02:07:00 UTC (rev 2028) @@ -23,6 +23,9 @@ return this.id; } + public String toString() { + return "[Path id=" + this.id + ", seat=" + this.seat + ", guest=" + this.guestName + "]"; + } } Deleted: trunk/labs/jbossrules/drools-core/src/test/java/org/drools/examples/manners/Seat.java =================================================================== --- trunk/labs/jbossrules/drools-core/src/test/java/org/drools/examples/manners/Seat.java 2006-01-08 23:45:28 UTC (rev 2027) +++ trunk/labs/jbossrules/drools-core/src/test/java/org/drools/examples/manner... [truncated message content] |