KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openlaszlo > compiler > SwitchCompiler


1 /* *****************************************************************************
2  * SwitchCompiler.java
3  * ****************************************************************************/

4
5 /* J_LZ_COPYRIGHT_BEGIN *******************************************************
6 * Copyright 2001-2004 Laszlo Systems, Inc. All Rights Reserved. *
7 * Use is subject to license terms. *
8 * J_LZ_COPYRIGHT_END *********************************************************/

9
10
11 package org.openlaszlo.compiler;
12 import java.util.*;
13 import org.apache.log4j.*;
14 import org.jdom.Element;
15
16 /** Compiler for <code>switch</code> elements.
17  */

18 class SwitchCompiler extends ToplevelCompiler {
19     static final String JavaDoc WHEN = "when";
20     static final String JavaDoc 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