
org.ioc.commons.flowcontrol.common.impl.ReceiverAdapter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ioc-commons-ext Show documentation
Show all versions of ioc-commons-ext Show documentation
Library which contains some extension classes for the library IOC-Commons.
It provides some interface definitions and some tool classes which are non-dependent from the used technology;
i.e. the classes and interfaces from this library do not depend on the choosen ioc-commons-implementation library.
The newest version!
package org.ioc.commons.flowcontrol.common.impl;
import java.util.Set;
import javax.validation.ConstraintViolation;
import javax.validation.ConstraintViolationException;
import org.ioc.commons.flowcontrol.common.Receiver;
import org.ioc.commons.flowcontrol.exceptioncontroller.ExceptionController;
/**
* Adapter for {@link Receiver}
*
* @author Jesús Lunar Pérez
*
* @param
* Success result type
*/
public abstract class ReceiverAdapter implements Receiver {
public static final String GLOBAL_EXCEPTION_CONTROLLER_MESSAGE_INFO = "Exception thrown";
private static ExceptionController globalExceptionController;
protected final ExceptionController receiverExceptionController;
private static String globalExceptionControllerMessageInfo = null; /* GLOBAL_EXCEPTION_CONTROLLER_MESSAGE_INFO */;
public ReceiverAdapter() {
// Default const.
this.receiverExceptionController = null;
}
public ReceiverAdapter(ExceptionController exceptionController) {
this.receiverExceptionController = exceptionController;
}
@Override
public void onEnd(boolean success) {
// Override me
}
@Override
public abstract void success(V result);
@Override
public void failure(Throwable failure) {
// Override me
if (this.receiverExceptionController != null) {
this.receiverExceptionController.handleException(failure, getOnFailureMessageInfo(failure));
} else if (globalExceptionController != null) {
globalExceptionController.handleException(failure, getOnFailureMessageInfo(failure));
} else {
throw new RuntimeException(failure);
}
}
@Override
public void constraintViolation(Set> violations) {
// Override me
throw new ConstraintViolationException(violations);
}
public static ExceptionController getGlobalExceptionController() {
return globalExceptionController;
}
public static void setGlobalExceptionController(ExceptionController globalExceptionController) {
ReceiverAdapter.globalExceptionController = globalExceptionController;
}
public static String getGlobalExceptionControllerMessageInfo() {
return globalExceptionControllerMessageInfo;
}
public static void setGlobalExceptionControllerMessageInfo(String globalExceptionControllerMessageInfo) {
ReceiverAdapter.globalExceptionControllerMessageInfo = globalExceptionControllerMessageInfo;
}
protected String getOnFailureMessageInfo(Throwable failure) {
return globalExceptionControllerMessageInfo != null ? globalExceptionControllerMessageInfo : (failure
.getMessage() != null ? failure.getMessage() : GLOBAL_EXCEPTION_CONTROLLER_MESSAGE_INFO);
}
public ExceptionController getReceiverExceptionController() {
return receiverExceptionController;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy