ch.qos.logback.core.util.Loader类的使用及代码示例

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

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

Loader介绍

[英]Load resources (or images) from various sources.
[中]从各种来源加载资源(或图像)。

代码示例

代码示例来源:origin: ch.qos.logback/logback-classic

private URL urlByResourceName(StatusManager sm, String resourceName) {
  sm.add(new InfoStatus("Searching for [" + resourceName + "]", this));
  URL url = Loader.getResource(resourceName, Loader.getTCL());
  if (url != null) {
    return url;
  }
  return Loader.getResourceBySelfClassLoader(resourceName);
}

代码示例来源:origin: ch.qos.logback/logback-classic

/**
 * Instantiate the context selector class designated by the user. The selector
 * must have a constructor taking a LoggerContext instance as an argument.
 * 
 * @param defaultLoggerContext
 * @param contextSelectorStr
 * @return an instance of the designated context selector class
 * @throws ClassNotFoundException
 * @throws SecurityException
 * @throws NoSuchMethodException
 * @throws IllegalArgumentException
 * @throws InstantiationException
 * @throws IllegalAccessException
 * @throws InvocationTargetException
 */
static ContextSelector dynamicalContextSelector(LoggerContext defaultLoggerContext, String contextSelectorStr) throws ClassNotFoundException,
        SecurityException, NoSuchMethodException, IllegalArgumentException, InstantiationException, IllegalAccessException,
        InvocationTargetException {
  Class<?> contextSelectorClass = Loader.loadClass(contextSelectorStr);
  Constructor cons = contextSelectorClass.getConstructor(new Class[] { LoggerContext.class });
  return (ContextSelector) cons.newInstance(defaultLoggerContext);
}

代码示例来源:origin: ch.qos.logback/logback-classic

public URL findURLOfDefaultConfigurationFile(boolean updateStatus) {
  ClassLoader myClassLoader = Loader.getClassLoaderOfObject(this);
  URL url = findConfigFileURLFromSystemProperties(myClassLoader, updateStatus);
  if (url != null) {
    return url;
  }
  url = getResource(TEST_AUTOCONFIG_FILE, myClassLoader, updateStatus);
  if (url != null) {
    return url;
  }
  url = getResource(GROOVY_AUTOCONFIG_FILE, myClassLoader, updateStatus);
  if (url != null) {
    return url;
  }
  return getResource(AUTOCONFIG_FILE, myClassLoader, updateStatus);
}

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

/**
 * Attempt to find a resource by using the classloader that loaded this class,
 * namely Loader.class.
 *
 * @param resource
 * @return
 */
public static URL getResourceBySelfClassLoader(String resource) {
 return getResource(resource, getClassLoaderOfClass(Loader.class));
}

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

URL resourceAsURL(String resourceAttribute) {
 URL url = Loader.getResourceBySelfClassLoader(resourceAttribute);
 if (url == null) {
  if (!optional) {
   String errMsg = "Could not find resource corresponding to ["
       + resourceAttribute + "]";
   addError(errMsg);
  }
  return null;
 } else
  return url;
}

代码示例来源:origin: ch.qos.logback/logback-classic

private URL getResource(String filename, ClassLoader myClassLoader, boolean updateStatus) {
  URL url = Loader.getResource(filename, myClassLoader);
  if (updateStatus) {
    statusOnResourceSearch(filename, myClassLoader, url);
  }
  return url;
}

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

/**
  * If running under JDK 1.2 load the specified class using the
  * <code>Thread</code> <code>contextClassLoader</code> if that fails try
  * Class.forname. Under JDK 1.1 only Class.forName is used.
  */
 public static Class<?> loadClass(String clazz) throws ClassNotFoundException {
  // Just call Class.forName(clazz) if we are running under JDK 1.1
  // or if we are instructed to ignore the TCL.
  if (ignoreTCL) {
   return Class.forName(clazz);
  } else {
   try {
    return getTCL().loadClass(clazz);
   } catch (Throwable e) {
    // we reached here because tcl was null or because of a
    // security exception, or because clazz could not be loaded...
    // In any case we now try one more time
    return Class.forName(clazz);
   }
  }
 }
}

代码示例来源:origin: ch.qos.logback/logback-classic

private static ClassLoader getServiceLoaderClassLoader() {
  return testServiceLoaderClassLoader == null ? Loader.getClassLoaderOfClass(EnvUtil.class) : testServiceLoaderClassLoader;
}

代码示例来源:origin: ch.qos.logback/logback-classic

private void multiplicityWarning(String resourceName, ClassLoader classLoader) {
    Set<URL> urlSet = null;
    StatusManager sm = loggerContext.getStatusManager();
    try {
      urlSet = Loader.getResources(resourceName, classLoader);
    } catch (IOException e) {
      sm.add(new ErrorStatus("Failed to get url list for resource [" + resourceName + "]", loggerContext, e));
    }
    if (urlSet != null && urlSet.size() > 1) {
      sm.add(new WarnStatus("Resource [" + resourceName + "] occurs multiple times on the classpath.", loggerContext));
      for (URL url : urlSet) {
        sm.add(new WarnStatus("Resource [" + resourceName + "] occurs at [" + url.toString() + "]", loggerContext));
      }
    }
  }
}

代码示例来源:origin: tony19/logback-android

