KickJava   Java API By Example, From Geeks To Geeks.

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


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 import javax.servlet.jsp.tagext.BodyContent JavaDoc;
22
23 /** Defines a property on an outer JMS Message
24   *
25   * @author <a HREF="mailto:jstrachan@apache.org">James Strachan</a>
26   * @version $Revision: 1.2 $
27   */

28 public class PropertyTag extends AbstractBodyTag {
29
30     /** Stores the name of the property */
31     private String JavaDoc name;
32     
33     /** Stores the value of the property */
34     private Object JavaDoc value;
35     
36     
37     // BodyTag interface
38
//-------------------------------------------------------------------------
39
public int doStartTag() throws JspException JavaDoc {
40         if ( value != null ) {
41             fireSetProperty();
42             return SKIP_BODY;
43         }
44         return EVAL_BODY_TAG;
45     }
46     
47     public int doAfterBody() throws JspException JavaDoc {
48         BodyContent JavaDoc body = getBodyContent();
49         value = body.getString();
50         body.clearBody();
51         fireSetProperty();
52         return EVAL_PAGE;
53     }
54     
55     public void release() {
56         name = null;
57         value = null;
58     }
59     
60     // Properties
61
//-------------------------------------------------------------------------
62
/** Sets the name of the JMS property
63       */

64     public void setName(String JavaDoc name) {
65         this.name = name;
66     }
67     
68     /** Sets the value of the JMS property.
69       * If no value is set then the body of the tag is used
70       */

71     public void setValue(Object JavaDoc value) {
72         this.value = value;
73     }
74     
75     // Implementation methods
76
//-------------------------------------------------------------------------
77
protected void fireSetProperty() throws JspException JavaDoc {
78         try {
79             MessageTag tag = (MessageTag) findAncestorWithClass( this, MessageTag.class );
80             if ( tag == null ) {
81                 throw new JspException JavaDoc("<jms:property> tag must be within a <jms:message> tag");
82             }
83             tag.addProperty( name, value );
84         }
85         catch (JMSException JavaDoc e) {
86             throw new JspException JavaDoc( "Failed to set Message header property name: " + name + " value: " + value + ". Reason: " + e, e );
87         }
88     }
89 }
90
Popular Tags