%line | %branch | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
org.apache.commons.jelly.impl.ScriptBlock |
|
|
1 | /* |
|
2 | * Copyright 2002,2004 The Apache Software Foundation. |
|
3 | * |
|
4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
|
5 | * you may not use this file except in compliance with the License. |
|
6 | * You may obtain a copy of the License at |
|
7 | * |
|
8 | * http://www.apache.org/licenses/LICENSE-2.0 |
|
9 | * |
|
10 | * Unless required by applicable law or agreed to in writing, software |
|
11 | * distributed under the License is distributed on an "AS IS" BASIS, |
|
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
13 | * See the License for the specific language governing permissions and |
|
14 | * limitations under the License. |
|
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 | 3098 | private List list = new ArrayList(); |
37 | ||
38 | 3098 | public ScriptBlock() { |
39 | 3098 | } |
40 | ||
41 | public String toString() { |
|
42 | 0 | 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 | 6986 | list.add(script); |
48 | 6986 | } |
49 | ||
50 | /** Removes a script from this block */ |
|
51 | public void removeScript(Script script) { |
|
52 | 0 | list.remove(script); |
53 | 0 | } |
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 | 804 | return list; |
61 | } |
|
62 | ||
63 | // Script interface |
|
64 | //------------------------------------------------------------------------- |
|
65 | public Script compile() throws JellyException { |
|
66 | 3080 | int size = list.size(); |
67 | 3080 | if (size == 1) { |
68 | 550 | Script script = (Script) list.get(0); |
69 | 550 | return script.compile(); |
70 | } |
|
71 | // now compile children |
|
72 | 8952 | for (int i = 0; i < size; i++) { |
73 | 6422 | Script script = (Script) list.get(i); |
74 | 6422 | list.set(i, script.compile()); |
75 | } |
|
76 | 2530 | return this; |
77 | } |
|
78 | ||
79 | /** Evaluates the body of a tag */ |
|
80 | public void run(JellyContext context, XMLOutput output) throws JellyTagException { |
|
81 | /* |
|
82 | for (int i = 0, size = scripts.length; i < size; i++) { |
|
83 | Script script = scripts[i]; |
|
84 | script.run(context, output); |
|
85 | } |
|
86 | */ |
|
87 | 3270 | for (Iterator iter = list.iterator(); iter.hasNext(); ) { |
88 | 1686 | Script script = (Script) iter.next(); |
89 | 1686 | script.run(context, output); |
90 | } |
|
91 | 750 | } |
92 | } |
This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |