Thread: [Pfc-prolog-cvs] prolix/src/org/asturlinux/frade/prolix/ejb/sessionjb ProlixMainBean.java,1.12,1.13
Status: Beta
Brought to you by:
ivanfrade
From: <iva...@us...> - 2003-07-02 19:33:09
|
Update of /cvsroot/pfc-prolog/prolix/src/org/asturlinux/frade/prolix/ejb/sessionjb In directory sc8-pr-cvs1:/tmp/cvs-serv18862/src/org/asturlinux/frade/prolix/ejb/sessionjb Modified Files: ProlixMainBean.java SimpleXmlVisitor.java Log Message: Fixed minor errors in xml generation Index: ProlixMainBean.java =================================================================== RCS file: /cvsroot/pfc-prolog/prolix/src/org/asturlinux/frade/prolix/ejb/sessionjb/ProlixMainBean.java,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** ProlixMainBean.java 29 Jun 2003 15:33:04 -0000 1.12 --- ProlixMainBean.java 2 Jul 2003 19:33:06 -0000 1.13 *************** *** 51,54 **** --- 51,57 ---- private PrologContextDummy prologCtx; + private String xmlResult = ""; + private int solutionCounter = 1; + /** * @ejb:interface-method *************** *** 134,141 **** throws ProgramNotLoadedException, QueryNotLoadedException { TreeElement resolution = prologCtx.step(); ! String xmlChain = new String(""); ! treeElementToXmlTransformation(resolution,xmlChain); ! return xmlChain; } --- 137,145 ---- throws ProgramNotLoadedException, QueryNotLoadedException { + xmlResult = ""; + solutionCounter = 1; TreeElement resolution = prologCtx.step(); ! treeElementToXmlTransformation(resolution); ! return xmlResult; } *************** *** 169,185 **** ! private void treeElementToXmlTransformation(TreeElement tree, String result) { String xmlOpen = "<results>"; ! result.concat(xmlOpen); ! int solutionCounter = 1; ! recursiveInOrder(tree,result,solutionCounter); String xmlClose = "</results>"; ! result.concat(xmlClose); } ! private void recursiveInOrder(TreeElement tree, String result, int solution) { /** --- 173,190 ---- ! private void treeElementToXmlTransformation(TreeElement tree) { String xmlOpen = "<results>"; ! xmlResult = xmlResult.concat(xmlOpen); ! recursiveInOrder(tree); + if (tree.isCompletlyExplored()) + xmlResult = xmlResult.concat("<result solution=\"no\"/>"); String xmlClose = "</results>"; ! xmlResult = xmlResult.concat(xmlClose); } ! private void recursiveInOrder(TreeElement tree) { /** *************** *** 194,198 **** TreeElement[] sons = tree.getNextLevelElements(); for (int i = 0; i < sons.length; i++) ! recursiveInOrder(sons[i],result,solution); } catch (NullPointerException np) --- 199,203 ---- TreeElement[] sons = tree.getNextLevelElements(); for (int i = 0; i < sons.length; i++) ! recursiveInOrder(sons[i]); } catch (NullPointerException np) *************** *** 201,213 **** /** * node "treatment" using visitor pattern. ! * visitor _add_ node's xml to result. */ System.out.println("Exploring node: " + tree.getQuery()); if (tree.isSolution()) { ! SimpleXmlVisitor visitor = new SimpleXmlVisitor(result,solution); tree.accept(visitor); ! solution++; ! result = visitor.getResult(); } } --- 206,218 ---- /** * node "treatment" using visitor pattern. ! * visitor write node's xml. */ System.out.println("Exploring node: " + tree.getQuery()); if (tree.isSolution()) { ! SimpleXmlVisitor visitor = new SimpleXmlVisitor(solutionCounter); tree.accept(visitor); ! solutionCounter++; ! xmlResult = xmlResult.concat(visitor.getResult()); } } Index: SimpleXmlVisitor.java =================================================================== RCS file: /cvsroot/pfc-prolog/prolix/src/org/asturlinux/frade/prolix/ejb/sessionjb/SimpleXmlVisitor.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** SimpleXmlVisitor.java 23 Jun 2003 19:04:38 -0000 1.2 --- SimpleXmlVisitor.java 2 Jul 2003 19:33:06 -0000 1.3 *************** *** 30,36 **** private int _counter; ! public SimpleXmlVisitor(String result,int counter) { ! _result = result; _counter = counter; } --- 30,36 ---- private int _counter; ! public SimpleXmlVisitor(int counter) { ! _result = ""; _counter = counter; } *************** *** 41,62 **** * Code to execute over the TreeElement te */ ! String opening = "<result solution=\"yes\" number=\"" + _counter + "\">"; ! _result.concat(opening); Substitution[] substArray = te.getSubstitutions(); ! for (int i = 0; i < substArray.length;i++) { ! _result.concat("<substitution " + ! "variable=\"" + substArray[i].getOriginalValue() + "\"" + ! "value=\"" + substArray[i].getNewValue() + "\"" + ! "/>"); } - String closing = "</result>"; ! _result.concat(closing); } - public String getResult() { --- 41,67 ---- * Code to execute over the TreeElement te */ ! String opening = "<result solution=\"yes\" number=\"" + _counter + "\">"; ! _result = _result.concat(opening); Substitution[] substArray = te.getSubstitutions(); ! if (substArray != null) { ! System.out.println("Node have substitutions"); ! for (int i = 0; i < substArray.length;i++) ! { ! _result = _result.concat("<substitution " ! + "variable=\"" ! + substArray[i].getOriginalValue() ! + "\" " + "value=\"" ! + substArray[i].getNewValue() ! + "\"" + "/>"); ! } } String closing = "</result>"; ! _result = _result.concat(closing); ! } public String getResult() { |