Math2mat

/home/ythoma/docs/math2mat/svn/wp1/framework/m2mGUI/src/m2m/backend/structure/LoopWhile.java

Go to the documentation of this file.
00001 /******************************************************************************
00002  *                                                                                      LoopFor
00003  ******************************************************************************
00004  * Auteur               : Trolliet Gregory
00005  * Date                 : 4 mars 2009
00006  * Description :
00007  ******************************************************************************/
00008 package m2m.backend.structure;
00009 
00010 import java.util.Vector;
00011 
00012 import org.w3c.dom.Document;
00013 import org.w3c.dom.Node;
00014 
00022 public class LoopWhile extends Function {
00023 
00027         private Vector<Element> cond;
00028 
00032         public LoopWhile() {
00033                 this.setName("loopwhile");
00034                 this.cond = new Vector<Element>();
00035         }
00036         
00037 
00038         public String getXmlTagName() {
00039                 return "LoopWhile";
00040         }
00041 
00042 
00043         public boolean insideFromXml(org.w3c.dom.Element el,Function newFunc) {
00044                 super.insideFromXml(el,newFunc);
00045                 
00046                 Node node = el.getFirstChild();
00047                 while(node!=null) {
00048                         if (node.getNodeName().equalsIgnoreCase("Cond")) {
00049                                 org.w3c.dom.Element inputEl=(org.w3c.dom.Element)node;
00050                                 Node nodeIn = inputEl.getFirstChild().getNextSibling();
00051                                 while(nodeIn!=null) {
00052                                         if (nodeIn.getNodeType()==org.w3c.dom.Node.ELEMENT_NODE) {
00053                                                 Element element=getElement((org.w3c.dom.Element)nodeIn,this);
00054                                                 if (element!=null)
00055                                                         cond.add(element);
00056                                         }
00057                                         nodeIn=nodeIn.getNextSibling();
00058                                 }
00059                         }
00060                         node=node.getNextSibling();
00061                 }
00062                 return false;
00063         }
00064         
00065         public void insideToXml(org.w3c.dom.Element el,Document dom,boolean shortRef) {
00066                 // This function replaces the one of Function, so we call Element instead
00067                 // of function
00068 //              superInsideToXml(el,dom,shortRef);
00069                 super.insideToXml(el, dom, shortRef);
00070 
00071                 org.w3c.dom.Element condEl=dom.createElement("Cond");
00072                 for(Element e: cond) {
00073                         condEl.appendChild(e.toXml(dom,false));
00074                 }
00075                 el.appendChild(condEl);
00076         }
00077         
00078         
00079 
00084         public void setCond(Vector<Element> cond) {
00085                 this.cond = cond;
00086         }
00087 
00092         public Vector<Element> getCond() {
00093                 return this.cond;
00094         }
00095 
00096         @Override
00097         public String toString(int level) {
00098                 String s = new String();
00099                 s += tab(level) + "[LoopWhile]\tName: " + this.name;
00100                 s += "\n" + this.toStringParam(level + 1);
00101                 s += "\n" + tab(level) + ">>===COND===<<";
00102                 for (Element el : this.cond) {
00103                         s += "\n" + el.toString(level + 1);
00104                 }
00105                 s += "\n" + tab(level) + ">>==========<<";
00106                 for (Element el : this.body) {
00107                         s += "\n" + el.toString(level + 1);
00108                 }
00109                 return s;
00110         }
00111 
00112 
00113         @Override
00114         public String toSchematic(int level, String prefix, String boxFormat, String color) {
00115                 String s = new String();
00116                 int cpt = 0;
00117                 s += super.toSchematic(level, prefix, "box", color);
00118                 if (!this.cond.isEmpty()) {
00119                         cpt = 0;
00120                         for (Element el : this.cond) {
00121                                 s += "\n" + el.toSchematic(level, prefix + "_cond_"
00122                                                   + cpt, "box", GraphParams.defaultColor);
00123                                 s += "\n" + tab(level) + prefix + " -> " + prefix + "_cond_" + cpt;
00124                                 cpt++;
00125                         }
00126                 }
00127                 return s;
00128         }
00129 
00130         @Override
00131         public String toOctave(int level) {
00132                 String sOctave = new String();
00133                 sOctave += tab(level) + "while " + "";//this.internalVars.firstElement().getName() + "=";
00134                 sOctave += "\n";
00135                 for (Element e : this.body) {
00136                         sOctave += e.toOctave(level + 1) + "\n";
00137                 }
00138                 /*
00139                 sOctave += tab(level + 1) + "if ("
00140                 + ((Variable) this.internalVars.firstElement()).getName() + " == "
00141                 + ((this.start.getName().isEmpty()) ? ((Variable) this.start).getVal() : this.start.getName())
00142                 + ")\n";
00143                 sOctave += */
00144                 sOctave += tab(level) + "end";
00145                 return sOctave;
00146         }
00147 }
 All Classes Namespaces Files Functions Variables Enumerations