KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > protomatter > syslog > xml > LengthRolloverLog_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>LengthRolloverLog</tt>.
64  */

65 public class LengthRolloverLog_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.LengthRolloverLog" &gt;
77    *
78    * <font color="#888888">&lt;!--
79    * Config params from {@link BasicLogger_Helper#configure(Object,Element) BasicLogger_Helper} can
80    * get inserted here.
81    * --&gt;</font>
82    *
83    * &lt;baseName&gt;<i>BaseFileName</i>&lt;/baseName&gt;
84    * &lt;extension&gt;<i>FilenameExtension</i>&lt;/extension&gt;
85    * &lt;rollsize&gt;<i>MaxFileSize</i>&lt;/rollsize&gt;
86    * &lt;append&gt;<i>true|false</i>&lt;/append&gt;
87    * &lt;autoFlush&gt;<i>true|false</i>&lt;/autoFlush&gt;
88    *
89    * &lt;/Logger&gt;
90    * </B></PRE>
91    * </TD></TR></TABLE><P>
92    *
93    * <TABLE BORDER=1 CELLPADDING=2 CELLSPACING=0 WIDTH="90%">
94    * <TR CLASS="TableHeadingColor">
95    * <TD COLSPAN=3><B>Element</B></TD>
96    * </TR>
97    * <TR CLASS="TableHeadingColor">
98    * <TD><B>name</B></TD>
99    * <TD><B>value</B></TD>
100    * <TD><B>required</B></TD>
101    * </TR>
102    *
103    * <TR CLASS="TableRowColor">
104    * <TD VALIGN=TOP><TT>baseName</TT></TD>
105    * <TD>The base name of the file to write to.
106    * </TD>
107    * <TD VALIGN=TOP>yes</TD>
108    * </TR>
109    *
110    * <TR CLASS="TableRowColor">
111    * <TD VALIGN=TOP><TT>extension</TT></TD>
112    * <TD>The filename extension to use.
113    * </TD>
114    * <TD VALIGN=TOP>no</TD>
115    * </TR>
116    *
117    * <TR CLASS="TableRowColor">
118    * <TD VALIGN=TOP><TT>rollsize</TT></TD>
119    * <TD>The maximum number of bytes to write to any
120    * one file.
121    * </TD>
122    * <TD VALIGN=TOP>no (default is 1MB)</TD>
123    * </TR>
124    *
125    * <TR CLASS="TableRowColor">
126    * <TD VALIGN=TOP><TT>append</TT></TD>
127    * <TD><tt>true</tt> or <tt>false</tt> -- decide if the file
128    * should be appended to (or overwritten).
129    * </TD>
130    * <TD VALIGN=TOP>no (default is <tt>true</tt>)</TD>
131    * </TR>
132    *
133    * <TR CLASS="TableRowColor">
134    * <TD VALIGN=TOP><TT>autoFlush</TT></TD>
135    * <TD><tt>true</tt> or <tt>false</tt> -- decide if we should
136    * flush the output stream after each log write. If this is
137    * set to <tt>false</tt> (the default), log writing will be fast,
138    * but if it is set to <tt>true</tt>, the log will always be
139    * up-to-date.
140    * </TD>
141    * <TD VALIGN=TOP>no (default is <tt>false</tt>)</TD>
142    * </TR>
143    *
144    * </TABLE><P>
145    */

146   public void configure(Object JavaDoc o, Element e)
147   throws SyslogInitException
148   {
149     super.configure(o, e);
150
151     LengthRolloverLog log = (LengthRolloverLog)o;
152
153     String JavaDoc tmp = e.getChildTextTrim("baseName", e.getNamespace());
154     if (tmp != null)
155     {
156       log.setBasename(tmp);
157     }
158     else
159     {
160       throw new IllegalArgumentException JavaDoc(MessageFormat.format(
161           Syslog.getResourceString(MessageConstants.XML_MUST_SPECIFY_PARAM_MESSAGE),
162           new Object JavaDoc[] { "baseName" } ));
163     }
164
165     tmp = e.getChildTextTrim("append", e.getNamespace());
166     log.setAppend("true".equalsIgnoreCase(tmp));
167
168     tmp = e.getChildTextTrim("autoFlush", e.getNamespace());
169     log.setAutoFlush("true".equalsIgnoreCase(tmp));
170
171     log.setExtension(e.getChildTextTrim("extension", e.getNamespace()));
172
173     tmp = e.getChildTextTrim("rollSize", e.getNamespace());
174     if (tmp != null)
175     {
176       try
177       {
178         log.setRollLength(Integer.parseInt(tmp));
179       }
180       catch (NumberFormatException JavaDoc x)
181       {
182         throw new IllegalArgumentException JavaDoc(MessageFormat.format(
183             Syslog.getResourceString(MessageConstants.MUST_BE_INTEGER_PARAM_MESSAGE),
184             new Object JavaDoc[] { "rollSize" } ));
185       }
186     }
187
188     log.rollover();
189   }
190
191   public Element getConfiguration(Object JavaDoc o, Element element)
192   {
193     Element e = super.getConfiguration(o, element);
194
195     LengthRolloverLog log = (LengthRolloverLog)o;
196
197     Element file = new Element("baseName");
198     file.setText(log.getBasename());
199     e.getChildren().add(file);
200
201     Element ext = new Element("extension");
202     ext.setText(log.getExtension());
203     e.getChildren().add(ext);
204
205     Element append = new Element("append");
206     append.setText(String.valueOf(log.getAppend()));
207     e.getChildren().add(append);
208
209     Element af = new Element("autoFlush");
210     af.setText(String.valueOf(log.getAutoFlush()));
211     e.getChildren().add(af);
212
213     Element roll = new Element("rollSize");
214     roll.setText(String.valueOf(log.getRollLength()));
215     e.getChildren().add(roll);
216
217     return e;
218   }
219 }
220
Popular Tags