All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.lotaris.jee.validation.preprocessing.PreprocessingChain Maven / Gradle / Ivy

Go to download

This library offers components that facilitate validation of arbitrary objects and how they are serialized towards a client. It focuses on the wiring of the proposed patterns and does not contain any concrete validator implementations.

There is a newer version: 0.5.2
Show newest version
package com.lotaris.jee.validation.preprocessing;

import java.util.ArrayList;
import java.util.List;

/**
 * Chain of {@link IPreprocessor} processes to apply to an object. You can add a preprocessor to the
 * chain with add. The chain runs all preprocessors in the order they were added. It stops
 * if any of the preprocessors indicates failure.
 *
 * @author Simon Oulevay ([email protected])
 * @see DefaultPreprocessingChain
 */
public class PreprocessingChain implements IPreprocessor {

	private List processors;

	public PreprocessingChain() {
		processors = new ArrayList<>();
	}

	/**
	 * Adds a preprocessor to be run at the end of the chain.
	 *
	 * @param processor the preprocessor to add
	 * @return this updated chain
	 */
	public PreprocessingChain add(IPreprocessor processor) {
		processors.add(processor);
		return this;
	}

	@Override
	public boolean process(Object object, IPreprocessingConfig config) {

		for (IPreprocessor processor : processors) {
			if (!processor.process(object, config)) {
				return false;
			}
		}

		return true;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy