org.apache.log4j.helpers.Loader.loadClass()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(8.4k)|赞(0)|评价(0)|浏览(183)

本文整理了Java中org.apache.log4j.helpers.Loader.loadClass()方法的一些代码示例,展示了Loader.loadClass()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Loader.loadClass()方法的具体详情如下:
包路径:org.apache.log4j.helpers.Loader
类名称:Loader
方法名:loadClass

Loader.loadClass介绍

[英]If running under JDK 1.2 load the specified class using the Thread``contextClassLoader if that fails try Class.forname. Under JDK 1.1 only Class.forName is used.
[中]如果在JDK 1.2下运行,请使用Thread``contextClassLoader加载指定的类,如果失败,请尝试类。forname。仅在JDK1.1类下。使用forName。

代码示例

代码示例来源:origin: log4j/log4j

private
void readLevel(ObjectInputStream ois)
          throws java.io.IOException, ClassNotFoundException {
 int p = ois.readInt();
 try {
  String className = (String) ois.readObject();
  if(className == null) {
 level = Level.toLevel(p);
  } else {
 Method m = (Method) methodCache.get(className);
 if(m == null) {
  Class clazz = Loader.loadClass(className);
  // Note that we use Class.getDeclaredMethod instead of
  // Class.getMethod. This assumes that the Level subclass
  // implements the toLevel(int) method which is a
  // requirement. Actually, it does not make sense for Level
  // subclasses NOT to implement this method. Also note that
  // only Level can be subclassed and not Priority.
  m = clazz.getDeclaredMethod(TO_LEVEL, TO_LEVEL_PARAMS);
  methodCache.put(className, m);
 }
 PARAM_ARRAY[0] = new Integer(p);
 level = (Level) m.invoke(null,  PARAM_ARRAY);
  }
 } catch(Exception e) {
 LogLog.warn("Level deserialization failed, reverting to default.", e);
 level = Level.toLevel(p);
 }
}

代码示例来源:origin: log4j/log4j

