[Pfc-prolog-cvs] prolix/src/org/asturlinux/frade/prolix/ejb/sessionjb SimpleXmlVisitor.java,NONE,1.1
Status: Beta
Brought to you by:
ivanfrade
From: <iva...@us...> - 2003-06-23 17:15:05
|
Update of /cvsroot/pfc-prolog/prolix/src/org/asturlinux/frade/prolix/ejb/sessionjb In directory sc8-pr-cvs1:/tmp/cvs-serv28019a/src/org/asturlinux/frade/prolix/ejb/sessionjb Modified Files: ProlixMainBean.java Added Files: SimpleXmlVisitor.java Log Message: Added visitor pattern --- NEW FILE: SimpleXmlVisitor.java --- package org.asturlinux.frade.prolix.ejb.sessionjb; import org.asturlinux.frade.prolix.interpreter.interfaces.*; public class SimpleXmlVisitor extends TreeElementVisitor { private String _result; private int _counter; public SimpleXmlVisitor(String result,int counter) { _result = result; _counter = counter; } public void visitTreeElement(TreeElement te) { /** * 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() { return _result; } } Index: ProlixMainBean.java =================================================================== RCS file: /cvsroot/pfc-prolog/prolix/src/org/asturlinux/frade/prolix/ejb/sessionjb/ProlixMainBean.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** ProlixMainBean.java 23 Jun 2003 12:01:30 -0000 1.5 --- ProlixMainBean.java 23 Jun 2003 17:15:00 -0000 1.6 *************** *** 76,80 **** { _consult = consult; ! //Could be prologCtx == null? prologCtx.consult(consult); } --- 76,80 ---- { _consult = consult; ! //FIXME Could be prologCtx == null? prologCtx.consult(consult); } *************** *** 118,127 **** --- 118,130 ---- } + private void treeElementToXmlTransformation(TreeElement tree, String result) { String xmlOpen = "<results>"; result.concat(xmlOpen); + int solutionCounter = 1; recursiveInOrden(tree,result,solutionCounter); + String xmlClose = "</results>"; result.concat(xmlClose); *************** *** 138,164 **** /** ! * node "treatment" */ if (tree.isSolution()) { ! treeElementNodeToXml(tree,result,solution); solution++; } } - private void treeElementNodeToXml(TreeElement t, String s, int counter) - { - String opening = "<result solution=\"yes\" number=\"" + counter + "\">"; - s.concat(opening); - Substitution[] substArray = t.getSubstitutions(); - for (int i = 0; i < substArray.length;i++) - { - s.concat("<substitution " + - "variable=\"" + substArray[i].getOriginalValue() + "\"" + - "value=\"" + substArray[i].getNewValue() + "\"" + - "/>"); - } - String closing = "</result>"; - s.concat(closing); - } } --- 141,155 ---- /** ! * node "treatment" using visitor pattern. ! * visitor _add_ node's xml to result. */ if (tree.isSolution()) { ! SimpleXmlVisitor visitor = new SimpleXmlVisitor(result,solution); ! tree.accept(visitor); solution++; + result = visitor.getResult(); } } } |