CommonsLogFactoryBean.java
Upload User: jiancairen
Upload Date: 2007-08-27
Package Size: 26458k
Code Size: 2k
Category:

Java Develop

Development Platform:

Java

  1. /*
  2.  * Copyright 2002-2004 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. package org.springframework.beans.factory.config;
  17. import org.apache.commons.logging.Log;
  18. import org.apache.commons.logging.LogFactory;
  19. import org.springframework.beans.factory.FactoryBean;
  20. /**
  21.  * Factory bean for
  22.  * <a href="http://jakarta.apache.org/commons/logging.html">commons-logging</a>
  23.  * Log instances.
  24.  * Will expose the created Log object on getBean calls, and can be passed
  25.  * to bean properites of type org.apache.commons.logging.Log.
  26.  *
  27.  * <p>Useful for sharing Log instances among multiple beans instead of using
  28.  * one Log instance per class name, e.g. for common log topics.
  29.  *
  30.  * @author Juergen Hoeller
  31.  * @since 16.11.2003
  32.  * @see org.apache.commons.logging.Log
  33.  */
  34. public class CommonsLogFactoryBean implements FactoryBean {
  35.   private Log log = null;
  36.   public void setLogName(String logName) {
  37. if (logName == null) {
  38. throw new IllegalArgumentException("'logName' must be specified");
  39. }
  40.     this.log = LogFactory.getLog(logName);
  41.   }
  42.   public Object getObject() {
  43.     return log;
  44.   }
  45. public Class getObjectType() {
  46. return (this.log != null ? this.log.getClass() : Log.class);
  47. }
  48.   public boolean isSingleton() {
  49.     return true;
  50.   }
  51. }