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
23 /***
24 * <p>This Store tag will store the given object in ObjectBridge using
25 * the given broker or it will use the parent broker tags broker instance.</p>
26 *
27 * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
28 * @version $Revision: 155420 $
29 */
30 public class StoreTag extends TagSupport {
31
32 /*** the value to persist */
33 private Object value;
34
35 /*** The persistence broker instance */
36 private PersistenceBroker broker;
37
38 public StoreTag() {
39 }
40
41
42
43
44 public void doTag(XMLOutput output) throws JellyTagException {
45 if ( value == null ) {
46 throw new JellyTagException( "No value is supplied!" );
47 }
48 getBroker().store( value );
49 }
50
51
52
53
54 /*** Sets the value to be persisted */
55 public void setValue(Object value) {
56 this.value = value;
57 }
58
59 /*** @return the persistence broker instance */
60 public PersistenceBroker getBroker() {
61 if (broker == null) {
62 BrokerTag brokerTag = (BrokerTag) findAncestorWithClass( BrokerTag.class );
63 if ( brokerTag != null ) {
64 broker = brokerTag.getBroker();
65 }
66 else {
67 broker = (PersistenceBroker) context.getVariable(
68 "org.apache.commons.jelly.ojb.Broker"
69 );
70 }
71 }
72 return broker;
73 }
74
75 /*** Sets the persistence broker instance */
76 public void setBroker(PersistenceBroker broker) {
77 this.broker = broker;
78 }
79 }
80