KickJava   Java API By Example, From Geeks To Geeks.

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


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.ServletContext JavaDoc;
21 import javax.servlet.jsp.JspException JavaDoc;
22 import javax.servlet.jsp.tagext.BodyContent JavaDoc;
23
24 /** Adds a map entry to the outer Map Message tag
25   *
26   * @author <a HREF="mailto:jstrachan@apache.org">James Strachan</a>
27   * @version $Revision: 1.2 $
28   */

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

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

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