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 org.apache.commons.beanutils.DynaBean;
19 import org.apache.commons.beanutils.DynaClass;
20 import org.apache.commons.jelly.JellyTagException;
21 import org.apache.commons.jelly.MissingAttributeException;
22 import org.apache.commons.jelly.TagSupport;
23 import org.apache.commons.jelly.XMLOutput;
24
25
26 /*** A tag which conditionally evaluates its body based on some condition
27 *
28 * @author Theo Niemeijer
29 * @version $Revision: 155420 $
30 */
31 public class DynabeanTag extends TagSupport {
32
33 private DynaClass dynaClass;
34 private String var;
35
36 public DynabeanTag() {
37 }
38
39
40
41 public void doTag(XMLOutput output) throws MissingAttributeException, JellyTagException {
42
43 if (dynaClass == null) {
44 throw new MissingAttributeException( "dynaclass" );
45 }
46
47 if (var == null) {
48 throw new MissingAttributeException( "var" );
49 }
50
51 try {
52
53 DynaBean dynaBean = dynaClass.newInstance();
54
55
56 context.setVariable(getVar(), dynaBean);
57 } catch (IllegalAccessException e) {
58 throw new JellyTagException(e);
59 } catch (InstantiationException e) {
60 throw new JellyTagException(e);
61 }
62 }
63
64
65
66
67 /***
68 * Sets the DynaClass of the new instance to create
69 */
70 public void setDynaclass(DynaClass dynaClass) {
71 this.dynaClass = dynaClass;
72 }
73
74 public String getVar() {
75 return var;
76 }
77
78 /***
79 * Sets the name of the variable to export the new DynaBean instance to
80 */
81 public void setVar(String var) {
82 this.var = var;
83 }
84
85
86 }