1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.commons.jelly.tags.ojb;
17
18 import org.apache.commons.jelly.JellyTagException;
19 import org.apache.commons.jelly.TagSupport;
20 import org.apache.commons.jelly.XMLOutput;
21 import org.apache.ojb.broker.PersistenceBroker;
22 import org.apache.ojb.broker.PersistenceBrokerFactory;
23
24 /***
25 * <p>Tag handler for <Driver> in JSTL, used to create
26 * a simple DataSource for prototyping.</p>
27 *
28 * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
29 * @version $Revision: 155420 $
30 */
31 public class BrokerTag extends TagSupport {
32
33 /*** The variable name to export. */
34 private String var;
35
36 /*** The persistence broker instance */
37 private PersistenceBroker broker;
38
39 public BrokerTag() {
40 }
41
42
43
44
45 public void doTag(XMLOutput output) throws JellyTagException {
46 if ( var == null ) {
47 var = "org.apache.commons.jelly.ojb.Broker";
48 }
49 if ( broker != null ) {
50 context.setVariable(var, broker);
51 invokeBody(output);
52 }
53 else {
54 broker = PersistenceBrokerFactory.defaultPersistenceBroker();
55 context.setVariable(var, broker);
56
57 try {
58 invokeBody(output);
59 }
60 finally {
61 broker.close();
62 broker = null;
63 context.removeVariable(var);
64 }
65 }
66 }
67
68
69
70 /*** Sets the variable name to define for this expression
71 */
72 public void setVar(String var) {
73 this.var = var;
74 }
75
76 /*** @return the persistence broker instance */
77 public PersistenceBroker getBroker() {
78 return broker;
79 }
80
81 /*** Sets the persistence broker instance */
82 public void setBroker(PersistenceBroker broker) {
83 this.broker = broker;
84 }
85 }