List of usage examples for org.apache.commons.beanutils ConstructorUtils invokeConstructor
public static Object invokeConstructor(Class klass, Object[] args) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException
Returns new instance of klazz created using the actual arguments args.
From source file:br.com.sicoob.cro.cop.batch.step.StepTaskletExecutor.java
public void start() throws Exception { ConstructorUtils.invokeConstructor(TaskletInjector.class, this.step).inject(); TaskletExecutor taskletExecutor = new TaskletExecutor(this.step); this.task = new FutureTask(taskletExecutor); this.service.executeTask(task); }
From source file:com.create.validation.MultiDateConstraintValidator.java
@Override public void initialize(MultiDateConstraint multiDateConstraint) { final Class<? extends MultiDateConstraintChecker> constraintCheckerClass = multiDateConstraint .constraintChecker();/*from w ww .j a va 2 s . co m*/ try { constraintChecker = ConstructorUtils.invokeConstructor(constraintCheckerClass, null); } catch (final IllegalAccessException | InvocationTargetException | NoSuchMethodException | InstantiationException e) { throw new IllegalArgumentException(e); } this.multiDateConstraint = multiDateConstraint; }
From source file:com.github.dozermapper.core.functional_tests.runner.NoProxyDataObjectInstantiator.java
public <T> T newInstance(Class<T> classToInstantiate, Object[] args) { try {/*from w ww . ja va 2 s . c om*/ return ConstructorUtils.invokeConstructor(classToInstantiate, args); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:eu.squadd.testing.objectspopulator.RandomValuePopulator.java
private <P> P getMathNumberType(final Class<P> klass) { try {//from w w w. j ava2 s . c om if (BigDecimal.class.isAssignableFrom(klass)) { return (P) ConstructorUtils.invokeConstructor(klass, 0L); } else if (BigInteger.class.isAssignableFrom(klass)) { return (P) ConstructorUtils.invokeConstructor(klass, 0); } else { System.out.println("*** Unknown Math type, skipping for now !!!"); return null; } } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | InstantiationException ex) { Logger.getLogger(RandomValuePopulator.class.getName()).log(Level.SEVERE, null, ex); return null; } }
From source file:com.curl.orb.servlet.InstanceManagementUtil.java
/** * Create new instance.// w w w . j a va2 s .com */ public static Object newInstance(Class<?> cls, Object[] arguments) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException { return ConstructorUtils.invokeConstructor(cls, arguments); }
From source file:br.com.sicoob.cro.cop.batch.configuration.ItemProcessorInjector.java
/** * Cria o contexto de dados para o tasklet. * * @return um {@link TaskletContext}./*from ww w . j a va 2 s .c o m*/ */ private ChunkContext createContext() throws Exception { return ConstructorUtils.invokeConstructor(ChunkContext.class, (StepParameters) PropertyUtils.getProperty(this.step, BatchKeys.PARAMETERS.getKey())); }
From source file:br.com.sicoob.cro.cop.batch.configuration.TaskletInjector.java
/** * Cria o contexto de dados para o tasklet. * * @return um {@link TaskletContext}.// w w w. j ava 2s . c om */ private TaskletContext createContext() throws Exception { return ConstructorUtils.invokeConstructor(TaskletContext.class, (StepParameters) PropertyUtils.getProperty(this.step, BatchKeys.PARAMETERS.getKey())); }
From source file:com.hs.mail.container.simple.SimpleSpringContainer.java
public Object createFileSystemXmlApplicationContext(String[] configLocations) throws Exception { ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); Class klass = classLoader.loadClass(IMPL_CLASS_NAME); Object[] args = new Object[] { configLocations, Boolean.FALSE }; Object applicationContext = ConstructorUtils.invokeConstructor(klass, args); MethodUtils.invokeMethod(applicationContext, "refresh", null); return applicationContext; }
From source file:eu.squadd.testing.objectspopulator.RandomValuePopulator.java
public Object populateAllFields(final Class targetClass, Map exclusions) throws IllegalAccessException, InstantiationException { final Object target; try {// ww w. j a v a2 s . c o m if (isMathNumberType(targetClass)) { target = getMathNumberType(targetClass); } else { target = ConstructorUtils.invokeConstructor(targetClass, null); } } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | InstantiationException ex) { System.err.println(ex.getMessage()); return null; } //final Object target = targetClass.newInstance(); //Get all fields present on the target class final Set<Field> allFields = getAllFields(targetClass, Predicates.<Field>alwaysTrue()); if (this.stopOnMxRecusionDepth) this.currentRecursionDepth++; //Iterate through fields if recursion depth is not reached if (!this.stopOnMxRecusionDepth || (this.stopOnMxRecusionDepth && this.currentRecursionDepth <= scannerFactory.getRecursionDepth())) { for (final Field field : allFields) { try { // check if the field is not on exclusion list if (exclusions != null && exclusions.containsValue(field.getName())) continue; //Set fields to be accessible even when private field.setAccessible(true); final Class<?> fieldType = field.getType(); if (fieldType.isEnum() && Enum.class.isAssignableFrom(fieldType)) { //handle any enums here if you have any } else if (isMathNumberType(fieldType)) { //System.out.println("*** Math number found, populating it: "+fieldType); field.set(target, getManufacturedPojo(fieldType)); } //Check if the field is a collection else if (Collection.class.isAssignableFrom(fieldType)) { //Get the generic type class of the collection final Class<?> genericClass = getGenericClass(field); //Check if the generic type of a list is abstract if (Modifier.isAbstract(genericClass.getModifiers())) { System.out.println("Abstract classes are not supported !!!"); // this stuff needs real class extending abstract one to work //final List<Object> list = new ArrayList(); //list.add(populateAllIn(ClassExtendingAbstract.class)); //field.set(target, list); } else { final List<Object> list = new ArrayList(); list.add(populateAllFields(genericClass, exclusions)); field.set(target, list); } } else if ((isSimpleType(fieldType) || isSimplePrimitiveWrapperType(fieldType)) && !fieldType.isEnum()) { field.set(target, getManufacturedPojo(fieldType)); } else if (!fieldType.isEnum()) { field.set(target, populateAllFields(fieldType, exclusions)); } } catch (IllegalAccessException | InstantiationException ex) { System.err.println(ex.getMessage()); } } } return target; }
From source file:com.otiliouine.configurablefactory.ConfigurableFactory.java
/** * Creates an instance of the implementation class mapped to <b>interfazz</b> * //from w w w . j a va 2s . c om * @param interfazz the Interface or class which represents the abstraction of instance types * @param args the arguments to use when creating the new instance * @return a new instance of the implementation class mapped to <b>interfazz</b> */ public <T> T createInstance(Class<T> interfazz, Object... args) { Class<T> clazz = (Class<T>) mapping.get(interfazz); if (clazz == null) { throw new NoFactoryDefinitionException( "No factory is defined for class " + interfazz.getCanonicalName()); } try { T instance = (T) ConstructorUtils.invokeConstructor(clazz, args); return interfazz.cast(instance); } catch (ClassCastException e) { throw new InvalidMappingValuesException( "invalid factory configuration, class " + clazz.getCanonicalName(), e); } catch (Exception e) { throw new RuntimeException(e.getMessage(), e); } }