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.JMSException;
19
20 import org.apache.commons.jelly.JellyTagException;
21 import org.apache.commons.jelly.TagSupport;
22 import org.apache.commons.jelly.XMLOutput;
23 import org.apache.commons.messenger.Messenger;
24 import org.apache.commons.messenger.MessengerManager;
25
26 /*** Defines a JMS connection for use by other JMS tags.
27 *
28 * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
29 * @version $Revision: 155420 $
30 */
31 public class ConnectionTag extends TagSupport implements ConnectionContext {
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 /*** The Messenger */
40 private Messenger connection;
41
42
43
44 public Messenger getConnection() {
45 return connection;
46 }
47
48
49
50 public void doTag(XMLOutput output) throws JellyTagException {
51
52 try {
53 connection = MessengerManager.get( name );
54 }
55 catch (JMSException e) {
56 throw new JellyTagException(e);
57 }
58
59 if (connection == null) {
60 throw new JellyTagException( "Could not find a JMS connection called: " + name );
61 }
62
63 if ( var != null ) {
64 context.setVariable( var, connection );
65 }
66
67 invokeBody(output);
68 }
69
70
71
72
73 /*** Sets the name of the Messenger (JMS connection pool) to use
74 */
75 public void setName(String name) {
76 this.name = name;
77 }
78
79 /*** Sets the variable name to use for the exported Messenger (JMS connection pool)
80 */
81 public void setVar(String var) {
82 this.var = var;
83 }
84 }