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

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

本文整理了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

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

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

  1. /**
  2. * Instantiate the context selector class designated by the user. The selector
  3. * must have a constructor taking a LoggerContext instance as an argument.
  4. *
  5. * @param defaultLoggerContext
  6. * @param contextSelectorStr
  7. * @return an instance of the designated context selector class
  8. * @throws ClassNotFoundException
  9. * @throws SecurityException
  10. * @throws NoSuchMethodException
  11. * @throws IllegalArgumentException
  12. * @throws InstantiationException
  13. * @throws IllegalAccessException
  14. * @throws InvocationTargetException
  15. */
  16. static ContextSelector dynamicalContextSelector(LoggerContext defaultLoggerContext, String contextSelectorStr) throws ClassNotFoundException,
  17. SecurityException, NoSuchMethodException, IllegalArgumentException, InstantiationException, IllegalAccessException,
  18. InvocationTargetException {
  19. Class<?> contextSelectorClass = Loader.loadClass(contextSelectorStr);
  20. Constructor cons = contextSelectorClass.getConstructor(new Class[] { LoggerContext.class });
  21. return (ContextSelector) cons.newInstance(defaultLoggerContext);
  22. }

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

  1. public URL findURLOfDefaultConfigurationFile(boolean updateStatus) {
  2. ClassLoader myClassLoader = Loader.getClassLoaderOfObject(this);
  3. URL url = findConfigFileURLFromSystemProperties(myClassLoader, updateStatus);
  4. if (url != null) {
  5. return url;
  6. }
  7. url = getResource(TEST_AUTOCONFIG_FILE, myClassLoader, updateStatus);
  8. if (url != null) {
  9. return url;
  10. }
  11. url = getResource(GROOVY_AUTOCONFIG_FILE, myClassLoader, updateStatus);
  12. if (url != null) {
  13. return url;
  14. }
  15. return getResource(AUTOCONFIG_FILE, myClassLoader, updateStatus);
  16. }

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

  1. /**
  2. * Attempt to find a resource by using the classloader that loaded this class,
  3. * namely Loader.class.
  4. *
  5. * @param resource
  6. * @return
  7. */
  8. public static URL getResourceBySelfClassLoader(String resource) {
  9. return getResource(resource, getClassLoaderOfClass(Loader.class));
  10. }

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

  1. URL resourceAsURL(String resourceAttribute) {
  2. URL url = Loader.getResourceBySelfClassLoader(resourceAttribute);
  3. if (url == null) {
  4. if (!optional) {
  5. String errMsg = "Could not find resource corresponding to ["
  6. + resourceAttribute + "]";
  7. addError(errMsg);
  8. }
  9. return null;
  10. } else
  11. return url;
  12. }

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

  1. private URL getResource(String filename, ClassLoader myClassLoader, boolean updateStatus) {
  2. URL url = Loader.getResource(filename, myClassLoader);
  3. if (updateStatus) {
  4. statusOnResourceSearch(filename, myClassLoader, url);
  5. }
  6. return url;
  7. }

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

  1. /**
  2. * If running under JDK 1.2 load the specified class using the
  3. * <code>Thread</code> <code>contextClassLoader</code> if that fails try
  4. * Class.forname. Under JDK 1.1 only Class.forName is used.
  5. */
  6. public static Class<?> loadClass(String clazz) throws ClassNotFoundException {
  7. // Just call Class.forName(clazz) if we are running under JDK 1.1
  8. // or if we are instructed to ignore the TCL.
  9. if (ignoreTCL) {
  10. return Class.forName(clazz);
  11. } else {
  12. try {
  13. return getTCL().loadClass(clazz);
  14. } catch (Throwable e) {
  15. // we reached here because tcl was null or because of a
  16. // security exception, or because clazz could not be loaded...
  17. // In any case we now try one more time
  18. return Class.forName(clazz);
  19. }
  20. }
  21. }
  22. }

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

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

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

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

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

  1. /**
  2. * Attempt to find a resource by using the classloader that loaded this class,
  3. * namely Loader.class.
  4. *
  5. * @param resource the resource name to look for
  6. * @return resource URL
  7. */
  8. public static URL getResourceBySelfClassLoader(String resource) {
  9. return getResource(resource, getClassLoaderOfClass(Loader.class));
  10. }

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

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

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

  1. private URL findConfigFileURLFromSystemProperties(ClassLoader classLoader, boolean updateStatus) {
  2. String logbackConfigFile = OptionHelper.getSystemProperty(CONFIG_FILE_PROPERTY);
  3. if (logbackConfigFile != null) {
  4. URL result = null;
  5. try {
  6. result = new URL(logbackConfigFile);
  7. return result;
  8. } catch (MalformedURLException e) {
  9. // so, resource is not a URL:
  10. // attempt to get the resource from the class path
  11. result = Loader.getResource(logbackConfigFile, classLoader);
  12. if (result != null) {
  13. return result;
  14. }
  15. File f = new File(logbackConfigFile);
  16. if (f.exists() && f.isFile()) {
  17. try {
  18. result = f.toURI().toURL();
  19. return result;
  20. } catch (MalformedURLException e1) {
  21. }
  22. }
  23. } finally {
  24. if (updateStatus) {
  25. statusOnResourceSearch(logbackConfigFile, classLoader, result);
  26. }
  27. }
  28. }
  29. return null;
  30. }

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

  1. /**
  2. * If running under JDK 1.2 load the specified class using the
  3. * <code>Thread</code> <code>contextClassLoader</code> if that fails try
  4. * Class.forname. Under JDK 1.1 only Class.forName is used.
  5. */
  6. public static Class loadClass(String clazz) throws ClassNotFoundException {
  7. // Just call Class.forName(clazz) if we are running under JDK 1.1
  8. // or if we are instructed to ignore the TCL.
  9. if (ignoreTCL) {
  10. return Class.forName(clazz);
  11. } else {
  12. try {
  13. return getTCL().loadClass(clazz);
  14. } catch (Throwable e) {
  15. // we reached here because tcl was null or because of a
  16. // security exception, or because clazz could not be loaded...
  17. // In any case we now try one more time
  18. return Class.forName(clazz);
  19. }
  20. }
  21. }
  22. }

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

  1. static public boolean isGroovyAvailable() {
  2. ClassLoader classLoader = Loader.getClassLoaderOfClass(EnvUtil.class);
  3. try {
  4. Class<?> bindingClass = classLoader.loadClass("groovy.lang.Binding");
  5. return (bindingClass != null);
  6. } catch (ClassNotFoundException e) {
  7. return false;
  8. }
  9. }

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

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

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

  1. private URL urlByResourceName(StatusManager sm, String resourceName) {
  2. sm.add(new InfoStatus("Searching for [" + resourceName + "]",
  3. this));
  4. URL url = Loader.getResource(resourceName, Loader.getTCL());
  5. if (url != null) {
  6. return url;
  7. }
  8. return Loader.getResourceBySelfClassLoader(resourceName);
  9. }

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

  1. /**
  2. * Attempt to find a resource by using the classloader that loaded this class,
  3. * namely Loader.class.
  4. *
  5. * @param resource
  6. * @return
  7. */
  8. public static URL getResourceBySelfClassLoader(String resource) {
  9. return getResource(resource, getClassLoaderOfClass(Loader.class));
  10. }

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

  1. private <T> T getEnhancer(String enhancerClassName) {
  2. try {
  3. Class<T> clz = (Class<T>) Loader.loadClass(enhancerClassName.trim());
  4. return clz.newInstance();
  5. } catch (Exception ex) {
  6. // If we cannot create the enhancer we fallback to null
  7. }
  8. return null;
  9. }

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

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

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

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

相关文章