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 java.util.Iterator;
19  import java.util.Map;
20  
21  import javax.jms.Message;
22  import javax.jms.MapMessage;
23  import javax.jms.JMSException;
24  
25  import org.apache.commons.jelly.JellyTagException;
26  
27  /*** Creates a JMS MapMessage
28    *
29    * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
30    * @version $Revision: 155420 $
31    */
32  public class MapMessageTag extends MessageTag {
33  
34      public MapMessageTag() {
35      }
36  
37      public void addEntry(String name, Object value) throws JellyTagException {
38          MapMessage message = (MapMessage) getMessage();
39          try {
40              message.setObject(name, value);
41          }
42          catch (JMSException e) {
43              throw new JellyTagException(e);
44          }
45      }
46  
47      // Properties
48      //-------------------------------------------------------------------------
49  
50      /***
51       * Sets the Map of entries to be used for this Map Message
52       */
53      public void setMap(Map map) throws JellyTagException {
54          MapMessage message = (MapMessage) getMessage();
55          for (Iterator iter = map.entrySet().iterator(); iter.hasNext(); ) {
56              Map.Entry entry = (Map.Entry) iter.next();
57              String name = entry.getKey().toString();
58              Object value = entry.getValue();
59  
60              try {
61                  message.setObject(name, value);
62              }
63              catch (JMSException e) {
64                  throw new JellyTagException(e);
65              }
66          }
67      }
68  
69      // Implementation methods
70      //-------------------------------------------------------------------------
71      protected Message createMessage() throws JellyTagException {
72          try {
73              return getConnection().createMapMessage();
74          } catch (JMSException e) {
75              throw new JellyTagException(e);
76          }
77      }
78  }