KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > avalon > excalibur > logger > decorator > LoggerManagerDecorator


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
14  * implied.
15  *
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */

19 package org.apache.avalon.excalibur.logger.decorator;
20
21 import org.apache.avalon.excalibur.logger.LoggerManager;
22 import org.apache.avalon.framework.activity.Disposable;
23 import org.apache.avalon.framework.activity.Startable;
24 import org.apache.avalon.framework.configuration.Configurable;
25 import org.apache.avalon.framework.configuration.Configuration;
26 import org.apache.avalon.framework.configuration.ConfigurationException;
27 import org.apache.avalon.framework.container.ContainerUtil;
28 import org.apache.avalon.framework.context.Context;
29 import org.apache.avalon.framework.context.ContextException;
30 import org.apache.avalon.framework.context.Contextualizable;
31 import org.apache.avalon.framework.logger.LogEnabled;
32 import org.apache.avalon.framework.logger.Logger;
33
34 /**
35  * This is the base class to create LoggerManager decorators.
36  * It passes all lifecycle and LoggerManagerc
37  * calls onto the wrapped object.
38  *
39  * <p> Decorators are expected to be slim - be able to run
40  * for instance both with and without having their
41  * enableLogging() method called.
42  *
43  * <p> This constraint is imposed to allow decorators to
44  * be applicable to an object both at its burth, like
45  *
46  * <pre>
47  * C c = new C();
48  * DecoratorX d = new DecoratorX( c );
49  * x.enableLogging( logger );
50  * </pre>
51  *
52  * and after the object has been completely configured
53  *
54  * <pre>
55  * C c = (C)manager.lookup( C.ROLE );
56  * DecoratorX d = new DecoratorX( c );
57  * </pre>
58  *
59  * If this constrianed is not obeyed this should be clearly
60  * stated in the javadocs. For instance, LogToSelfDecorator
61  * _only_ makes sense if it passes the <code>enableLogging</code>
62  * call through it.
63  *
64  * <p>
65  * This implementation is incomplete,
66  * it passes only those calls that are needed in
67  *
68  * <code>org.apache.avalon.excalibur.logger.decorator.*</code> and
69  * <code>org.apache.avalon.excalibur.logger.adapter.*</code>:
70  * <pre>
71  * LogEnabled
72  * Contextualizable
73  * Configurable
74  * Startable
75  * Disposable
76  * </pre>
77  *
78  * This object differes from LoggerManagerTee by being abstract,
79  * by absence of addTee() public method and by implementation.
80  * LoggerManagerTee might be used instead of this but maintaining
81  * it as a separate class seemed cleaner.
82  *
83  * @author <a HREF="mailto:dev@avalon.apache.org">Avalon Development Team</a>
84  * @version CVS $Revision: 1.4 $ $Date: 2004/03/10 13:54:50 $
85  * @since 4.0
86  */

87 public abstract class LoggerManagerDecorator implements
88         LoggerManager,
89         LogEnabled,
90         Contextualizable,
91         Configurable,
92         Startable,
93         Disposable
94 {
95     /**
96      * The wrapped-in LoggerManager.
97      */

98     protected final LoggerManager m_loggerManager;
99
100     public LoggerManagerDecorator( final LoggerManager loggerManager )
101     {
102         if ( loggerManager == null ) throw new NullPointerException JavaDoc( "loggerManager" );
103         m_loggerManager = loggerManager;
104     }
105
106     public void enableLogging( final Logger logger )
107     {
108         ContainerUtil.enableLogging( m_loggerManager, logger );
109     }
110
111     public void contextualize( final Context context ) throws ContextException
112     {
113         ContainerUtil.contextualize( m_loggerManager, context );
114     }
115     
116     public void configure( final Configuration configuration ) throws ConfigurationException
117     {
118         ContainerUtil.configure( m_loggerManager, configuration );
119     }
120
121     public void start() throws Exception JavaDoc
122     {
123         ContainerUtil.start( m_loggerManager );
124     }
125
126     public void stop() throws Exception JavaDoc
127     {
128         ContainerUtil.stop( m_loggerManager );
129     }
130
131     public void dispose()
132     {
133         ContainerUtil.dispose( m_loggerManager );
134     }
135
136     /**
137      * Return the Logger for the specified category.
138      */

139     public Logger getLoggerForCategory( final String JavaDoc categoryName )
140     {
141         return m_loggerManager.getLoggerForCategory( categoryName );
142     }
143
144     /**
145      * Return the default Logger. This is basically the same
146      * as getting the Logger for the "" category.
147      */

148     public Logger getDefaultLogger()
149     {
150         return m_loggerManager.getDefaultLogger();
151     }
152 }
153
Popular Tags