KickJava   Java API By Example, From Geeks To Geeks.

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


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.Destination JavaDoc;
20 import javax.jms.JMSException JavaDoc;
21 import javax.jms.Message JavaDoc;
22 import javax.servlet.jsp.JspException JavaDoc;
23
24 import org.apache.commons.messenger.Messenger;
25
26 /** An abstract base class for JMS Message operation tags such as send, receive or call.
27   *
28   * @author <a HREF="mailto:jstrachan@apache.org">James Strachan</a>
29   * @version $Revision: 1.2 $
30   */

31 public abstract class MessageOperationTag extends AbstractTag implements ConnectionContext {
32
33     /** The Messenger used to access the JMS connection */
34     private Messenger connection;
35     
36     /** The Destination */
37     private Destination JavaDoc destination;
38     
39     public MessageOperationTag() {
40     }
41     
42     // Tag interface
43
//-------------------------------------------------------------------------
44
public void release() {
45         super.release();
46         connection = null;
47         destination = null;
48     }
49     
50     
51     // Properties
52
//-------------------------------------------------------------------------
53
public Messenger getConnection() throws JspException JavaDoc, JMSException JavaDoc {
54         if ( connection == null ) {
55             return findConnection();
56         }
57         return connection;
58     }
59     
60     public void setConnection(Messenger connection) {
61         this.connection = connection;
62     }
63     
64     public Destination JavaDoc getDestination() {
65         return destination;
66     }
67     
68     public void setDestination(Destination JavaDoc destination) {
69         this.destination = destination;
70     }
71
72     // Implementation methods
73
//-------------------------------------------------------------------------
74
protected Messenger findConnection() throws JspException JavaDoc, JMSException JavaDoc {
75         ConnectionContext messengerTag = (ConnectionContext) findAncestorWithClass( this, ConnectionContext.class );
76         if ( messengerTag == null ) {
77             throw new JspException JavaDoc("This tag must be within a <jms:connection> tag or the 'connection' attribute should be specified");
78         }
79         return messengerTag.getConnection();
80     }
81 }
82
Popular Tags