1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.commons.jelly.tags.dynabean;
17
18 import java.util.ArrayList;
19
20 import org.apache.commons.beanutils.BasicDynaClass;
21 import org.apache.commons.beanutils.DynaClass;
22 import org.apache.commons.beanutils.DynaProperty;
23 import org.apache.commons.jelly.JellyTagException;
24 import org.apache.commons.jelly.MissingAttributeException;
25 import org.apache.commons.jelly.TagSupport;
26 import org.apache.commons.jelly.XMLOutput;
27
28 /***
29 * A tag which creates and defines and creates a DynaClass
30 * The DynaClass object is placed by name in the context,
31 * so that a DynaBean tag can use it by name to instantiate
32 * a DynaBean object
33 *
34 * @author Theo Niemeijer
35 * @version 1.0
36 */
37 public class DynaclassTag extends TagSupport {
38
39 private ArrayList propList = new ArrayList();
40 private DynaProperty[] props = null;
41 private DynaClass dynaClass = null;
42
43 private String name;
44 private String var;
45
46 public DynaclassTag() {
47 }
48
49
50
51 public void doTag(XMLOutput output) throws MissingAttributeException, JellyTagException {
52
53 if (name == null) {
54 throw new MissingAttributeException("name");
55 }
56
57 if (var == null) {
58 var = name;
59 }
60
61
62 invokeBody(output);
63
64
65 props =
66 (DynaProperty[]) propList.toArray(
67 new DynaProperty[propList.size()]);
68
69 if (props == null) {
70 throw new JellyTagException("No properties list");
71 }
72
73 if (props.length == 0) {
74 throw new JellyTagException("No properties");
75 }
76
77
78 dynaClass = (DynaClass) new BasicDynaClass(name, null, props);
79
80
81 context.setVariable(getVar(), dynaClass);
82 }
83
84
85
86
87 /***
88 * Sets the name of the new DynaClass
89 */
90 public void setName(String name) {
91 this.name = name;
92 }
93
94 public String getVar() {
95 return var;
96 }
97
98 /***
99 * Sets the name of the variable to export the DynaClass instance
100 */
101 public void setVar(String var) {
102 this.var = var;
103 }
104
105 protected void addDynaProperty(DynaProperty prop) {
106 propList.add(prop);
107 }
108 }