@Test public void testResolveClass() throws Exception { ClassAliasResolver<IDummyAliasTest> resolver = new ClassAliasResolver<>(IDummyAliasTest.class); Assert.assertEquals(resolver.resolveClass("abc"), DummyAliasTest.class); Assert.assertEquals(resolver.resolveClass(DummyAliasTest.class.getName()), DummyAliasTest.class); try { resolver.resolveClass("def"); Assert.fail(); } catch (ClassNotFoundException cnfe) { } try { resolver.resolveClass(AnotherAliasClass.class.getName()); Assert.fail(); } catch (ClassNotFoundException cnfe) { } }
public Class<? extends T> resolveClass(final String aliasOrClassName) throws ClassNotFoundException { if (this.aliasToClassCache.containsKey(aliasOrClassName.toUpperCase())) { return this.aliasToClassCache.get(aliasOrClassName.toUpperCase()); } try { return Class.forName(aliasOrClassName).asSubclass(this.subtypeOf); } catch (ClassCastException cce) { throw new ClassNotFoundException( String.format("Found class %s but it cannot be cast to %s.", aliasOrClassName, this.subtypeOf.getName()), cce); } }
ClassAliasResolver { public Class<? extends T> resolveClass(final String aliasOrClassName) throws ClassNotFoundException { if (this.aliasToClassCache.containsKey(aliasOrClassName.toUpperCase())) { return this.aliasToClassCache.get(aliasOrClassName.toUpperCase()); } try { return Class.forName(aliasOrClassName).asSubclass(this.subtypeOf); } catch (ClassCastException cce) { throw new ClassNotFoundException( String.format("Found class %s but it cannot be cast to %s.", aliasOrClassName, this.subtypeOf.getName()), cce); } } }
ClassAliasResolver { public Class<? extends T> resolveClass(final String aliasOrClassName) throws ClassNotFoundException { if (this.aliasToClassCache.containsKey(aliasOrClassName.toUpperCase())) { return this.aliasToClassCache.get(aliasOrClassName.toUpperCase()); } try { return Class.forName(aliasOrClassName).asSubclass(this.subtypeOf); } catch (ClassCastException cce) { throw new ClassNotFoundException( String.format("Found class %s but it cannot be cast to %s.", aliasOrClassName, this.subtypeOf.getName()), cce); } } ClassAliasResolver(Class<T> subTypeOf); }
ClassAliasResolver { public Class<? extends T> resolveClass(final String aliasOrClassName) throws ClassNotFoundException { if (this.aliasToClassCache.containsKey(aliasOrClassName.toUpperCase())) { return this.aliasToClassCache.get(aliasOrClassName.toUpperCase()); } try { return Class.forName(aliasOrClassName).asSubclass(this.subtypeOf); } catch (ClassCastException cce) { throw new ClassNotFoundException( String.format("Found class %s but it cannot be cast to %s.", aliasOrClassName, this.subtypeOf.getName()), cce); } } ClassAliasResolver(Class<T> subTypeOf); String resolve(final String possibleAlias); Class<? extends T> resolveClass(final String aliasOrClassName); Map<String, Class<? extends T>> getAliasMap(); List<Alias> getAliasObjects(); }
ClassAliasResolver { public Class<? extends T> resolveClass(final String aliasOrClassName) throws ClassNotFoundException { if (this.aliasToClassCache.containsKey(aliasOrClassName.toUpperCase())) { return this.aliasToClassCache.get(aliasOrClassName.toUpperCase()); } try { return Class.forName(aliasOrClassName).asSubclass(this.subtypeOf); } catch (ClassCastException cce) { throw new ClassNotFoundException( String.format("Found class %s but it cannot be cast to %s.", aliasOrClassName, this.subtypeOf.getName()), cce); } } ClassAliasResolver(Class<T> subTypeOf); String resolve(final String possibleAlias); Class<? extends T> resolveClass(final String aliasOrClassName); Map<String, Class<? extends T>> getAliasMap(); List<Alias> getAliasObjects();  }