⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 optionconverter.java

📁 log4j2me 是一个在j2me上使用的log4j风格的源码
💻 JAVA
字号:
/*
 * Copyright (C) The Apache Software Foundation. All rights reserved.
 *
 * This software is published under the terms of the Apache Software
 * License version 1.1, a copy of which has been included with this
 * distribution in the LICENSE.txt file.  */
//Modifiers:	Witmate [Nov,2004: Modified for log4j2me]

package org.apache.log4j.helpers;

import log4j2me.util.Properties;

public class OptionConverter {

  public
  static
  boolean toBoolean(String value, boolean defaultVal) {
    if(value == null)
      return defaultVal;
    String trimmedVal = value.trim();
    if("true".equals(trimmedVal.toLowerCase())) 
  	return true;
    if("false".equals(trimmedVal.toLowerCase()))
      return false;
    return defaultVal;
  }


  public
  static
  Object instantiateByKey(Properties props, String key, Class superClass,
				Object defaultValue) {

    // Get the value of the property in string form
    String className = props.getProperty(key);    
    if(className == null) {
      LogLog.error("Could not find value for " + key);
      return defaultValue;
    }
    // Trim className to avoid trailing spaces that cause problems.
    /*Object obj=OptionConverter.instantiateByClassName(className.trim(), superClass,
			  defaultValue);
    LogLog.debug("OKOK:"+obj.toString());
    return obj;*/
    return OptionConverter.instantiateByClassName(className.trim(), superClass, defaultValue);
  }


    /**
     Instantiate an object given a class name. Check that the
     <code>className</code> is a subclass of <code>superClass</code>.

   */
  public
  static
  Object instantiateByClassName(String className, Class superClass,
				Object defaultValue) {
  	LogLog.debug("instantiateByClassName Here:"+className+","+superClass.toString());
    if(className != null) {
      try {
      	Class classObj = Class.forName(className);
      	if(!superClass.isAssignableFrom(classObj)){ 
      		LogLog.error("A \""+className+"\" object is not assignable to a \""+
      				superClass.getName() + "\" object.");
      	}
      	/*Object obj=classObj.newInstance();
      	LogLog.debug(obj.toString());
      	return obj;*/
      	return classObj.newInstance();
      }
      catch (Exception e) {
      	LogLog.error("Could not instantiate class [" + className + "].", e);
      }
    }
    return defaultValue;    
  }



}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -