try {
Constructor constructor = this.productClass.getConstructor(typesArray);
Object product = constructor.newInstance(argsArray);
return product;
} catch (NoSuchMethodException ex) {
throw new ObjectConstructionException("No constructor found accepting the following array of types: "
+ ToStringBuilder.reflectionToString(typesArray, ToStringStyle.SIMPLE_STYLE)
+ " Have you correctly set all constructor arguments?", ex);
} catch (InvocationTargetException ex) {
throw new ObjectConstructionException("Exception thrown by the underlying constructor: "
+ ex.getMessage(), ex);
} catch (IllegalAccessException ex) {
throw new ObjectConstructionException("Cannot access a constructor with the following array of types: "
+ ToStringBuilder.reflectionToString(typesArray, ToStringStyle.SIMPLE_STYLE)
+ " Have you correctly set all constructor arguments?", ex);
} catch (InstantiationException ex) {
throw new ObjectConstructionException("Unable to instantiate the following class: "
+ this.productClass, ex);
}
}