Method m = (Method) methodCache.get(className);
if(m == null) {
 Class clazz = Loader.loadClass(className);

代码示例来源:origin: log4j/log4j

LogLog.debug("Parsing layout of class: \""+className+"\"");		 
try {
 Object instance     = Loader.loadClass(className).newInstance();
 Layout layout       = (Layout)instance;
 PropertySetter propSetter = new PropertySetter(layout);

代码示例来源:origin: log4j/log4j

LogLog.debug("Parsing throwableRenderer of class: \""+className+"\"");
try {
 Object instance     = Loader.loadClass(className).newInstance();
 ThrowableRenderer tr       = (ThrowableRenderer)instance;
 PropertySetter propSetter = new PropertySetter(tr);

代码示例来源:origin: log4j/log4j

if (converterObj instanceof String) {
 try {
  converterClass = Loader.loadClass((String) converterObj);
 } catch (ClassNotFoundException ex) {
   LogLog.warn(

代码示例来源:origin: log4j/log4j

LogLog.debug("Desired Level sub-class: ["+className+']');
try {	 
 Class clazz = Loader.loadClass(className);
 Method toLevelMethod = clazz.getMethod("toLevel", 
            ONE_STRING_PARAM);

代码示例来源:origin: log4j/log4j

Class customLevel = Loader.loadClass(clazz);

代码示例来源:origin: log4j/log4j

if(className != null) {
 try {
Class classObj = Loader.loadClass(className);
if(!superClass.isAssignableFrom(classObj)) {
 LogLog.error("A \""+className+"\" object is not assignable to a \""+

代码示例来源:origin: log4j/log4j

LogLog.debug("Class name: [" + className+']');    
try {
 Object instance     = Loader.loadClass(className).newInstance();
 Appender appender    = (Appender)instance;
 PropertySetter propSetter = new PropertySetter(appender);

代码示例来源:origin: log4j/log4j

LogLog.debug("Desired logger sub-class: ["+className+']');
 try {	 
Class clazz = Loader.loadClass(className);
Method getInstanceMethod = clazz.getMethod("getLogger", 
           ONE_STRING_PARAM);

代码示例来源:origin: log4j/log4j

/**
  Add a renderer to a hierarchy passed as parameter.
*/
static
public
void addRenderer(RendererSupport repository, String renderedClassName,
     String renderingClassName) {
 LogLog.debug("Rendering class: ["+renderingClassName+"], Rendered class: ["+
    renderedClassName+"].");
 ObjectRenderer renderer = (ObjectRenderer)
      OptionConverter.instantiateByClassName(renderingClassName,
             ObjectRenderer.class,
             null);
 if(renderer == null) {
  LogLog.error("Could not instantiate renderer ["+renderingClassName+"].");
  return;
 } else {
  try {
 Class renderedClass = Loader.loadClass(renderedClassName);
 repository.setRenderer(renderedClass, renderer);
  } catch(ClassNotFoundException e) {
 LogLog.error("Could not find class ["+renderedClassName+"].", e);
  }
 }
}

代码示例来源:origin: camunda/camunda-bpm-platform

private
void readLevel(ObjectInputStream ois)
          throws java.io.IOException, ClassNotFoundException {
 int p = ois.readInt();
 try {
  String className = (String) ois.readObject();
  if(className == null) {
 level = Level.toLevel(p);
  } else {
 Method m = (Method) methodCache.get(className);
 if(m == null) {
  Class clazz = Loader.loadClass(className);
  // Note that we use Class.getDeclaredMethod instead of
  // Class.getMethod. This assumes that the Level subclass
  // implements the toLevel(int) method which is a
  // requirement. Actually, it does not make sense for Level
  // subclasses NOT to implement this method. Also note that
  // only Level can be subclassed and not Priority.
  m = clazz.getDeclaredMethod(TO_LEVEL, TO_LEVEL_PARAMS);
  methodCache.put(className, m);
 }
 PARAM_ARRAY[0] = new Integer(p);
 level = (Level) m.invoke(null,  PARAM_ARRAY);
  }
 } catch(Exception e) {
 LogLog.warn("Level deserialization failed, reverting to default.", e);
 level = Level.toLevel(p);
 }
}

代码示例来源:origin: apache/log4j

private
void readLevel(ObjectInputStream ois)
          throws java.io.IOException, ClassNotFoundException {
 int p = ois.readInt();
 try {
  String className = (String) ois.readObject();
  if(className == null) {
 level = Level.toLevel(p);
  } else {
 Method m = (Method) methodCache.get(className);
 if(m == null) {
  Class clazz = Loader.loadClass(className);
  // Note that we use Class.getDeclaredMethod instead of
  // Class.getMethod. This assumes that the Level subclass
  // implements the toLevel(int) method which is a
  // requirement. Actually, it does not make sense for Level
  // subclasses NOT to implement this method. Also note that
  // only Level can be subclassed and not Priority.
  m = clazz.getDeclaredMethod(TO_LEVEL, TO_LEVEL_PARAMS);
  methodCache.put(className, m);
 }
 PARAM_ARRAY[0] = new Integer(p);
 level = (Level) m.invoke(null,  PARAM_ARRAY);
  }
 } catch(Exception e) {
 LogLog.warn("Level deserialization failed, reverting to default.", e);
 level = Level.toLevel(p);
 }
}

代码示例来源:origin: camunda/camunda-bpm-platform

if(className != null) {
 try {
Class classObj = Loader.loadClass(className);
if(!superClass.isAssignableFrom(classObj)) {
 LogLog.error("A \""+className+"\" object is not assignable to a \""+

代码示例来源:origin: camunda/camunda-bpm-platform

LogLog.debug("Parsing layout of class: \""+className+"\"");		 
try {
 Object instance     = Loader.loadClass(className).newInstance();
 Layout layout       = (Layout)instance;
 PropertySetter propSetter = new PropertySetter(layout);

代码示例来源:origin: apache/log4j

LogLog.debug("Parsing throwableRenderer of class: \""+className+"\"");
try {
 Object instance     = Loader.loadClass(className).newInstance();
 ThrowableRenderer tr       = (ThrowableRenderer)instance;
 PropertySetter propSetter = new PropertySetter(tr);

代码示例来源:origin: camunda/camunda-bpm-platform

LogLog.debug("Desired Level sub-class: ["+className+']');
try {	 
 Class clazz = Loader.loadClass(className);
 Method toLevelMethod = clazz.getMethod("toLevel", 
            ONE_STRING_PARAM);

代码示例来源:origin: camunda/camunda-bpm-platform

LogLog.debug("Desired logger sub-class: ["+className+']');
 try {	 
Class clazz = Loader.loadClass(className);
Method getInstanceMethod = clazz.getMethod("getLogger", 
           ONE_STRING_PARAM);

代码示例来源:origin: camunda/camunda-bpm-platform

/**
  Add a renderer to a hierarchy passed as parameter.
*/
static
public
void addRenderer(RendererSupport repository, String renderedClassName,
     String renderingClassName) {
 LogLog.debug("Rendering class: ["+renderingClassName+"], Rendered class: ["+
    renderedClassName+"].");
 ObjectRenderer renderer = (ObjectRenderer)
      OptionConverter.instantiateByClassName(renderingClassName,
             ObjectRenderer.class,
             null);
 if(renderer == null) {
  LogLog.error("Could not instantiate renderer ["+renderingClassName+"].");
  return;
 } else {
  try {
 Class renderedClass = Loader.loadClass(renderedClassName);
 repository.setRenderer(renderedClass, renderer);
  } catch(ClassNotFoundException e) {
 LogLog.error("Could not find class ["+renderedClassName+"].", e);
  }
 }
}

代码示例来源:origin: apache/log4j

/**
  Add a renderer to a hierarchy passed as parameter.
*/
static
public
void addRenderer(RendererSupport repository, String renderedClassName,
     String renderingClassName) {
 LogLog.debug("Rendering class: ["+renderingClassName+"], Rendered class: ["+
    renderedClassName+"].");
 ObjectRenderer renderer = (ObjectRenderer)
      OptionConverter.instantiateByClassName(renderingClassName,
             ObjectRenderer.class,
             null);
 if(renderer == null) {
  LogLog.error("Could not instantiate renderer ["+renderingClassName+"].");
  return;
 } else {
  try {
 Class renderedClass = Loader.loadClass(renderedClassName);
 repository.setRenderer(renderedClass, renderer);
  } catch(ClassNotFoundException e) {
 LogLog.error("Could not find class ["+renderedClassName+"].", e);
  }
 }
}

相关文章