001    // Copyright 2006, 2008, 2010 The Apache Software Foundation
002    //
003    // Licensed under the Apache License, Version 2.0 (the "License");
004    // you may not use this file except in compliance with the License.
005    // You may obtain a copy of the License at
006    //
007    // http://www.apache.org/licenses/LICENSE-2.0
008    //
009    // Unless required by applicable law or agreed to in writing, software
010    // distributed under the License is distributed on an "AS IS" BASIS,
011    // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012    // See the License for the specific language governing permissions and
013    // limitations under the License.
014    
015    package org.apache.tapestry5.internal.services;
016    
017    import org.apache.tapestry5.internal.TapestryInternalUtils;
018    
019    /**
020     * Validator type and constraint values parsed from a validator specification.
021     */
022    public class ValidatorSpecification
023    {
024        private final String validatorType;
025    
026        private final String constraintValue;
027    
028        public ValidatorSpecification(String validatorType)
029        {
030            this(validatorType, null);
031        }
032    
033        public ValidatorSpecification(String validatorType, String constraintValue)
034        {
035            this.validatorType = validatorType;
036            this.constraintValue = constraintValue;
037        }
038    
039        public String getConstraintValue()
040        {
041            return constraintValue;
042        }
043    
044        public String getValidatorType()
045        {
046            return validatorType;
047        }
048    
049        @Override
050        public String toString()
051        {
052            return String.format("ValidatorSpecification[%s %s]", validatorType, constraintValue);
053        }
054    
055        @Override
056        public boolean equals(Object other)
057        {
058            if (other == null || other.getClass() != getClass())
059                return false;
060    
061            ValidatorSpecification ov = (ValidatorSpecification) other;
062    
063            if (!validatorType.equals(ov.validatorType))
064                return false;
065    
066            return TapestryInternalUtils.isEqual(constraintValue, ov.constraintValue);
067        }
068    }