AbstractComponentApiServlet extends AbstractApiServlet { @SuppressWarnings("unchecked") protected <S extends T, T> Class<S> getClassFromString(String className, String... defaultPackage) throws InvalidParameterException { for (String pkg : defaultPackage) { try { return (Class<S>) Class.forName(pkg + "." + className); } catch (Exception e) { LoggerFactory.getLogger(clazz) .debug("Couldn't find class {} in package {}", className, pkg, e); } } try { return (Class<S>) Class.forName(className); } catch (Exception e) { throw new InvalidParameterException( "Could not find or instantiate analysis engine " + className, e); } } AbstractComponentApiServlet(
      String componentClass,
      String componentPackage,
      List<String> excludeClass,
      List<String> excludePackage,
      Class<?> clazz); static boolean excludeByPackage(String pkg, List<String> excludePkg); static boolean excludeByClass(Class<?> clazz, List<Class<?>> excludeClazz);  }
@Test public void testClassFromString() throws Exception { AbstractComponentApiServlet servlet = new AbstractComponentApiServlet( "java.util.List", "java.util", Collections.emptyList(), Collections.emptyList(), this.getClass()); Class<?> al = servlet.getClassFromString("ArrayList", "java.util"); assertEquals(ArrayList.class.getName(), al.getName()); Class<?> al2 = servlet.getClassFromString("java.util.ArrayList", "foo.bar"); assertEquals(ArrayList.class.getName(), al2.getName()); try { servlet.getClassFromString("ArrayList", "java.util.foo"); fail("Expected exception not thrown"); } catch (InvalidParameterException ipe) { } }