ValidateChain.java
/***************************************************************************
Copyright 2013 Emily Estes
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
***************************************************************************/
package net.metanotion.formsauth;
import java.util.Arrays;
import net.metanotion.util.Nullable;
import net.metanotion.util.SecureString;
import net.metanotion.web.RequestObject;
/** Chain instances of the Validate interface to apply a sequence af validators to
the account creation request. */
public final class ValidateChain implements Validate {
private final Iterable<Validate> checks;
/** Create a validation chain from an array of validators.
@param checks The array of validators to use.
*/
public ValidateChain(final Validate... checks) { this.checks = Arrays.asList(checks); }
/** Create a validation chain from an iterable collection of validators.
@param checks The iterable collection.
*/
public ValidateChain(final Iterable<Validate> checks) { this.checks = checks; }
@Override public void validate(final String username, final SecureString password, @Nullable final RequestObject ro) {
for(final Validate v: checks) { v.validate(username, password, ro); }
}
}