/**
 * Attempt to find a resource by using the classloader that loaded this class,
 * namely Loader.class.
 *
 * @param resource the resource name to look for
 * @return resource URL
 */
public static URL getResourceBySelfClassLoader(String resource) {
 return getResource(resource, getClassLoaderOfClass(Loader.class));
}

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

url = Loader.getResourceBySelfClassLoader(location);
 throw new MalformedURLException("path is required");
url = Loader.getResourceBySelfClassLoader(path);

代码示例来源:origin: ch.qos.logback/logback-classic

private URL findConfigFileURLFromSystemProperties(ClassLoader classLoader, boolean updateStatus) {
  String logbackConfigFile = OptionHelper.getSystemProperty(CONFIG_FILE_PROPERTY);
  if (logbackConfigFile != null) {
    URL result = null;
    try {
      result = new URL(logbackConfigFile);
      return result;
    } catch (MalformedURLException e) {
      // so, resource is not a URL:
      // attempt to get the resource from the class path
      result = Loader.getResource(logbackConfigFile, classLoader);
      if (result != null) {
        return result;
      }
      File f = new File(logbackConfigFile);
      if (f.exists() && f.isFile()) {
        try {
          result = f.toURI().toURL();
          return result;
        } catch (MalformedURLException e1) {
        }
      }
    } finally {
      if (updateStatus) {
        statusOnResourceSearch(logbackConfigFile, classLoader, result);
      }
    }
  }
  return null;
}

代码示例来源:origin: ch.qos.logback/core

/**
  * If running under JDK 1.2 load the specified class using the
  * <code>Thread</code> <code>contextClassLoader</code> if that fails try
  * Class.forname. Under JDK 1.1 only Class.forName is used.
  */
 public static Class loadClass(String clazz) throws ClassNotFoundException {
  // Just call Class.forName(clazz) if we are running under JDK 1.1
  // or if we are instructed to ignore the TCL.
  if (ignoreTCL) {
   return Class.forName(clazz);
  } else {
   try {
    return getTCL().loadClass(clazz);
   } catch (Throwable e) {
    // we reached here because tcl was null or because of a
    // security exception, or because clazz could not be loaded...
    // In any case we now try one more time
    return Class.forName(clazz);
   }
  }
 }
}

代码示例来源:origin: ch.qos.logback/logback-classic

static public boolean isGroovyAvailable() {
  ClassLoader classLoader = Loader.getClassLoaderOfClass(EnvUtil.class);
  try {
    Class<?> bindingClass = classLoader.loadClass("groovy.lang.Binding");
    return (bindingClass != null);
  } catch (ClassNotFoundException e) {
    return false;
  }
}

代码示例来源:origin: com.impetus.fabric/fabric-jdbc-driver-shaded

private void multiplicityWarning(String resourceName, ClassLoader classLoader) {
    Set<URL> urlSet = null;
    StatusManager sm = loggerContext.getStatusManager();
    try {
      urlSet = Loader.getResources(resourceName, classLoader);
    } catch (IOException e) {
      sm.add(new ErrorStatus("Failed to get url list for resource [" + resourceName + "]", loggerContext, e));
    }
    if (urlSet != null && urlSet.size() > 1) {
      sm.add(new WarnStatus("Resource [" + resourceName + "] occurs multiple times on the classpath.", loggerContext));
      for (URL url : urlSet) {
        sm.add(new WarnStatus("Resource [" + resourceName + "] occurs at [" + url.toString() + "]", loggerContext));
      }
    }
  }
}

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

private URL urlByResourceName(StatusManager sm, String resourceName) {
 sm.add(new InfoStatus("Searching for [" + resourceName + "]",
     this));
 URL url = Loader.getResource(resourceName, Loader.getTCL());
 if (url != null) {
  return url;
 }
 return Loader.getResourceBySelfClassLoader(resourceName);
}

代码示例来源:origin: ch.qos.logback/core

/**
 * Attempt to find a resource by using the classloader that loaded this class,
 * namely Loader.class.
 *
 * @param resource
 * @return
 */
public static URL getResourceBySelfClassLoader(String resource) {
 return getResource(resource, getClassLoaderOfClass(Loader.class));
}

代码示例来源:origin: googleapis/google-cloud-java

private <T> T getEnhancer(String enhancerClassName) {
 try {
  Class<T> clz = (Class<T>) Loader.loadClass(enhancerClassName.trim());
  return clz.newInstance();
 } catch (Exception ex) {
  // If we cannot create the enhancer we fallback to null
 }
 return null;
}

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

public static Class<?> loadClass(String clazz, Context context)
    throws ClassNotFoundException {
 ClassLoader cl = getClassLoaderOfObject(context);
 return cl.loadClass(clazz);
}

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

/**
 * Returns the string "true" if the {@link #setResource(String) resource} specified by the
 * user is available on the class path, "false" otherwise.
 *
 * @return "true"|"false" depending on the availability of resource on the classpath
 */
public String getPropertyValue() {
 if (OptionHelper.isEmpty(resourceStr)) {
  addError("The \"resource\" property must be set.");
  return null;
 }
 URL resourceURL = Loader.getResourceBySelfClassLoader(resourceStr);
 return booleanAsStr(resourceURL != null);
}

相关文章