KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > beans > factory > config > CommonsLogFactoryBean


1 /*
2  * Copyright 2002-2005 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.springframework.beans.factory.config;
18
19 import org.apache.commons.logging.Log;
20 import org.apache.commons.logging.LogFactory;
21 import org.springframework.beans.factory.FactoryBean;
22 import org.springframework.beans.factory.InitializingBean;
23
24 /**
25  * Factory bean for
26  * <a HREF="http://jakarta.apache.org/commons/logging.html">commons-logging</a>
27  * {@link org.apache.commons.logging.Log} instances.
28  *
29  * <p>Useful for sharing Log instances among multiple beans instead of using
30  * one Log instance per class name, e.g. for common log topics.
31  *
32  * @author Juergen Hoeller
33  * @see org.apache.commons.logging.Log
34  * @since 16.11.2003
35  */

36 public class CommonsLogFactoryBean implements FactoryBean, InitializingBean {
37
38     private Log log;
39
40
41     /**
42      * The name of the log.
43      * <p>This property is required.
44      * @param logName the name of the log
45      */

46     public void setLogName(String JavaDoc logName) {
47         this.log = LogFactory.getLog(logName);
48     }
49
50
51     public void afterPropertiesSet() {
52         if (this.log == null) {
53             throw new IllegalArgumentException JavaDoc("logName is required");
54         }
55     }
56
57     public Object JavaDoc getObject() {
58         return log;
59     }
60
61     public Class JavaDoc getObjectType() {
62         return (this.log != null ? this.log.getClass() : Log.class);
63     }
64
65     public boolean isSingleton() {
66         return true;
67     }
68
69 }
70
Popular Tags