KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > taglibs > jms > ConnectionTag


1 /*
2  * Copyright 1999,2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.taglibs.jms;
18
19 import javax.jms.JMSException JavaDoc;
20 import javax.servlet.jsp.JspException JavaDoc;
21
22 import org.apache.commons.messenger.Messenger;
23 import org.apache.commons.messenger.MessengerManager;
24
25 /** Defines a JMS connection for use by other JMS tags.
26   *
27   * @author <a HREF="mailto:jstrachan@apache.org">James Strachan</a>
28   * @version $Revision: 1.2 $
29   */

30 public class ConnectionTag extends AbstractTag implements ConnectionContext {
31
32     /** The variable name to create */
33     private String JavaDoc var;
34         
35     /** Stores the name of the map entry */
36     private String JavaDoc name;
37
38     /** The Messenger */
39     private Messenger connection;
40
41     // ConnectionContext interface
42
//-------------------------------------------------------------------------
43
public Messenger getConnection() {
44         return connection;
45     }
46     
47     // Tag interface
48
//-------------------------------------------------------------------------
49
public int doStartTag() throws JspException JavaDoc {
50         try {
51             connection = MessengerManager.get( name );
52         }
53         catch (JMSException JavaDoc e) {
54             throw new JspException JavaDoc( "Could not find JMS Connection named: " + name + ". Reason: " + e, e );
55         }
56         if ( var != null ) {
57             pageContext.setAttribute( var, connection );
58         }
59         return EVAL_BODY_INCLUDE;
60     }
61     
62     public void release() {
63         name = null;
64         var = null;
65         connection = null;
66     }
67     
68     // Properties
69
//-------------------------------------------------------------------------
70

71     /** Sets the name of the Destination
72       */

73     public void setName(String JavaDoc name) {
74         this.name = name;
75     }
76     
77     /** Sets the variable name to use for the Destination
78       */

79     public void setVar(String JavaDoc var) {
80         this.var = var;
81     }
82 }
83
Popular Tags