1 /*
2 * Copyright 2002,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 package org.apache.commons.jelly.tags.jms;
17
18 import javax.jms.Message;
19 import javax.jms.JMSException;
20
21 import org.apache.commons.jelly.JellyTagException;
22
23 /*** Creates a JMS TextMessage
24 *
25 * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
26 * @version $Revision: 155420 $
27 */
28 public class TextMessageTag extends MessageTag {
29
30 private String text;
31
32 public TextMessageTag() {
33 }
34
35 // Properties
36 //-------------------------------------------------------------------------
37
38 /***
39 * Sets the body of the message, a String. If this value is not set or
40 * the value is null then the content of the tag will be used instead.
41 */
42 public void setText(String text) {
43 this.text = text;
44 }
45
46
47 // Implementation methods
48 //-------------------------------------------------------------------------
49 protected Message createMessage() throws JellyTagException {
50 String value = (text != null) ? text : getBodyText();
51 try {
52 return getConnection().createTextMessage(value);
53 } catch (JMSException e) {
54 throw new JellyTagException(e);
55 }
56 }
57 }