/** * Helper method equivalent to <code>ClassPathLoader.getLatest().asClassLoader();</code>. * * @return {@link ClassLoader} for current {@link ClassPathLoader}. * @since GemFire 8.1 */ public static ClassLoader getLatestAsClassLoader() { return getLatest().asClassLoader(); }
private void loadDriverUsingClassName() throws ClassNotFoundException, InstantiationException, IllegalAccessException { Class<?> driverClass = ClassPathLoader.getLatest().forName(jdbcDriver); driverObject = (Driver) driverClass.newInstance(); } }
@Override public boolean isAvailable() { try { ClassPathLoader.getLatest().forName(DEFAULT_PROVIDER_CLASS_NAME); LOGGER.info("Log4j Core is available"); return true; } catch (ClassNotFoundException | ClassCastException e) { LOGGER.info("Unable to find Log4j Core"); } return false; } }
private static boolean canLoadClass(String className) { try { ClassPathLoader.getLatest().forName(className); } catch (ClassNotFoundException e) { return false; } return true; }
public static boolean isEnabledManagedEntityController() { try { ClassPathLoader.getLatest().forName(ENABLED_MANAGED_ENTITY_CONTROLLER_CLASS_NAME); return true; } catch (ClassNotFoundException e) { return false; } }
ResultCollector parseResultCollector(String resultCollectorName) throws ClassNotFoundException, IllegalAccessException, InstantiationException { if (resultCollectorName != null && resultCollectorName.length() > 0) { return (ResultCollector) ClassPathLoader.getLatest().forName(resultCollectorName) .newInstance(); } else { return null; } }
@Override public Collection<String> getSerializationAcceptlist() throws IOException { URL sanctionedSerializables = ClassPathLoader.getLatest().getResource(getClass(), "sanctioned-geode-cq-serializables.txt"); return InternalDataSerializer.loadClassNames(sanctionedSerializables); } }
@Override public Collection<String> getSerializationAcceptlist() throws IOException { URL sanctionedSerializables = ClassPathLoader.getLatest().getResource(getClass(), "sanctioned-geode-wan-serializables.txt"); return InternalDataSerializer.loadClassNames(sanctionedSerializables); } }
private Object newInstance(String className) throws ClassNotFoundException, IllegalAccessException, InstantiationException { if (Strings.isNullOrEmpty(className)) { return null; } return ClassPathLoader.getLatest().forName(className).newInstance(); }
private Object newInstance(String className) throws ClassNotFoundException, IllegalAccessException, InstantiationException { if (Strings.isNullOrEmpty(className)) { return null; } return ClassPathLoader.getLatest().forName(className).newInstance(); }
@Override public Collection<String> getSerializationAcceptlist() throws IOException { URL sanctionedSerializables = ClassPathLoader.getLatest().getResource(getClass(), "sanctioned-geode-connectors-serializables.txt"); return InternalDataSerializer.loadClassNames(sanctionedSerializables); } }
@Override public Collection<String> getSerializationAcceptlist() throws IOException { URL sanctionedSerializables = ClassPathLoader.getLatest().getResource(getClass(), "sanctioned-geode-lucene-serializables.txt"); return InternalDataSerializer.loadClassNames(sanctionedSerializables); } }
public void validateWithLocalCacheXSD() { // find the local Cache-1.0.xsd URL local_cache_xsd = ClassPathLoader.getLatest() .getResource("META-INF/schemas/geode.apache.org/schema/cache/cache-1.0.xsd"); validateWith(local_cache_xsd); }
/** * Resolve the class from the given name. Supports primitive types, too. */ public static Class classFromName(String className) throws ClassNotFoundException { Class result = checkForPrimType(className); if (result == null) { result = ClassPathLoader.getLatest().forName(className); } return result; }
public static <V> V newInstance(ClassNameType className) { try { Class<V> loadedClass = (Class<V>) ClassPathLoader.getLatest().forName(className.getClassName()); return loadedClass.newInstance(); } catch (Exception e) { throw new RuntimeException("Error instantiating class: <" + className.getClassName() + ">", e); } } }
/** * Verifies that {@link ClassPathLoader#getLatest()} is always initialized and returns a * <tt>ClassPathLoader</tt> instance. */ @Test public void testLatestExists() throws Exception { System.out.println("\nStarting ClassPathLoaderTest#testLatestExists"); assertThat(ClassPathLoader.getLatest()).isNotNull(); }
/** * Verifies that {@link ClassPathLoader#getLatest()} throws <tt>ClassNotFoundException</tt> when * class does not exist. */ @Test public void testForNameThrowsClassNotFoundException() throws Exception { System.out.println("\nStarting ClassPathLoaderTest#testForNameThrowsClassNotFoundException"); String classToLoad = "com.nowhere.DoesNotExist"; assertThatThrownBy(() -> ClassPathLoader.getLatest().forName(classToLoad)) .isInstanceOf(ClassNotFoundException.class); }
public static <V> V newInstance(ClassName<?> type, Cache cache) { try { Class<V> loadedClass = (Class<V>) ClassPathLoader.getLatest().forName(type.getClassName()); V object = loadedClass.newInstance(); if (object instanceof Declarable) { Declarable declarable = (Declarable) object; declarable.initialize(cache, type.getInitProperties()); declarable.init(type.getInitProperties()); // for backwards compatibility } return object; } catch (Exception e) { throw new RuntimeException("Error instantiating class: <" + type.getClassName() + ">", e); } }
void applyJarAndXmlFromClusterConfig() { if (this.configurationResponse == null) { // Deploy all the jars from the deploy working dir. ClassPathLoader.getLatest().getJarDeployer().loadPreviouslyDeployedJarsFromDisk(); } ccLoader.applyClusterXmlConfiguration(this, this.configurationResponse, this.system.getConfig().getGroups()); }
/** * Verifies that {@link ClassPathLoader#getLatest()} finds and loads class via * <tt>Class.forName(String, boolean, ClassLoader)</tt> when class does exist. */ @Test public void testForName() throws Exception { System.out.println("\nStarting ClassPathLoaderTest#testForName"); String classToLoad = "org.apache.geode.internal.classpathloaderjunittest.DoesExist"; Class<?> clazz = ClassPathLoader.getLatest().forName(classToLoad); assertThat(clazz).isNotNull(); }