KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > acting > JMSPublisherAction


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 package org.apache.cocoon.acting;
17
18 import java.util.Collections JavaDoc;
19 import java.util.Map JavaDoc;
20
21 import javax.jms.Message JavaDoc;
22
23 import org.apache.avalon.framework.parameters.Parameters;
24 import org.apache.avalon.framework.thread.ThreadSafe;
25 import org.apache.cocoon.environment.Redirector;
26 import org.apache.cocoon.environment.SourceResolver;
27
28 import org.apache.cocoon.components.jms.AbstractMessagePublisher;
29
30 /**
31  * Action to publish TextMessages to a JMS Topic. For description of static
32  * parameter configuration see {@link org.apache.cocoon.components.jms.AbstractMessagePublisher}
33  *
34  * <p>Sitemap parameters:</p>
35  * <table border="1">
36  * <tbody>
37  * <tr>
38  * <th align="left">parameter</th>
39  * <th align="left">required</th>
40  * <th align="left">default</th>
41  * <th align="left">description</th>
42  * </tr>
43  * <tbody>
44  * <tr>
45  * <td>message</td>
46  * <td>required</td>
47  * <td>&nbsp;</td>
48  * <td>Content of TextMessage to publish</td>
49  * </tr>
50  * </tbody>
51  * </table>
52  */

53 public class JMSPublisherAction extends AbstractMessagePublisher implements Action, ThreadSafe {
54
55     // ---------------------------------------------------- Constants
56

57     private static final String JavaDoc MESSAGE_PARAM = "message";
58
59     // ---------------------------------------------------- Lifecycle
60

61     public JMSPublisherAction () {
62     }
63
64     // ---------------------------------------------------- Action
65

66     public Map JavaDoc act(Redirector redirector,
67                    SourceResolver resolver,
68                    Map JavaDoc objectModel,
69                    String JavaDoc source,
70                    Parameters parameters) throws Exception JavaDoc {
71
72         Map JavaDoc result = null;
73         try {
74             // publish the message
75
final String JavaDoc event = parameters.getParameter(MESSAGE_PARAM);
76             final Message JavaDoc message = m_session.createTextMessage(event);
77             publishMessage(message);
78             result = Collections.EMPTY_MAP;
79         } catch (Exception JavaDoc e) {
80             if (getLogger().isWarnEnabled()) {
81                 getLogger().warn("Error delivering message.", e);
82             }
83         }
84
85         return result;
86     }
87
88 }
89
Popular Tags