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

com.imsweb.validation.internal.IterativeProcessor Maven / Gradle / Ivy

/*
 * Copyright (C) 2004 Information Management Services, Inc.
 */
package com.imsweb.validation.internal;

import java.util.ArrayList;
import java.util.Collection;

import com.imsweb.validation.ValidatingContext;
import com.imsweb.validation.ValidationException;
import com.imsweb.validation.entities.RuleFailure;
import com.imsweb.validation.entities.Validatable;

/**
 * An IterativeProcessor is a Processor that follows a collection on a Validatable.
 * 

* Conceptually, an IterativeProcessor does not execute any edits; it is only a mechanism to iterate over a complex data structure. *

* Created on Apr 26, 2011 by depryf * @author depryf */ public class IterativeProcessor implements Processor { /** * Name of the collection associated with this processor */ private final String _collectionName; /** * Child processor */ private final Processor _processor; /** * Constructor *

* Created on Jan 9, 2006 by Mike Ringrose * @param processor that performs all of the actual work * @param collectionName collection to iterate over */ public IterativeProcessor(Processor processor, String collectionName) { if (processor == null) throw new RuntimeException("Cannot create an iterative processor from a null processor!"); if (collectionName == null) throw new RuntimeException("Cannot create an iterative processor from a null collection name!"); _processor = processor; _collectionName = collectionName; } @Override public Collection process(Validatable validatable, ValidatingContext procCtx) throws ValidationException { Collection results = new ArrayList<>(); try { // it is important to pass a new version of the failedRuleIds and failedConditionsIds! for (Validatable childValidatable : validatable.followCollection(_collectionName)) results.addAll(_processor.process(childValidatable, procCtx)); } catch (IllegalAccessException e) { throw new ValidationException(e); } return results; } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy