1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.commons.jelly.tags.sql;
17
18 import java.util.ArrayList;
19 import java.util.List;
20 import java.util.Map;
21
22 import org.apache.commons.jelly.JellyTagException;
23 import org.apache.commons.jelly.MissingAttributeException;
24 import org.apache.commons.jelly.TagSupport;
25 import org.apache.commons.jelly.XMLOutput;
26
27 /***
28 * This Tag creates a result set object based on its body content via child row tags.
29 * This tag is useful for unit testing with Mock Tags to simulate the results returned by databases.
30 *
31 */
32 public class ResultSetTag extends TagSupport {
33
34 private List rows;
35 private String var;
36
37 /***
38 * Adds the given row to the list of rows
39 */
40 public void addRow(Map row) {
41 rows.add(row);
42 }
43
44
45
46 public void doTag(XMLOutput output) throws MissingAttributeException, JellyTagException {
47 if (var == null) {
48 throw new MissingAttributeException( "var" );
49 }
50 rows = new ArrayList();
51 invokeBody(output);
52
53
54 ResultImpl results = new ResultImpl( rows );
55 context.setVariable(var, results);
56 rows = null;
57 }
58
59
60
61 /***
62 * Sets the variable to export the result set to.
63 */
64 public void setVar(String var) {
65 this.var = var;
66 }
67
68 }