/** * Instantiate the document repository from a string, to be able to use * third party repositories. */ private DocumentRepository instantiateDocumentRepository() { DocumentRepository documentRepository = ClassUtils.createInstanceFromClassNameWithArguments(classLoader, documentRepositoryClass, DocumentRepository.class); return documentRepository; }
/** * Instantiate the system under development from a string, to be able to use * third party SuDs. */ private SystemUnderDevelopment instantiateSystemUnderDevelopment() { LOG.debug("Creating SUD " + systemUnderDevelopmentClass); SystemUnderDevelopment systemUnderDevelopment = ClassUtils.createInstanceFromClassNameWithArguments(classLoader, systemUnderDevelopmentClass, SystemUnderDevelopment.class); systemUnderDevelopment.setClassLoader(classLoader); return systemUnderDevelopment; }
public DocumentRepository asDocumentRepository(ClassLoader classLoader, String user, String pwd) throws UndeclaredThrowableException { return ClassUtils.createInstanceFromClassNameWithArguments(classLoader, type.asFactoryArguments(this, true, user, pwd), DocumentRepository.class); }
@Test public void shouldInstantiateClassFromArguments() throws Exception { String className = MySytemUnderDevelopment.class.getName(); String classNameWithArguments = className + ";arg1;arg2;arg3"; SystemUnderDevelopment sud = ClassUtils.createInstanceFromClassNameWithArguments(Thread.currentThread() .getContextClassLoader(), classNameWithArguments, SystemUnderDevelopment.class); assertTrue(sud instanceof MySytemUnderDevelopment); MySytemUnderDevelopment mySud = ( MySytemUnderDevelopment ) sud; assertEquals(mySud.getParam(0), "arg1"); assertEquals(mySud.getParam(1), "arg2"); assertEquals(mySud.getParam(2), "arg3"); }