View Javadoc

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 org.apache.commons.jelly.JellyTagException;
19  import org.apache.commons.jelly.MissingAttributeException;
20  import org.apache.commons.jelly.TagSupport;
21  import org.apache.commons.jelly.XMLOutput;
22  
23  /*** Adds a map entry to the outer Map Message tag
24    *
25    * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
26    * @version $Revision: 155420 $
27    */
28  public class MapEntryTag extends TagSupport {
29  
30      /*** Stores the name of the map entry */
31      private String name;
32  
33      /*** Stores the value of the map entry */
34      private Object value;
35  
36  
37      // Tag interface
38      //-------------------------------------------------------------------------
39      public void doTag(XMLOutput output) throws MissingAttributeException, JellyTagException {
40          if ( name == null ) {
41              throw new MissingAttributeException("name");
42          }
43          MapMessageTag tag = (MapMessageTag) findAncestorWithClass( MapMessageTag.class );
44          if ( tag == null ) {
45              throw new JellyTagException("<jms:mapEntry> tag must be within a <jms:mapMessage> tag");
46          }
47  
48          if (value != null) {
49              tag.addEntry( name, value );
50          }
51          else {
52              tag.addEntry( name, getBodyText() );
53          }
54      }
55  
56      // Properties
57      //-------------------------------------------------------------------------
58      /*** Sets the name of the entry in the map message
59        */
60      public void setName(String name) {
61          this.name = name;
62      }
63  
64      /*** Sets the value of the entry in the map message.
65        * If no value is set then the body of the tag is used
66        */
67      public void setValue(Object value) {
68          this.value = value;
69      }
70  }