@Test public void newServiceInstance_ClassNameServiceId() throws Exception { assertNull(ClassLoaderUtil.newServiceInstance(null, (String) null)); try { ClassLoaderUtil.newServiceInstance("myservice.notexist", "myservice.notexist"); fail("expected ServiceNotFoundException"); } catch (ServiceNotFoundException e) { } try { ClassLoaderUtil.newServiceInstance("myservice.notfound", "myservice.notfound"); fail("expected ClassNotFoundException"); } catch (ClassNotFoundException e) { assertFalse(e instanceof ServiceNotFoundException); } try { ClassLoaderUtil.newServiceInstance("myservice.err", "myservice.err"); fail("Expected ClassInstantiationException"); } catch (ClassInstantiationException e) { } assertInstance(MyService.class, ClassLoaderUtil.newServiceInstance("myservice", "myservice")); assertNull(ClassLoaderUtil.newServiceInstance(null, null, getClass())); assertNull(ClassLoaderUtil.newServiceInstance(null, null, (Class<?>) null)); try { ClassLoaderUtil.newServiceInstance("myservice.notexist", "myservice.notexist", getClass()); fail("expected ServiceNotFoundException"); } catch (ServiceNotFoundException e) { } try { ClassLoaderUtil.newServiceInstance("myservice.notfound", "myservice.notfound", getClass()); fail("expected ClassNotFoundException"); } catch (ClassNotFoundException e) { assertFalse(e instanceof ServiceNotFoundException); } try { ClassLoaderUtil.newServiceInstance("myservice.notexist", "myservice.notexist", (Class<?>) null); fail("expected ServiceNotFoundException"); } catch (ServiceNotFoundException e) { } try { ClassLoaderUtil.newServiceInstance("myservice.notfound", "myservice.notfound", (Class<?>) null); fail("expected ClassNotFoundException"); } catch (ClassNotFoundException e) { assertFalse(e instanceof ServiceNotFoundException); } try { ClassLoaderUtil.newServiceInstance("myservice.err", "myservice.err", getClass()); fail("Expected ClassInstantiationException"); } catch (ClassInstantiationException e) { } assertInstance(MyService.class, ClassLoaderUtil.newServiceInstance("myservice", "myservice", getClass())); assertInstance(MyService.class, ClassLoaderUtil.newServiceInstance("myservice", "myservice", (Class<?>) null)); assertNull(ClassLoaderUtil.newServiceInstance(null, null, getClass().getClassLoader())); assertNull(ClassLoaderUtil.newServiceInstance(null, null, (ClassLoader) null)); try { ClassLoaderUtil.newServiceInstance("myservice.notexist", "myservice.notexist", getClass().getClassLoader()); fail("expected ServiceNotFoundException"); } catch (ServiceNotFoundException e) { } try { ClassLoaderUtil.newServiceInstance("myservice.notfound", "myservice.notfound", getClass().getClassLoader()); fail("expected ClassNotFoundException"); } catch (ClassNotFoundException e) { assertFalse(e instanceof ServiceNotFoundException); } try { ClassLoaderUtil.newServiceInstance("myservice.notexist", "myservice.notexist", (ClassLoader) null); fail("expected ServiceNotFoundException"); } catch (ServiceNotFoundException e) { } try { ClassLoaderUtil.newServiceInstance("myservice.notfound", "myservice.notfound", (ClassLoader) null); fail("expected ClassNotFoundException"); } catch (ClassNotFoundException e) { assertFalse(e instanceof ServiceNotFoundException); } try { ClassLoaderUtil.newServiceInstance("myservice.err", "myservice.err", getClass().getClassLoader()); fail("Expected ClassInstantiationException"); } catch (ClassInstantiationException e) { } assertInstance(MyService.class, ClassLoaderUtil.newServiceInstance("myservice", "myservice", getClass().getClassLoader())); assertInstance(MyService.class, ClassLoaderUtil.newServiceInstance("myservice", "myservice", (ClassLoader) null)); assertInstance(MyService.class, ClassLoaderUtil.newServiceInstance("com.baidu.unbiz.common.sample.MyService", "com.baidu.unbiz.common.sample.MyService", getClass().getClassLoader())); assertInstance(MyService.class, ClassLoaderUtil.newServiceInstance("com.baidu.unbiz.common.sample.MyService", "com.baidu.unbiz.common.sample.MyService", (ClassLoader) null)); assertInstance(MyService.class, ClassLoaderUtil.newServiceInstance("com.baidu.unbiz.common.sample.MyService", "abc")); assertInstance(MyService.class, ClassLoaderUtil.newServiceInstance("abc", "myservice")); }
public static <T> T newServiceInstance(String serviceId) throws ClassNotFoundException, ClassInstantiationException { Class<T> clazz = loadServiceClass(serviceId); return newInstance(clazz); }
ClassLoaderUtil { public static <T> T newServiceInstance(String serviceId) throws ClassNotFoundException, ClassInstantiationException { Class<T> clazz = loadServiceClass(serviceId); return newInstance(clazz); } }
ClassLoaderUtil { public static <T> T newServiceInstance(String serviceId) throws ClassNotFoundException, ClassInstantiationException { Class<T> clazz = loadServiceClass(serviceId); return newInstance(clazz); }  }
ClassLoaderUtil { public static <T> T newServiceInstance(String serviceId) throws ClassNotFoundException, ClassInstantiationException { Class<T> clazz = loadServiceClass(serviceId); return newInstance(clazz); }  static ClassLoader getContextClassLoader(); static String getClasspath(); static Class<T> loadClass(String className); static Class<T> loadClass(String className, Class<?> referrer); static Class<T> loadClass(String className, ClassLoader classLoader); static Class<T> loadServiceClass(String serviceId); static Class<T> loadServiceClass(String serviceId, Class<?> referrer); static Class<T> loadServiceClass(String serviceId, ClassLoader classLoader); static Class<T> loadServiceClass(String className, String serviceId); static Class<T> loadServiceClass(String className, String serviceId, Class<T> referrer); static Class<T> loadServiceClass(String className, String serviceId, ClassLoader classLoader); static T newInstance(String className); static Object newInstance(String className, Class<?> referrer); static Object newInstance(String className, ClassLoader classLoader); static T newInstance(Class<T> clazz); static T newServiceInstance(String serviceId); static T newServiceInstance(String serviceId, Class<T> referrer); static T newServiceInstance(String serviceId, ClassLoader classLoader); static T newServiceInstance(String className, String serviceId); static T newServiceInstance(String className, String serviceId, Class<T> referrer); static T newServiceInstance(String className, String serviceId, ClassLoader classLoader); static URL[] getResources(String resourceName); static URL[] getResources(String resourceName, Class<?> referrer); static URL[] getResources(String resourceName, ClassLoader classLoader); static URL getResource(String resourceName); static URL getResource(String resourceName, Class<?> referrer); static URL getResource(String resourceName, ClassLoader classLoader); static InputStream getResourceAsStream(String resourceName); static InputStream getResourceAsStream(String resourceName, Class<?> referrer); static InputStream getResourceAsStream(String resourceName, ClassLoader classLoader); static URL[] whichClasses(String className); static URL[] whichClasses(String className, Class<T> referrer); static URL[] whichClasses(String className, ClassLoader classLoader); static URL whichClass(String className); static URL whichClass(String className, Class<T> referrer); static URL whichClass(String className, ClassLoader classLoader); }
ClassLoaderUtil { public static <T> T newServiceInstance(String serviceId) throws ClassNotFoundException, ClassInstantiationException { Class<T> clazz = loadServiceClass(serviceId); return newInstance(clazz); }  static ClassLoader getContextClassLoader(); static String getClasspath(); static Class<T> loadClass(String className); static Class<T> loadClass(String className, Class<?> referrer); static Class<T> loadClass(String className, ClassLoader classLoader); static Class<T> loadServiceClass(String serviceId); static Class<T> loadServiceClass(String serviceId, Class<?> referrer); static Class<T> loadServiceClass(String serviceId, ClassLoader classLoader); static Class<T> loadServiceClass(String className, String serviceId); static Class<T> loadServiceClass(String className, String serviceId, Class<T> referrer); static Class<T> loadServiceClass(String className, String serviceId, ClassLoader classLoader); static T newInstance(String className); static Object newInstance(String className, Class<?> referrer); static Object newInstance(String className, ClassLoader classLoader); static T newInstance(Class<T> clazz); static T newServiceInstance(String serviceId); static T newServiceInstance(String serviceId, Class<T> referrer); static T newServiceInstance(String serviceId, ClassLoader classLoader); static T newServiceInstance(String className, String serviceId); static T newServiceInstance(String className, String serviceId, Class<T> referrer); static T newServiceInstance(String className, String serviceId, ClassLoader classLoader); static URL[] getResources(String resourceName); static URL[] getResources(String resourceName, Class<?> referrer); static URL[] getResources(String resourceName, ClassLoader classLoader); static URL getResource(String resourceName); static URL getResource(String resourceName, Class<?> referrer); static URL getResource(String resourceName, ClassLoader classLoader); static InputStream getResourceAsStream(String resourceName); static InputStream getResourceAsStream(String resourceName, Class<?> referrer); static InputStream getResourceAsStream(String resourceName, ClassLoader classLoader); static URL[] whichClasses(String className); static URL[] whichClasses(String className, Class<T> referrer); static URL[] whichClasses(String className, ClassLoader classLoader); static URL whichClass(String className); static URL whichClass(String className, Class<T> referrer); static URL whichClass(String className, ClassLoader classLoader);  }