1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.commons.jelly.impl;
17
18 import java.util.ArrayList;
19 import java.util.Iterator;
20 import java.util.List;
21
22 import org.apache.commons.jelly.JellyContext;
23 import org.apache.commons.jelly.JellyException;
24 import org.apache.commons.jelly.JellyTagException;
25 import org.apache.commons.jelly.Script;
26 import org.apache.commons.jelly.XMLOutput;
27
28 /*** <p><code>ScriptBlock</code> a block of scripts.</p>
29 *
30 * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
31 * @version $Revision: 1.15 $
32 */
33 public class ScriptBlock implements Script {
34
35 /*** The list of scripts */
36 private List list = new ArrayList();
37
38 public ScriptBlock() {
39 }
40
41 public String toString() {
42 return super.toString() + "[scripts=" + list + "]";
43 }
44
45 /*** Add a new script to the end of this block */
46 public void addScript(Script script) {
47 list.add(script);
48 }
49
50 /*** Removes a script from this block */
51 public void removeScript(Script script) {
52 list.remove(script);
53 }
54
55 /***
56 * Gets the child scripts that make up this block. This list is live
57 * so that it can be modified if requried
58 */
59 public List getScriptList() {
60 return list;
61 }
62
63
64
65 public Script compile() throws JellyException {
66 int size = list.size();
67 if (size == 1) {
68 Script script = (Script) list.get(0);
69 return script.compile();
70 }
71
72 for (int i = 0; i < size; i++) {
73 Script script = (Script) list.get(i);
74 list.set(i, script.compile());
75 }
76 return this;
77 }
78
79 /*** Evaluates the body of a tag */
80 public void run(JellyContext context, XMLOutput output) throws JellyTagException {
81
82
83
84
85
86
87 for (Iterator iter = list.iterator(); iter.hasNext(); ) {
88 Script script = (Script) iter.next();
89 script.run(context, output);
90 }
91 }
92 }