1 4 5 9 10 11 package org.openlaszlo.compiler; 12 import java.util.*; 13 import org.apache.log4j.*; 14 import org.jdom.Element; 15 16 18 class SwitchCompiler extends ToplevelCompiler { 19 static final String WHEN = "when"; 20 static final String OTHERWISE = "otherwise"; 21 22 SwitchCompiler(CompilationEnvironment env) { 23 super(env); 24 } 25 26 static boolean isElement(Element element) { 27 return element.getName().equals("switch"); 28 } 29 30 public void compile(Element element) { 31 for (Iterator iter = element.getChildren(WHEN, element.getNamespace()).iterator(); 32 iter.hasNext(); ) { 33 Element child = (Element) iter.next(); 34 if (evaluateConditions(child)) { 35 compileChildren(child); 36 return; 37 } 38 } 39 for (Iterator iter = element.getChildren(OTHERWISE, element.getNamespace()).iterator(); 40 iter.hasNext(); ) { 41 Element child = (Element) iter.next(); 42 compileChildren(child); 43 return; 44 } 45 } 46 47 protected void compileChildren(Element element) { 48 for (Iterator iter = element.getChildren().iterator(); 49 iter.hasNext(); ) { 50 Element child = (Element) iter.next(); 51 Compiler.compileElement(child, mEnv); 52 } 53 } 54 55 void updateSchema(Element element, ViewSchema schema, Set visited) 56 { 57 for (Iterator iter = element.getChildren(WHEN, element.getNamespace()).iterator(); 58 iter.hasNext(); ) { 59 Element child = (Element) iter.next(); 60 if (evaluateConditions(child)) { 61 updateChildren(child, schema, visited); 62 return; 63 } 64 } 65 for (Iterator iter = element.getChildren(OTHERWISE, element.getNamespace()).iterator(); 66 iter.hasNext(); ) { 67 Element child = (Element) iter.next(); 68 updateChildren(child, schema, visited); 69 return; 70 } 71 } 72 73 protected void updateChildren(Element element, ViewSchema schema, Set visited) { 74 for (Iterator iter = element.getChildren().iterator(); 75 iter.hasNext(); ) { 76 Element child = (Element) iter.next(); 77 Compiler.updateSchema(child, mEnv, schema, visited); 78 } 79 } 80 81 protected boolean evaluateConditions(Element element) { 82 if (element.getAttribute("runtime") != null 83 && !element.getAttributeValue("runtime").equals(mEnv.getSWFVersion())) { 84 return false; 85 } 86 return true; 87 } 88 } 89 | Popular Tags |