KickJava   Java API By Example, From Geeks To Geeks.

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


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 /** Sends a JMS message to some destination.
25   *
26   * @author <a HREF="mailto:jstrachan@apache.org">James Strachan</a>
27   * @version $Revision: 1.2 $
28   */

29 public class SendTag extends MessageOperationTag {
30
31     /** The JMS Message to be sent */
32     private Message JavaDoc message;
33     
34     public SendTag() {
35     }
36         
37     // TagTag interface
38
//-------------------------------------------------------------------------
39
public int doStartTag() throws JspException JavaDoc {
40         return EVAL_BODY_INCLUDE;
41     }
42     
43     public int doEndTag() throws JspException JavaDoc {
44         try {
45             Message JavaDoc message = getMessage();
46             if ( message == null ) {
47                 throw new JspException JavaDoc( "No message specified. Either specify a 'message' attribute or use a nested <jms:message> tag" );
48             }
49             Destination JavaDoc destination = getDestination();
50             if ( destination == null ) {
51                 throw new JspException JavaDoc( "No destination specified. Either specify a 'destination' attribute or use a nested <jms:destination> tag" );
52             }
53             getConnection().send( destination, message );
54         }
55         catch (JMSException JavaDoc e) {
56             throw new JspException JavaDoc( "Failed to send JMS message: " + e, e );
57         }
58         return EVAL_PAGE;
59     }
60     
61     public void release() {
62         super.release();
63         message = null;
64     }
65     
66     
67     // Properties
68
//-------------------------------------------------------------------------
69
public Message JavaDoc getMessage() {
70         return message;
71     }
72     
73     public void setMessage(Message JavaDoc message) {
74         this.message = message;
75     }
76 }
77
Popular Tags