KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > idaremedia > antx > feedback > DefaultEmitConfiguration


1 /**
2  * $Id: DefaultEmitConfiguration.java 180 2007-03-15 12:56:38Z ssmc $
3  * Copyright 2002-2004 iDare Media, Inc. All rights reserved.
4  *
5  * Originally written by iDare Media, Inc. for release into the public domain. This
6  * library, source form and binary form, is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public License as published by the
8  * Free Software Foundation; either version 2 of the License, or (at your option) any later
9  * version.<p>
10  *
11  * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
12  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13  * See the GNU LGPL (GNU Lesser General Public License) for more details.<p>
14  *
15  * You should have received a copy of the GNU Lesser General Public License along with this
16  * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite
17  * 330, Boston, MA 02111-1307 USA. The LGPL can be found online at
18  * http://www.fsf.org/copyleft/lesser.html<p>
19  *
20  * This product has been influenced by several projects within the open-source community.
21  * The JWare developers wish to acknowledge the open-source community's support. For more
22  * information regarding the open-source products used within JWare, please visit the
23  * JWare website.
24  *----------------------------------------------------------------------------------------*
25  * WEBSITE- http://www.jware.info EMAIL- inquiries@jware.info
26  *----------------------------------------------------------------------------------------*
27  **/

28
29 package com.idaremedia.antx.feedback;
30
31 import java.text.DateFormat JavaDoc;
32 import java.util.Date JavaDoc;
33
34 import com.idaremedia.apis.DiagnosticsEmitter;
35
36 import com.idaremedia.antx.AntX;
37 import com.idaremedia.antx.AntXFixture;
38 import com.idaremedia.antx.NoiseLevel;
39 import com.idaremedia.antx.helpers.DateTimeFormat;
40 import com.idaremedia.antx.helpers.Tk;
41
42 /**
43  * Class that embodies the AntX defaults for each EmitConfiguration attribute and
44  * behavior. The root emitter used by the default configuration can be customized.
45  * Just set the System property: {@linkplain AntX#DEFAULT_ROOT_CATEGORY_PROP
46  * DEFAULT_ROOT_CATEGORY_PROP} to the desired root category's name.
47  *
48  * @since JWare/AntX 0.1
49  * @author ssmc, &copy;2002-2004 <a HREF="http://www.jware.info">iDare&nbsp;Media,&nbsp;Inc.</a>
50  * @version 0.5
51  * @.safety multiple
52  * @.group impl,helper
53  * @see LJDiagnosticsEmitter
54  * @see EmitContext#getConfiguration
55  **/

56
57 public final class DefaultEmitConfiguration implements EmitConfiguration
58 {
59     /**
60      * VM/ClassLoader shareable singleton.
61      **/

62     public final static DefaultEmitConfiguration INSTANCE=
63         new DefaultEmitConfiguration();
64
65
66     /**
67      * Initializes a new default configuration. Anyone can create a default
68      * instance although the singleton is all that's needed for most uses.
69      **/

70     public DefaultEmitConfiguration()
71     {
72         String JavaDoc grpId= AntXFixture.getProperty(AntX.DEFAULT_ROOT_CATEGORY_PROP);
73
74         if (!Tk.isWhitespace(grpId)) {
75             m_rootEmitter = LJDiagnosticsEmitter.FACTORY.newEmitter(grpId);
76             m_grpId = grpId;
77         } else {
78             m_rootEmitter = LJDiagnosticsEmitter.FACTORY.newEmitter();
79             m_grpId = "";
80         }
81     }
82
83
84     /**
85      * Returns the default log4j category separator (dot).
86      * @since JWare/AntX 0.3
87      **/

88     public String JavaDoc getGroupingPathSeparator()
89     {
90         return ".";
91     }
92
93
94     /**
95      * Returns either the empty string or the custom root grouping defined
96      * in the system properties. Never returns <i>null</i>.
97      * @since JWare/AntX 0.3
98      **/

99     public String JavaDoc getFrom()
100     {
101         return m_grpId;
102     }
103
104
105     /**
106      * Returns a wrapper for the root Log4j logger.
107      **/

108     public DiagnosticsEmitter getEmitter()
109     {
110         return m_rootEmitter;
111     }
112
113
114     /**
115      * Returns a wrapper for the Log4j logger of specified
116      * grouping. Note: this method creates a new emitter instance
117      * everytime it is called.
118      **/

119     public DiagnosticsEmitter getCustomEmitter(String JavaDoc grpId)
120     {
121         return LJDiagnosticsEmitter.FACTORY.newEmitter(grpId);
122     }
123
124
125     /**
126      * Returns the default runtime noiselevel.
127      * @see com.idaremedia.antx.NoiseLevel#getDefault
128      **/

129     public NoiseLevel getNoiseLevel()
130     {
131         return NoiseLevel.getDefault(null);
132     }
133
134
135     /**
136      * Updates incoming buffer with list of special properties values
137      * to be recorded. No-op.
138      **/

139     public boolean getPropertiesNameList(StringBuffer JavaDoc list)
140     {
141         return false;
142     }
143
144
145     /**
146      * Returns <i>false</i> to exclude timestamps by default.
147      **/

148     public boolean wantTimestamp()
149     {
150         return false;
151     }
152
153
154     /**
155      * Returns the simple AntX ABBREVIATED formatted date-time
156      * string. Format string like: "dd-MMM h:m a"
157      * @param ms the timestamp (milliseconds)
158      * @see DateTimeFormat#ABBREV
159      **/

160     public String JavaDoc stampify(long ms)
161     {
162         synchronized(m_defaultFormat) {
163             return m_defaultFormat.format(new Date JavaDoc(ms));
164         }
165     }
166
167
168     /**
169      * Returns <i>true</i> so all emitted messages are also passed
170      * through the standard Ant logging mechanism.
171      **/

172     public boolean shouldEcho()
173     {
174         return true;
175     }
176
177
178     private final DiagnosticsEmitter m_rootEmitter;
179     private final String JavaDoc m_grpId;
180
181     private final DateFormat JavaDoc m_defaultFormat=
182         (DateFormat JavaDoc)DateTimeFormat.ABBREV.clone();//NB:our own sync
183
}
184
185 /* end-of-DefaultEmitConfiguration.java */
186
Popular Tags