001: /*
002: * Copyright 2005-2006 the original author or authors.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
005: * in compliance with the License. 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 distributed under the License
010: * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
011: * or implied. See the License for the specific language governing permissions and limitations under
012: * the License.
013: */
014:
015: package org.strecks.validator.internal;
016:
017: import java.lang.reflect.Method;
018: import java.util.List;
019:
020: import org.strecks.util.Assert;
021: import org.strecks.validator.Validator;
022: import org.strecks.validator.message.MessageParameterProvider;
023:
024: /**
025: * Immutable wrapper class which holds a <code>Validator</code> as well as other metadata, such as
026: * the messages key, parameters, the validation order, whether a converted value is used, etc.
027: * @author Phil Zoio
028: */
029: public class ValidatorWrapper implements Comparable<ValidatorWrapper> {
030:
031: private String key;
032:
033: private List<Object> params;
034:
035: private Validator validator;
036:
037: private Method method;
038:
039: private int order;
040:
041: private boolean usesConvertedValue;
042:
043: private Class<?> parameterizedType;
044:
045: private MessageParameterProvider parameterProvider;
046:
047: public ValidatorWrapper(String key, int order, List<Object> params,
048: Validator validator, Method method,
049: MessageParameterProvider paramProvider) {
050: super ();
051:
052: Assert.notNull(key);
053: Assert.notNull(validator);
054: Assert.notNull(method);
055: Assert.notNull(paramProvider);
056:
057: this .key = key;
058: this .order = order;
059: this .params = params;
060: this .validator = validator;
061: this .method = method;
062: this .parameterProvider = paramProvider;
063: }
064:
065: public ValidatorWrapper(String key, int order, List<Object> params,
066: Validator validator, Method method,
067: MessageParameterProvider paramProvider,
068: boolean usesConvertedValue, Class<?> parameterizedType) {
069: this (key, order, params, validator, method, paramProvider);
070: this .usesConvertedValue = usesConvertedValue;
071: this .parameterizedType = parameterizedType;
072: }
073:
074: public String getKey() {
075: return key;
076: }
077:
078: public List<Object> getParams() {
079: return params;
080: }
081:
082: public Validator getValidator() {
083: return validator;
084: }
085:
086: public Method getGetterMethod() {
087: return method;
088: }
089:
090: // notice the silent conversion to an Integer
091: public Integer getOrder() {
092: return order;
093: }
094:
095: public int compareTo(ValidatorWrapper o) {
096: return o.getOrder().compareTo(order);
097: }
098:
099: public MessageParameterProvider getParameterProvider() {
100: return parameterProvider;
101: }
102:
103: public boolean getUsesConvertedValue() {
104: return usesConvertedValue;
105: }
106:
107: public Class<?> getParameterizedType() {
108: return parameterizedType;
109: }
110:
111: public void setParameterizedType(Class<?> parameterizedType) {
112: this.parameterizedType = parameterizedType;
113: }
114:
115: }
|