Made failure message customizable.

This commit is contained in:
David Montag
2011-04-07 13:08:54 -07:00
parent 71f08efa53
commit 35537aba8a

View File

@@ -57,12 +57,16 @@ public abstract class AbstractConstructorEntityInstantiator<BACKING_INTERFACE, S
private <T extends BACKING_INTERFACE> StateBackedCreator<T, STATE> createFailingInstantiator(final Class<STATE> stateType) {
return new StateBackedCreator<T, STATE>() {
public T create(STATE n, Class<T> c) throws Exception {
throw new IllegalArgumentException(getClass().getSimpleName() + ": entity " + c +
" must have either a constructor taking [" + stateType + "] or a no-arg constructor and state set method");
throw new IllegalArgumentException(getFailingMessageForClass(c, stateType));
}
};
}
protected String getFailingMessageForClass(Class<?> entityClass, Class<STATE> stateClass) {
return getClass().getSimpleName() + ": entity " + entityClass +
" must have either a constructor taking [" + stateClass + "] or a no-arg constructor and state setter.";
}
private <T extends BACKING_INTERFACE> StateBackedCreator<T, STATE> emptyConstructorStateSettingInstantiator(Class<T> type, Class<STATE> stateType) {
final Constructor<T> constructor = getNoArgConstructor(type);
if (constructor == null) return null;