KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > protomatter > syslog > xml > JMSLog_Helper


1 package com.protomatter.syslog.xml;
2
3 /**
4  * {{{ The Protomatter Software License, Version 1.0
5  * derived from The Apache Software License, Version 1.1
6  *
7  * Copyright (c) 1998-2002 Nate Sammons. All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  *
13  * 1. Redistributions of source code must retain the above copyright
14  * notice, this list of conditions and the following disclaimer.
15  *
16  * 2. Redistributions in binary form must reproduce the above copyright
17  * notice, this list of conditions and the following disclaimer in
18  * the documentation and/or other materials provided with the
19  * distribution.
20  *
21  * 3. The end-user documentation included with the redistribution,
22  * if any, must include the following acknowledgment:
23  * "This product includes software developed for the
24  * Protomatter Software Project
25  * (http://protomatter.sourceforge.net/)."
26  * Alternately, this acknowledgment may appear in the software itself,
27  * if and wherever such third-party acknowledgments normally appear.
28  *
29  * 4. The names "Protomatter" and "Protomatter Software Project" must
30  * not be used to endorse or promote products derived from this
31  * software without prior written permission. For written
32  * permission, please contact support@protomatter.com.
33  *
34  * 5. Products derived from this software may not be called "Protomatter",
35  * nor may "Protomatter" appear in their name, without prior written
36  * permission of the Protomatter Software Project
37  * (support@protomatter.com).
38  *
39  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
40  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
41  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
42  * DISCLAIMED. IN NO EVENT SHALL THE PROTOMATTER SOFTWARE PROJECT OR
43  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
45  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
46  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
47  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
48  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
49  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
50  * SUCH DAMAGE. }}}
51  */

52
53 import java.io.*;
54 import java.net.*;
55 import java.util.*;
56 import java.text.*;
57
58 import com.protomatter.xml.*;
59 import com.protomatter.syslog.*;
60 import org.jdom.*;
61
62 /**
63  * XML configuration helper for <tt>JMSLog</tt>.
64  */

65 public class JMSLog_Helper
66 extends BasicLogger_Helper
67 {
68  /**
69   * Configure this logger given the XML element.
70   * The <tt>&lt;Logger&gt;</tt> element should look like this:<P>
71   *
72   * <TABLE BORDER=1 CELLPADDING=4 CELLSPACING=0 WIDTH="90%">
73   * <TR><TD>
74   * <PRE><B>
75   *
76   * &lt;Logger class="com.protomatter.syslog.JMSLog" &gt;
77   *
78   * <font color="#888888">&lt;!--
79   * Config params from {@link BasicLogger_Helper#configure(Object,Element) BasicLogger_Helper}
80   * can get inserted here.
81   * --&gt;</font>
82   *
83   * &lt;factoryName&gt;<i>JNDI-name</i>&lt;/factoryName&gt;
84   * &lt;topicName&gt;<i>JNDI-name</i>&lt;/topicName&gt;
85   *
86   * &lt;connectionUser&gt;<i>UserName</i>&lt;/connectionUser&gt;
87   * &lt;connectionPass&gt;<i>Password</i>&lt;/connectionPass&gt;
88   *
89   * &lt;persistent&gt;<i>true|false</i>&lt;/persistent&gt;
90   * &lt;ttl&gt;<i>TimeToLive</i>&lt;/ttl&gt;
91   * &lt;priority&gt;<i>Priority</i>&lt;/priority&gt;
92   *
93   * &lt;/Logger&gt;
94   * </B></PRE>
95   * </TD></TR></TABLE><P>
96   *
97   * <TABLE BORDER=1 CELLPADDING=2 CELLSPACING=0 WIDTH="90%">
98   * <TR CLASS="TableHeadingColor">
99   * <TD COLSPAN=3><B>Element</B></TD>
100   * </TR>
101   * <TR CLASS="TableHeadingColor">
102   * <TD><B>name</B></TD>
103   * <TD><B>value</B></TD>
104   * <TD><B>required</B></TD>
105   * </TR>
106   *
107   * <TR CLASS="TableRowColor">
108   * <TD VALIGN=TOP><TT>topicName</TT></TD>
109   * <TD>The JNDI location of a JMS Topic to send messages to.
110   * </TD>
111   * <TD VALIGN=TOP>yes</TD>
112   * </TR>
113   *
114   * <TR CLASS="TableRowColor">
115   * <TD VALIGN=TOP><TT>factoryName</TT></TD>
116   * <TD>The JNDI location of a JMS TopicConnectionFactory
117   * to use to create the JMS session and publisher.
118   * </TD>
119   * <TD VALIGN=TOP>yes</TD>
120   * </TR>
121   *
122   * <TR CLASS="TableRowColor">
123   * <TD VALIGN=TOP><TT>connectionUser</TT></TD>
124   * <TD>If this property is present, it is used as
125   * the username to use in creating the JMS connection.
126   * </TD>
127   * <TD VALIGN=TOP>no</TD>
128   * </TR>
129   *
130   * <TR CLASS="TableRowColor">
131   * <TD VALIGN=TOP><TT>connectionPass</TT></TD>
132   * <TD>If this property is present, it is used as
133   * the password to use in creating the JMS connection.
134   * </TD>
135   * <TD VALIGN=TOP>no</TD>
136   * </TR>
137   *
138   * <TR CLASS="TableRowColor">
139   * <TD VALIGN=TOP><TT>ttl</TT></TD>
140   * <TD>Message time to live in milliseconds. Default is
141   * 30 minutes.
142   * </TD>
143   * <TD VALIGN=TOP>no</TD>
144   * </TR>
145   *
146   * <TR CLASS="TableRowColor">
147   * <TD VALIGN=TOP><TT>priority</TT></TD>
148   * <TD>Message priority. Default is 5.
149   * </TD>
150   * <TD VALIGN=TOP>no</TD>
151   * </TR>
152   *
153   * <TR CLASS="TableRowColor">
154   * <TD VALIGN=TOP><TT>persistent</TT></TD>
155   * <TD>Should persistent JMS be used? Default is false.
156   * </TD>
157   * <TD VALIGN=TOP>no</TD>
158   * </TR>
159   *
160   * </TABLE><P>
161   *
162   * For example: If you are using BEA WebLogic, you can add the
163   * following lines to your <tt>weblogic.properties</tt> file
164   * to configure a JMS topic and connection factory:<P>
165   *
166   * <TABLE BORDER=1 CELLPADDING=4 CELLSPACING=0 WIDTH="90%">
167   * <TR><TD>
168   * <PRE><B>
169   * weblogic.jms.topic.syslog=jms.topic.syslog
170   * weblogic.jms.connectionFactoryName.syslog=jms.connection.syslogFactory
171   * </B></PRE>
172   * </TD></TR></TABLE><P>
173   *
174   * Then set "<TT>topicName</tt>" to "<TT>jms.topic.syslog</tt>"
175   * and "<TT>factoryName</tt>" to "<TT>jms.connection.syslogFactory</tt>".
176   * You will be able to route syslog messages through that JMS topic to a
177   * remote machine that is running the
178   * {@link com.protomatter.syslog.SyslogServer SyslogServer} program.
179   */

180   public void configure(Object JavaDoc o, Element e)
181   throws SyslogInitException
182   {
183     super.configure(o, e);
184     JMSLog log = (JMSLog)o;
185
186     if (Syslog.getLocalHostName() == null)
187       Syslog.setLocalHostName();
188
189     String JavaDoc tmp = null;
190
191     tmp = e.getChildTextTrim("topicName", e.getNamespace());
192     if (tmp != null)
193       log.setTopicName(tmp);
194     else
195       throw new IllegalArgumentException JavaDoc(MessageFormat.format(
196         Syslog.getResourceString(MessageConstants.XML_MUST_SPECIFY_PARAM_MESSAGE),
197         new Object JavaDoc[] { "topicName" } ));
198
199     tmp = e.getChildTextTrim("factoryName", e.getNamespace());
200     if (tmp != null)
201       log.setFactoryName(tmp);
202     else
203       throw new IllegalArgumentException JavaDoc(MessageFormat.format(
204         Syslog.getResourceString(MessageConstants.XML_MUST_SPECIFY_PARAM_MESSAGE),
205         new Object JavaDoc[] { "factoryName" } ));
206
207     tmp = e.getChildTextTrim("connectionUser", e.getNamespace());
208     if (tmp != null)
209       log.setUser(tmp);
210
211     tmp = e.getChildTextTrim("connectionPass", e.getNamespace());
212     if (tmp != null)
213       log.setPass(tmp);
214
215     tmp = e.getChildTextTrim("persistent");
216     if (tmp != null)
217       log.setPersistent(tmp.equalsIgnoreCase("true"));
218
219     tmp = e.getChildTextTrim("ttl");
220     if (tmp != null)
221       log.setTTL(Integer.parseInt(tmp));
222
223     tmp = e.getChildTextTrim("priority");
224     if (tmp != null)
225       log.setPriority(Integer.parseInt(tmp));
226
227     log.start();
228   }
229
230   public Element getConfiguration(Object JavaDoc o, Element element)
231   {
232     Element e = super.getConfiguration(o, element);
233     JMSLog log = (JMSLog)o;
234
235     e.getChildren().add(
236       (new Element("topicName")).setText(log.getTopicName()));
237     e.getChildren().add(
238       (new Element("factoryName")).setText(log.getFactoryName()));
239
240     if (log.getUser() != null)
241     {
242       e.getChildren().add(
243         (new Element("connectionUser")).setText(log.getUser()));
244       e.getChildren().add(
245         (new Element("connectionPass")).setText(log.getPass()));
246     }
247
248     e.getChildren().add((new Element("persistent"))
249       .setText(String.valueOf(log.getPersistent())));
250     e.getChildren().add((new Element("priority"))
251       .setText(String.valueOf(log.getPriority())));
252     e.getChildren().add((new Element("ttl"))
253       .setText(String.valueOf(log.getTTL())));
254     return e;
255   }
256 }
257
Popular Tags