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 javax.jms.Destination;
19 import javax.jms.JMSException;
20
21 import org.apache.commons.jelly.JellyTagException;
22 import org.apache.commons.jelly.TagSupport;
23 import org.apache.commons.jelly.XMLOutput;
24 import org.apache.commons.messenger.Messenger;
25
26 /*** Creates a Destination object from a String name.
27 *
28 * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
29 * @version $Revision: 155420 $
30 */
31 public class DestinationTag extends TagSupport {
32
33 /*** The variable name to create */
34 private String var;
35
36 /*** Stores the name of the map entry */
37 private String name;
38
39
40
41 public void doTag(XMLOutput output) throws JellyTagException {
42 ConnectionContext messengerTag = (ConnectionContext) findAncestorWithClass( ConnectionContext.class );
43 if ( messengerTag == null ) {
44 throw new JellyTagException("<jms:destination> tag must be within a <jms:connection> or <jms:send> or <jms:receive> tag");
45 }
46
47 Destination destination = null;
48 try {
49 Messenger messenger = messengerTag.getConnection();
50 if (messenger == null) {
51 throw new JellyTagException("No JMS Connection could be found!" );
52 }
53 String subject = (name != null) ? name : getBodyText();
54 destination = messenger.getDestination( subject );
55 }
56 catch (JMSException e) {
57 throw new JellyTagException(e);
58 }
59
60 if ( var != null ) {
61 context.setVariable( var, destination );
62 }
63 else {
64 MessageOperationTag tag = (MessageOperationTag) findAncestorWithClass( MessageOperationTag.class );
65 if ( tag == null ) {
66 throw new JellyTagException("<jms:destination> tag must be within a <jms:send> or <jms:receive> tag or the 'var' attribute should be specified");
67 }
68 tag.setDestination( destination );
69 }
70 }
71
72
73
74
75
76 /*** Sets the name of the Destination
77 */
78 public void setName(String name) {
79 this.name = name;
80 }
81
82 /*** Sets the variable name to use for the Destination
83 */
84 public void setVar(String var) {
85 this.var = var;
86 }
87 }