01: /*
02: * Copyright 2002-2005 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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,
37: InitializingBean {
38:
39: private Log log;
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 logName) {
47: this .log = LogFactory.getLog(logName);
48: }
49:
50: public void afterPropertiesSet() {
51: if (this .log == null) {
52: throw new IllegalArgumentException("logName is required");
53: }
54: }
55:
56: public Object getObject() {
57: return log;
58: }
59:
60: public Class getObjectType() {
61: return (this .log != null ? this .log.getClass() : Log.class);
62: }
63:
64: public boolean isSingleton() {
65: return true;
66: }
67:
68: }
|