
org.ioc.commons.flowcontrol.operationmanager.impl.OperationHandlerFactory 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.operationmanager.impl;
import org.ioc.commons.flowcontrol.operationmanager.IsOperation;
import org.ioc.commons.flowcontrol.operationmanager.OperationHandler;
import org.ioc.commons.ui.HasEnabled;
import org.ioc.commons.ui.HasLoader;
import org.ioc.commons.ui.HasPendingOperationsLoader;
import org.ioc.commons.ui.HasVisibility;
/**
* A factory for creating operation handlers for common components.
*
* @author Jesús Lunar Pérez
*
*/
public final class OperationHandlerFactory {
/**
* Behavior to perform when a null value is assigned.
*
* @author Jesús Lunar Pérez
*
*/
public enum NullBehavior {
/**
* The element will be ignored but a WARN log will be sent to the
* console output.
*
* It is the default value.
*/
IGNORE_AND_LOG_WARNING,
/**
* A {@link NullPointerException} will be thrown
*/
NULLPOINTER_EXCEPTION,
/**
* The element will be ignored and no log will be written in console
* output.
*/
SILENT_IGNORE;
}
private static NullBehavior ignoreNullValues = NullBehavior.IGNORE_AND_LOG_WARNING;
private OperationHandlerFactory() {
// No instanciable
}
/**
* New instance of {@link OperationHandler} which fires setLoading(true) or
* setLoading(false) on loaders passed as parameters when operation begins and
* ends respectively.
*
* @param loaders
* @return A new OperationHandler instance.
*
* @see #setIgnoreNullValues(NullBehavior)
*/
public static & IsOperation> OperationHandler forLoaders(HasLoader... loaders) {
if (ignoreNullValues == NullBehavior.NULLPOINTER_EXCEPTION) {
ensureNotNull("Parameter 'loaders' cannot be null or contain null values", loaders);
}
return new HasLoaderOperationHandler(ignoreNullValues != NullBehavior.SILENT_IGNORE, loaders);
}
/**
* New instance of {@link OperationHandler} which fires
* {@link HasPendingOperationsLoader#operationBeginning()} and
* {@link HasPendingOperationsLoader#operationFinished()} on loaders passed
* as parameters when operation begins and ends respectively.
*
* @param loaders
* @return A new OperationHandler instance.
*
* @see #setIgnoreNullValues(NullBehavior)
*/
public static & IsOperation> OperationHandler forLoaders(
HasPendingOperationsLoader... loaders) {
if (ignoreNullValues == NullBehavior.NULLPOINTER_EXCEPTION) {
ensureNotNull("Parameter 'loaders' cannot be null or contain null values", loaders);
}
return new HasPendingOperationsLoaderOperationHandler(ignoreNullValues != NullBehavior.SILENT_IGNORE,
loaders);
}
/**
* New instance of {@link OperationHandler} which fires setEnabled(false) or
* setEnabled(true) on enablers passed as parameters when operation begins and
* ends respectively.
*
* @param enablers
* @return A new OperationHandler instance.
*
* @see #setIgnoreNullValues(NullBehavior)
*/
public static & IsOperation> OperationHandler forEnablers(HasEnabled... enablers) {
if (ignoreNullValues == NullBehavior.NULLPOINTER_EXCEPTION) {
ensureNotNull("Parameter 'enablers' cannot be null or contain null values", enablers);
}
return new HasEnabledOperationHandler(ignoreNullValues != NullBehavior.SILENT_IGNORE, enablers);
}
/**
* New instance of {@link OperationHandler} which fires setVisible(true) or
* setVisible(false) on visibles passed as parameters when operation begins and
* ends respectively.
*
* @param visibles
* @return A new OperationHandler instance.
*
* @see #setIgnoreNullValues(NullBehavior)
*/
public static & IsOperation> OperationHandler forVisibles(HasVisibility... visibles) {
if (ignoreNullValues == NullBehavior.NULLPOINTER_EXCEPTION) {
ensureNotNull("Parameter 'visibles' cannot be null or contain null values", visibles);
}
return new HasVisibilityOperationHandler(ignoreNullValues != NullBehavior.SILENT_IGNORE, visibles);
}
private static void ensureNotNull(String message, T[] instanceArray) {
if (instanceArray == null) {
throw new NullPointerException(message);
}
for (T instance : instanceArray) {
if (instance == null) {
throw new NullPointerException(message);
}
}
}
/**
* Get the current behavior when a null value is assigned as parameter in
* the forXXXXX methods of this class.
*
* @return Current null value assigned behavior
*/
public static NullBehavior getIgnoreNullValues() {
return ignoreNullValues;
}
/**
* Set the current behavior when a null value is assigned as parameter in
* the forXXXX methods of this class
*
* @param ignoreNullLoaders
* Behavior when a null value is assigned. See
* {@link NullBehavior} to get more information about available
* behaviors.
*/
public static void setIgnoreNullValues(NullBehavior ignoreNullLoaders) {
OperationHandlerFactory.ignoreNullValues = ignoreNullLoaders;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy