@Test public void findClass() throws Exception { Class[] classes = serviceLocator.findClasses(Database.class); for (Class clazz : classes) { assertFalse(clazz.getName()+" is abstract", Modifier.isAbstract(clazz.getModifiers())); assertFalse(clazz.getName()+" is an interface", Modifier.isInterface(clazz.getModifiers())); assertNotNull(clazz.getConstructors()); } assertTrue(classes.length > 0); }
public Class findClass(Class requiredInterface) throws ServiceNotFoundException { if (requiredInterface == Logger.class ) { return DefaultLogger.class; } else if ( requiredInterface == Executor.class ) { return JdbcExecutor.class; } else { throw new ServiceNotFoundException("Could not find implementation of " + requiredInterface.getName()); } }
ServiceLocator { public Class findClass(Class requiredInterface) throws ServiceNotFoundException { if (requiredInterface == Logger.class ) { return DefaultLogger.class; } else if ( requiredInterface == Executor.class ) { return JdbcExecutor.class; } else { throw new ServiceNotFoundException("Could not find implementation of " + requiredInterface.getName()); } } }
ServiceLocator { public Class findClass(Class requiredInterface) throws ServiceNotFoundException { if (requiredInterface == Logger.class ) { return DefaultLogger.class; } else if ( requiredInterface == Executor.class ) { return JdbcExecutor.class; } else { throw new ServiceNotFoundException("Could not find implementation of " + requiredInterface.getName()); } } protected  ServiceLocator(); protected  ServiceLocator(ResourceAccessor accessor); protected  ServiceLocator(PackageScanClassResolver classResolver); protected  ServiceLocator(PackageScanClassResolver classResolver, ResourceAccessor accessor); }
ServiceLocator { public Class findClass(Class requiredInterface) throws ServiceNotFoundException { if (requiredInterface == Logger.class ) { return DefaultLogger.class; } else if ( requiredInterface == Executor.class ) { return JdbcExecutor.class; } else { throw new ServiceNotFoundException("Could not find implementation of " + requiredInterface.getName()); } } protected  ServiceLocator(); protected  ServiceLocator(ResourceAccessor accessor); protected  ServiceLocator(PackageScanClassResolver classResolver); protected  ServiceLocator(PackageScanClassResolver classResolver, ResourceAccessor accessor); static ServiceLocator getInstance(); static void setInstance(ServiceLocator newInstance); void setResourceAccessor(ResourceAccessor resourceAccessor); void addPackageToScan(String packageName); Class findClass(Class requiredInterface); Class[] findClasses(Class requiredInterface); Object newInstance(Class requiredInterface); static void reset(); }
ServiceLocator { public Class findClass(Class requiredInterface) throws ServiceNotFoundException { if (requiredInterface == Logger.class ) { return DefaultLogger.class; } else if ( requiredInterface == Executor.class ) { return JdbcExecutor.class; } else { throw new ServiceNotFoundException("Could not find implementation of " + requiredInterface.getName()); } } protected  ServiceLocator(); protected  ServiceLocator(ResourceAccessor accessor); protected  ServiceLocator(PackageScanClassResolver classResolver); protected  ServiceLocator(PackageScanClassResolver classResolver, ResourceAccessor accessor); static ServiceLocator getInstance(); static void setInstance(ServiceLocator newInstance); void setResourceAccessor(ResourceAccessor resourceAccessor); void addPackageToScan(String packageName); Class findClass(Class requiredInterface); Class[] findClasses(Class requiredInterface); Object newInstance(Class requiredInterface); static void reset();  }