001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.wicket.validation; 018 019import org.apache.wicket.behavior.Behavior; 020import org.apache.wicket.util.lang.Args; 021 022/** 023 * Adapts {@link IValidator} to Behavior 024 * 025 * @author igor 026 * @param <T> 027 * type of validator's validatable 028 */ 029public class ValidatorAdapter<T> extends Behavior implements IValidator<T> 030{ 031 private static final long serialVersionUID = 1L; 032 033 private final IValidator<T> validator; 034 035 /** 036 * Constructor 037 * 038 * @param validator 039 * validator to be adapted 040 */ 041 public ValidatorAdapter(IValidator<T> validator) 042 { 043 Args.notNull(validator, "validator"); 044 045 this.validator = validator; 046 } 047 048 /** {@inheritDoc} */ 049 @Override 050 public void validate(IValidatable<T> validatable) 051 { 052 validator.validate(validatable); 053 } 054 055 /** 056 * Gets adapted validator 057 * 058 * @return validator 059 */ 060 public IValidator<T> getValidator() 061 { 062 return validator; 063 } 064}