// Path: inputvalidation/src/main/java/com/switchfly/inputvalidation/exception/InvalidRequestParameterException.java
// public class InvalidRequestParameterException extends MissingRequestParameterException {
// 
//     private static final long serialVersionUID = 1L;
//     private final String _parameterValue;
// 
//     public InvalidRequestParameterException(String parameterName, String parameterValue) {
//         super(parameterName, "Invalid request parameter: " + parameterName + " = " + parameterValue);
//         _parameterValue = parameterValue;
//     }
// 
//     public InvalidRequestParameterException(String parameterName, String parameterValue, Throwable cause) {
//         super(parameterName, "Invalid request parameter: " + parameterName + " = " + parameterValue, cause);
//         _parameterValue = parameterValue;
//     }
// 
//     public String getParameterValue() {
//         return _parameterValue;
//     }
// }
// 
// Path: inputvalidation/src/main/java/com/switchfly/inputvalidation/exception/MissingRequestParameterException.java
// public class MissingRequestParameterException extends RuntimeException {
// 
//     private static final long serialVersionUID = 1L;
//     private final String _parameterName;
// 
//     public MissingRequestParameterException(String parameterName) {
//         super("Missing request parameter: " + parameterName + ".");
//         _parameterName = parameterName;
//     }
// 
//     public MissingRequestParameterException(String parameterName, String message) {
//         super(message);
//         _parameterName = parameterName;
//     }
// 
//     public MissingRequestParameterException(String parameterName, String message, Throwable cause) {
//         super(message, cause);
//         _parameterName = parameterName;
//     }
// 
//     public String getParameterName() {
//         return _parameterName;
//     }
// }
// 
// Path: inputvalidation/src/main/java/com/switchfly/inputvalidation/exception/ValidatorException.java
// public class ValidatorException extends RuntimeException {
//     private static final long serialVersionUID = 1L;
//     private final String _sanitizedContent;
// 
//     public ValidatorException(String sanitizedContent) {
//         _sanitizedContent = sanitizedContent;
//     }
// 
//     public ValidatorException(String sanitizedContent, String message) {
//         super(message);
//         _sanitizedContent = sanitizedContent;
//     }
// 
//     public String getSanitizedContent() {
//         return _sanitizedContent;
//     }
// }


import com.switchfly.inputvalidation.exception.InvalidRequestParameterException;
import com.switchfly.inputvalidation.exception.MissingRequestParameterException;
import com.switchfly.inputvalidation.exception.ValidatorException;
/*
 * Copyright 2012 Switchfly
 *
 * 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 com.switchfly.inputvalidation;


public class Parameter<E> {

    private final String _name;
    private final E _value;
    private final ValidationStrategy<String> _parameterNameValidationStrategy = new ParameterNameValidationStrategy();

    private ValidationStrategy<E> _validationStrategy = new ValidationStrategy<E>(null, null, null);

    public Parameter(String name, E value) {
        _name = name;
        _value = value;
    }

    protected E getValue() {
        return _value;
    }

    public String getName() {
        return _parameterNameValidationStrategy.validate(_name);
    }

    public Parameter<E> validateWith(ValidationStrategy<E> validationStrategy) {
        _validationStrategy = validationStrategy;
        return this;
    }

    public boolean isEmpty() {
        return _value == null;
    }

    public E validate() {
        if (isEmpty()) {
            throw new MissingRequestParameterException(getName());
        }
        try {
            return _validationStrategy.validate(_value);
// Path: inputvalidation/src/main/java/com/switchfly/inputvalidation/exception/InvalidRequestParameterException.java
// public class InvalidRequestParameterException extends MissingRequestParameterException {
// 
//     private static final long serialVersionUID = 1L;
//     private final String _parameterValue;
// 
//     public InvalidRequestParameterException(String parameterName, String parameterValue) {
//         super(parameterName, "Invalid request parameter: " + parameterName + " = " + parameterValue);
//         _parameterValue = parameterValue;
//     }
// 
//     public InvalidRequestParameterException(String parameterName, String parameterValue, Throwable cause) {
//         super(parameterName, "Invalid request parameter: " + parameterName + " = " + parameterValue, cause);
//         _parameterValue = parameterValue;
//     }
// 
//     public String getParameterValue() {
//         return _parameterValue;
//     }
// }
// 
// Path: inputvalidation/src/main/java/com/switchfly/inputvalidation/exception/MissingRequestParameterException.java
// public class MissingRequestParameterException extends RuntimeException {
// 
//     private static final long serialVersionUID = 1L;
//     private final String _parameterName;
// 
//     public MissingRequestParameterException(String parameterName) {
//         super("Missing request parameter: " + parameterName + ".");
//         _parameterName = parameterName;
//     }
// 
//     public MissingRequestParameterException(String parameterName, String message) {
//         super(message);
//         _parameterName = parameterName;
//     }
// 
//     public MissingRequestParameterException(String parameterName, String message, Throwable cause) {
//         super(message, cause);
//         _parameterName = parameterName;
//     }
// 
//     public String getParameterName() {
//         return _parameterName;
//     }
// }
// 
// Path: inputvalidation/src/main/java/com/switchfly/inputvalidation/exception/ValidatorException.java
// public class ValidatorException extends RuntimeException {
//     private static final long serialVersionUID = 1L;
//     private final String _sanitizedContent;
// 
//     public ValidatorException(String sanitizedContent) {
//         _sanitizedContent = sanitizedContent;
//     }
// 
//     public ValidatorException(String sanitizedContent, String message) {
//         super(message);
//         _sanitizedContent = sanitizedContent;
//     }
// 
//     public String getSanitizedContent() {
//         return _sanitizedContent;
//     }
// }


// Path: inputvalidation/src/main/java/com/switchfly/inputvalidation/Parameter.java
import com.switchfly.inputvalidation.exception.InvalidRequestParameterException;
import com.switchfly.inputvalidation.exception.MissingRequestParameterException;
import com.switchfly.inputvalidation.exception.ValidatorException;

/*
 * Copyright 2012 Switchfly
 *
 * 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 com.switchfly.inputvalidation;


public class Parameter<E> {

    private final String _name;
    private final E _value;
    private final ValidationStrategy<String> _parameterNameValidationStrategy = new ParameterNameValidationStrategy();

    private ValidationStrategy<E> _validationStrategy = new ValidationStrategy<E>(null, null, null);

    public Parameter(String name, E value) {
        _name = name;
        _value = value;
    }

    protected E getValue() {
        return _value;
    }

    public String getName() {
        return _parameterNameValidationStrategy.validate(_name);
    }

    public Parameter<E> validateWith(ValidationStrategy<E> validationStrategy) {
        _validationStrategy = validationStrategy;
        return this;
    }

    public boolean isEmpty() {
        return _value == null;
    }

    public E validate() {
        if (isEmpty()) {
            throw new MissingRequestParameterException(getName());
        }
        try {
            return _validationStrategy.validate(_value);
        } catch (ValidatorException e) {