1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.commons.jelly.tags.jms;
17
18 import org.apache.commons.jelly.JellyTagException;
19 import org.apache.commons.jelly.MissingAttributeException;
20 import org.apache.commons.jelly.TagSupport;
21 import org.apache.commons.jelly.XMLOutput;
22
23 /*** Adds a map entry to the outer Map Message tag
24 *
25 * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
26 * @version $Revision: 155420 $
27 */
28 public class MapEntryTag extends TagSupport {
29
30 /*** Stores the name of the map entry */
31 private String name;
32
33 /*** Stores the value of the map entry */
34 private Object value;
35
36
37
38
39 public void doTag(XMLOutput output) throws MissingAttributeException, JellyTagException {
40 if ( name == null ) {
41 throw new MissingAttributeException("name");
42 }
43 MapMessageTag tag = (MapMessageTag) findAncestorWithClass( MapMessageTag.class );
44 if ( tag == null ) {
45 throw new JellyTagException("<jms:mapEntry> tag must be within a <jms:mapMessage> tag");
46 }
47
48 if (value != null) {
49 tag.addEntry( name, value );
50 }
51 else {
52 tag.addEntry( name, getBodyText() );
53 }
54 }
55
56
57
58 /*** Sets the name of the entry in the map message
59 */
60 public void setName(String name) {
61 this.name = name;
62 }
63
64 /*** Sets the value of the entry in the map message.
65 * If no value is set then the body of the tag is used
66 */
67 public void setValue(Object value) {
68 this.value = value;
69 }
70 }