// nothing to decorate
try {
current = implClass.newInstance();
} catch (InstantiationException e) {
log.error(e.getMessage(), e);
throw new StrutsException(e);
} catch (IllegalAccessException e) {
log.error(e.getMessage(), e);
throw new StrutsException(e);
}
} else {
// let's check if class supports the decorator pattern
try {
Constructor delegationConstructor = implClass
.getConstructor(new Class[] { interfaceClass });
// impl class supports decorator pattern,
try {
// create new decorator wrapping current
current = delegationConstructor
.newInstance(new Object[] { current });
} catch (InstantiationException e) {
log.error(e.getMessage(), e);
throw new StrutsException(e);
} catch (IllegalAccessException e) {
log.error(e.getMessage(), e);
throw new StrutsException(e);
} catch (InvocationTargetException e) {
log.error(e.getMessage(), e);
throw new StrutsException(e);
}
} catch (NoSuchMethodException e) {
// no decorator pattern support
try {
current = implClass.newInstance();
} catch (InstantiationException e1) {
log.error(e.getMessage(), e);
throw new StrutsException(e);
} catch (IllegalAccessException e1) {
log.error(e.getMessage(), e);
throw new StrutsException(e);
}
}
}
}