001    // SECTION-START[License Header]
002    // <editor-fold defaultstate="collapsed" desc=" Generated License ">
003    /*
004     *   Java Object Management and Configuration
005     *   Copyright (C) Christian Schulte, 2005-206
006     *   All rights reserved.
007     *
008     *   Redistribution and use in source and binary forms, with or without
009     *   modification, are permitted provided that the following conditions
010     *   are met:
011     *
012     *     o Redistributions of source code must retain the above copyright
013     *       notice, this list of conditions and the following disclaimer.
014     *
015     *     o Redistributions in binary form must reproduce the above copyright
016     *       notice, this list of conditions and the following disclaimer in
017     *       the documentation and/or other materials provided with the
018     *       distribution.
019     *
020     *   THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
021     *   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
022     *   AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
023     *   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT,
024     *   INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
025     *   NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
026     *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
027     *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
028     *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
029     *   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
030     *
031     *   $JOMC: CommonsLogger.java 4274 2012-02-17 04:07:29Z schulte2005 $
032     *
033     */
034    // </editor-fold>
035    // SECTION-END
036    package org.jomc.logging.ri.commons;
037    
038    import java.util.logging.Level;
039    import org.apache.commons.logging.Log;
040    import org.apache.commons.logging.LogFactory;
041    
042    // SECTION-START[Documentation]
043    // <editor-fold defaultstate="collapsed" desc=" Generated Documentation ">
044    /**
045     * Object management and configuration logging system implementation backed by Apache Commons Logging.
046     *
047     * <dl>
048     *   <dt><b>Identifier:</b></dt><dd>org.jomc.logging.ri.commons.CommonsLogger</dd>
049     *   <dt><b>Name:</b></dt><dd>JOMC Logging Commons Logging</dd>
050     *   <dt><b>Specifications:</b></dt>
051     *     <dd>org.jomc.logging.Logger @ 1.0</dd>
052     *     <dd>org.jomc.spi.Listener @ 1.0</dd>
053     *   <dt><b>Abstract:</b></dt><dd>No</dd>
054     *   <dt><b>Final:</b></dt><dd>No</dd>
055     *   <dt><b>Stateless:</b></dt><dd>Yes</dd>
056     * </dl>
057     *
058     * @author <a href="mailto:schulte2005@users.sourceforge.net">Christian Schulte</a> 1.0
059     * @version 1.1
060     */
061    // </editor-fold>
062    // SECTION-END
063    // SECTION-START[Annotations]
064    // <editor-fold defaultstate="collapsed" desc=" Generated Annotations ">
065    @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.2", comments = "See http://jomc.sourceforge.net/jomc/1.2/jomc-tools-1.2" )
066    // </editor-fold>
067    // SECTION-END
068    public final class CommonsLogger
069        implements
070        org.jomc.logging.Logger,
071        org.jomc.spi.Listener
072    {
073        // SECTION-START[Constructors]
074        // <editor-fold defaultstate="collapsed" desc=" Generated Constructors ">
075        /** Creates a new {@code CommonsLogger} instance. */
076        @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.2", comments = "See http://jomc.sourceforge.net/jomc/1.2/jomc-tools-1.2" )
077        public CommonsLogger()
078        {
079            // SECTION-START[Default Constructor]
080            super();
081            // SECTION-END
082        }
083        // </editor-fold>
084        // SECTION-END
085        // SECTION-START[Logger]
086    
087        public boolean isDebugEnabled()
088        {
089            return this.getLogger().isDebugEnabled();
090        }
091    
092        public void debug( final String message )
093        {
094            this.getLogger().debug( message );
095        }
096    
097        public void debug( final Throwable throwable )
098        {
099            this.getLogger().debug( throwable.getMessage(), throwable );
100        }
101    
102        public void debug( final String message, final Throwable throwable )
103        {
104            this.getLogger().debug( message, throwable );
105        }
106    
107        public boolean isErrorEnabled()
108        {
109            return this.getLogger().isErrorEnabled();
110        }
111    
112        public void error( final String message )
113        {
114            this.getLogger().error( message );
115        }
116    
117        public void error( final Throwable throwable )
118        {
119            this.getLogger().error( throwable.getMessage(), throwable );
120        }
121    
122        public void error( final String message, final Throwable throwable )
123        {
124            this.getLogger().error( message, throwable );
125        }
126    
127        public boolean isFatalEnabled()
128        {
129            return this.getLogger().isFatalEnabled();
130        }
131    
132        public void fatal( final String message )
133        {
134            this.getLogger().fatal( message );
135        }
136    
137        public void fatal( final Throwable throwable )
138        {
139            this.getLogger().fatal( throwable.getMessage(), throwable );
140        }
141    
142        public void fatal( final String message, final Throwable throwable )
143        {
144            this.getLogger().fatal( message, throwable );
145        }
146    
147        public boolean isInfoEnabled()
148        {
149            return this.getLogger().isInfoEnabled();
150        }
151    
152        public void info( final String message )
153        {
154            this.getLogger().info( message );
155        }
156    
157        public void info( final Throwable throwable )
158        {
159            this.getLogger().info( throwable.getMessage(), throwable );
160        }
161    
162        public void info( final String message, final Throwable throwable )
163        {
164            this.getLogger().info( message, throwable );
165        }
166    
167        public boolean isTraceEnabled()
168        {
169            return this.getLogger().isTraceEnabled();
170        }
171    
172        public void trace( final String message )
173        {
174            this.getLogger().trace( message );
175        }
176    
177        public void trace( final Throwable throwable )
178        {
179            this.getLogger().trace( throwable.getMessage(), throwable );
180        }
181    
182        public void trace( final String message, final Throwable throwable )
183        {
184            this.getLogger().trace( message, throwable );
185        }
186    
187        public boolean isWarnEnabled()
188        {
189            return this.getLogger().isWarnEnabled();
190        }
191    
192        public void warn( final String message )
193        {
194            this.getLogger().warn( message );
195        }
196    
197        public void warn( final Throwable throwable )
198        {
199            this.getLogger().warn( throwable.getMessage(), throwable );
200        }
201    
202        public void warn( final String message, final Throwable throwable )
203        {
204            this.getLogger().warn( message, throwable );
205        }
206    
207        // SECTION-END
208        // SECTION-START[Listener]
209        public void onLog( final Level level, final String message, final Throwable throwable )
210        {
211            if ( level != null )
212            {
213                if ( level.equals( Level.CONFIG ) || level.equals( Level.FINE ) )
214                {
215                    this.getObjectManagementLogger().debug( message, throwable );
216                }
217                else if ( level.equals( Level.FINER ) || level.equals( Level.FINEST ) )
218                {
219                    this.getObjectManagementLogger().trace( message, throwable );
220                }
221                else if ( level.equals( Level.INFO ) )
222                {
223                    this.getObjectManagementLogger().info( message, throwable );
224                }
225                else if ( level.equals( Level.SEVERE ) )
226                {
227                    this.getObjectManagementLogger().error( message, throwable );
228                }
229                else if ( level.equals( Level.WARNING ) )
230                {
231                    this.getObjectManagementLogger().warn( message, throwable );
232                }
233                else
234                {
235                    this.getObjectManagementLogger().trace( message, throwable );
236                }
237            }
238        }
239    
240        // SECTION-END
241        // SECTION-START[CommonsLogger]
242        /**
243         * Gets the commons logging logger backing the instance.
244         *
245         * @return The commons logging logger backing the instance..
246         *
247         * @see #getName()
248         * @see LogFactory#getLog(java.lang.String)
249         */
250        public Log getLogger()
251        {
252            return LogFactory.getLog( this.getName() );
253        }
254    
255        // SECTION-END
256        // SECTION-START[Dependencies]
257        // <editor-fold defaultstate="collapsed" desc=" Generated Dependencies ">
258        /**
259         * Gets the {@code <ObjectManagementLogger>} dependency.
260         * <p>
261         *   This method returns the {@code <JOMC Logging Commons Logging>} object of the {@code <org.jomc.logging.Logger>} specification at specification level 1.0.
262         *   That specification does not apply to any scope. A new object is returned whenever requested and bound to this instance.
263         * </p>
264         * <p><strong>Properties:</strong>
265         *   <table border="1" width="100%" cellpadding="3" cellspacing="0">
266         *     <tr class="TableSubHeadingColor">
267         *       <th align="left" scope="col" nowrap><b>Name</b></th>
268         *       <th align="left" scope="col" nowrap><b>Type</b></th>
269         *       <th align="left" scope="col" nowrap><b>Documentation</b></th>
270         *     </tr>
271         *     <tr class="TableRow">
272         *       <td align="left" valign="top" nowrap>{@code <name>}</td>
273         *       <td align="left" valign="top" nowrap>{@code java.lang.String}</td>
274         *       <td align="left" valign="top">Name of the logger object management events are logged with.</td>
275         *     </tr>
276         *   </table>
277         * </p>
278         * <dl>
279         *   <dt><b>Final:</b></dt><dd>No</dd>
280         * </dl>
281         * @return Logger object management events are logged with.
282         * @throws org.jomc.ObjectManagementException if getting the dependency instance fails.
283         */
284        @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.2", comments = "See http://jomc.sourceforge.net/jomc/1.2/jomc-tools-1.2" )
285        private org.jomc.logging.Logger getObjectManagementLogger()
286        {
287            final org.jomc.logging.Logger _d = (org.jomc.logging.Logger) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getDependency( this, "ObjectManagementLogger" );
288            assert _d != null : "'ObjectManagementLogger' dependency not found.";
289            return _d;
290        }
291        // </editor-fold>
292        // SECTION-END
293        // SECTION-START[Properties]
294        // <editor-fold defaultstate="collapsed" desc=" Generated Properties ">
295        /**
296         * Gets the value of the {@code <name>} property.
297         * <p><dl>
298         *   <dt><b>Final:</b></dt><dd>No</dd>
299         * </dl></p>
300         * @return Name of the component events are logged for.
301         * @throws org.jomc.ObjectManagementException if getting the property instance fails.
302         */
303        @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.2", comments = "See http://jomc.sourceforge.net/jomc/1.2/jomc-tools-1.2" )
304        public java.lang.String getName()
305        {
306            final java.lang.String _p = (java.lang.String) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getProperty( this, "name" );
307            assert _p != null : "'name' property not found.";
308            return _p;
309        }
310        // </editor-fold>
311        // SECTION-END
312        // SECTION-START[Messages]
313        // SECTION-END
314    }