[Pfc-prolog-cvs] prolix/src/org/asturlinux/frade/prolix/ejb/sessionjb CheckSolutionVisitor.java,NONE
Status: Beta
Brought to you by:
ivanfrade
From: <iva...@us...> - 2003-07-20 17:55:07
|
Update of /cvsroot/pfc-prolog/prolix/src/org/asturlinux/frade/prolix/ejb/sessionjb In directory sc8-pr-cvs1:/tmp/cvs-serv8802/src/org/asturlinux/frade/prolix/ejb/sessionjb Modified Files: ProlixMainBean.java Added Files: CheckSolutionVisitor.java Log Message: refactored step method - Added new visitor class - added method visitLastNode --- NEW FILE: CheckSolutionVisitor.java --- package org.asturlinux.frade.prolix.ejb.sessionjb; import org.asturlinux.frade.prolix.interpreter.interfaces.*; public class CheckSolutionVisitor extends TreeElementVisitor { private boolean _isSolution; public void visitTreeElement(TreeElement te) { _isSolution = te.isSolution(); } public boolean getIsSolution() { return _isSolution; } } Index: ProlixMainBean.java =================================================================== RCS file: /cvsroot/pfc-prolog/prolix/src/org/asturlinux/frade/prolix/ejb/sessionjb/ProlixMainBean.java,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** ProlixMainBean.java 20 Jul 2003 15:18:27 -0000 1.22 --- ProlixMainBean.java 20 Jul 2003 17:55:01 -0000 1.23 *************** *** 134,137 **** --- 134,159 ---- } + + /** + * @ejb:interface-method + */ + public String nextSolution() + throws ProgramNotLoadedException, QueryNotLoadedException + { + CheckSolutionVisitor visitor = new CheckSolutionVisitor(); + + TreeElement treeResult = prologCtx.step(); + visitLastNode(treeResult,visitor); + + while (!visitor.getIsSolution()) + { + treeResult = prologCtx.step(); + visitLastNode(treeResult,visitor); + } + + return transformToXml(treeResult); + } + + /** * @ejb:interface-method *************** *** 211,215 **** // process recursively the tree ! recursiveInOrder(tree,visitor); // generate end tag --- 233,237 ---- // process recursively the tree ! visitInOrder(tree,visitor); // generate end tag *************** *** 224,228 **** } ! private void recursiveInOrder(TreeElement tree, SimpleXmlVisitor visitor) { /** --- 246,269 ---- } ! /** ! * Apply visitor to last node in tree ! */ ! private void visitLastNode(TreeElement tree, TreeElementVisitor visitor) ! { ! ! // FIXME: Could be better not use recursivity ! TreeElement[] sons = tree.getNextLevelElements(); ! if (sons.length > 0) ! visitLastNode(sons[sons.length-1],visitor); ! else ! tree.accept(visitor); ! ! return; ! } ! ! /** ! * Apply visitor to all nodes in tree using inorder path ! */ ! private void visitInOrder(TreeElement tree, TreeElementVisitor visitor) { /** *************** *** 237,241 **** { for (int i = 0; i < sons.length; i++) ! recursiveInOrder(sons[i],visitor); } /** --- 278,282 ---- { for (int i = 0; i < sons.length; i++) ! visitInOrder(sons[i],visitor); } /** |