org.infinispan.commons.util.Util.loadClassStrict()方法的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(5.4k)|赞(0)|评价(0)|浏览(110)

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

Util.loadClassStrict介绍

[英]Loads the specified class using the passed classloader, or, if it is null the Infinispan classes' classloader.

If loadtime instrumentation via GenerateInstrumentedClassLoader is used, this class may be loaded by the bootstrap classloader.
[中]使用传递的类加载器加载指定的类,如果是null,则使用Infinispan类的类加载器加载。
如果使用通过GenerateInstrumentedClassLoader的loadtime指令,则引导类加载器可能会加载此类。

代码示例

代码示例来源:origin: org.infinispan/infinispan-commons

public TransactionManager tryLookup(ClassLoader classLoader) {
   Class<?> clazz;
   try {
    clazz = Util.loadClassStrict(factoryClazz, classLoader);
    Method method = clazz.getMethod(factoryMethod);
    return (TransactionManager) method.invoke(null);
   } catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ignored) {
    return null;
   }
 }
}

代码示例来源:origin: org.infinispan/infinispan-commons

public static Class<?> getClassForName(String name, ClassLoader cl) throws ClassNotFoundException {
 try {
   return Util.loadClassStrict(name, cl);
 } catch (ClassNotFoundException cnfe) {
   // Could be a primitive - let's check
   for (Class<?> primitive : primitives) if (name.equals(primitive.getName())) return primitive;
   for (Class<?> primitive : primitiveArrays) if (name.equals(primitive.getName())) return primitive;
 }
 throw new ClassNotFoundException("Class " + name + " cannot be found");
}

代码示例来源:origin: org.infinispan/infinispan-commons

/**
* Similar to {@link #getInstance(String, ClassLoader)} except that exceptions are propagated to the caller.
*
* @param classname class to instantiate
* @return an instance of classname
* @throws ClassNotFoundException
* @throws InstantiationException
* @throws IllegalAccessException
*/
public static <T> T getInstanceStrict(String classname, ClassLoader cl) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
 if (classname == null) throw new IllegalArgumentException("Cannot load null class!");
 Class<T> clazz = loadClassStrict(classname, cl);
 return getInstanceStrict(clazz);
}

代码示例来源:origin: org.infinispan/infinispan-commons

/**
* <p>
* Loads the specified class using the passed classloader, or, if it is <code>null</code> the Infinispan classes'
* classloader.
* </p>
*
* <p>
* If loadtime instrumentation via GenerateInstrumentedClassLoader is used, this class may be loaded by the bootstrap
* classloader.
* </p>
* <p>
* If the class is not found, the {@link ClassNotFoundException} or {@link NoClassDefFoundError} is wrapped as a
* {@link CacheConfigurationException} and is re-thrown.
* </p>
*
* @param classname name of the class to load
* @param cl the application classloader which should be used to load the class, or null if the class is always packaged with
*        Infinispan
* @return the class
* @throws CacheConfigurationException if the class cannot be loaded
*/
public static <T> Class<T> loadClass(String classname, ClassLoader cl) {
 try {
   return loadClassStrict(classname, cl);
 } catch (ClassNotFoundException e) {
   throw new CacheConfigurationException("Unable to instantiate class " + classname, e);
 }
}

代码示例来源:origin: org.infinispan/infinispan-query

private Transformer getTransformer(String keyClassName) {
 Class<?> keyClass;
 try {
   keyClass = Util.loadClassStrict(keyClassName, classLoader);
 } catch (ClassNotFoundException e) {
   log.keyClassNotFound(keyClassName, e);
   return null;
 }
 return getTransformer(keyClass);
}

代码示例来源:origin: org.infinispan/infinispan-embedded-query

private Transformer getCustomTransformer(final String keyClassName, final ClassLoader classLoader) {
 Transformer t = null;
 // try and locate class
 Class<?> keyClass = null;
 try {
   keyClass = Util.loadClassStrict(keyClassName, classLoader);
 } catch (ClassNotFoundException e) {
   log.keyClassNotFound(keyClassName, e);
 }
 if (keyClass != null) {
   t = getTransformer(keyClass);
 }
 return t;
}

代码示例来源:origin: org.infinispan/infinispan-commons

try {
  clazz = toClassName(path.toPath().relativize(cf.toPath()).toString());
  claz = Util.loadClassStrict(clazz, null);
  classes.add(claz);
} catch (NoClassDefFoundError ncdfe) {
     try {
      clazz = toClassName(entry.getName());
      claz = Util.loadClassStrict(clazz, null);
      classes.add(claz);
     } catch (NoClassDefFoundError ncdfe) {

代码示例来源:origin: org.infinispan/infinispan-cachestore-jdbc

@Override
public void start() {
 if (configuration.manageConnectionFactory()) {
   ConnectionFactory factory = ConnectionFactory.getConnectionFactory(configuration.connectionFactory().connectionFactoryClass());
   factory.start(configuration.connectionFactory(), factory.getClass().getClassLoader());
   initializeConnectionFactory(factory);
 }
 try {
   Object mapper = Util.loadClassStrict(configuration.key2StringMapper(),
                     globalConfiguration.classLoader()).newInstance();
   if (mapper instanceof Key2StringMapper) key2StringMapper = (Key2StringMapper) mapper;
 } catch (Exception e) {
   log.errorf("Trying to instantiate %s, however it failed due to %s", configuration.key2StringMapper(),
        e.getClass().getName());
   throw new IllegalStateException("This should not happen.", e);
 }
 if (trace) {
   log.tracef("Using key2StringMapper: %s", key2StringMapper.getClass().getName());
 }
 if (configuration.preload()) {
   enforceTwoWayMapper("preload");
 }
 if (isDistributedCache) {
   enforceTwoWayMapper("distribution/rehashing");
 }
}

代码示例来源:origin: org.infinispan/infinispan-tools

case CLASS:
  try {
   interceptorBuilder.interceptorClass(Util.loadClassStrict(value, holder.getClassLoader()).asSubclass(CommandInterceptor.class));
  } catch (ClassNotFoundException e) {
   throw new CacheConfigurationException(e);

相关文章