001 /*
002 *
003 * Licensed to the Apache Software Foundation (ASF) under one
004 * or more contributor license agreements. See the NOTICE file
005 * distributed with this work for additional information
006 * regarding copyright ownership. The ASF licenses this file
007 * to you under the Apache License, Version 2.0 (the
008 * "License"); you may not use this file except in compliance
009 * with the License. You may obtain a copy of the License at
010 *
011 * http://www.apache.org/licenses/LICENSE-2.0
012 *
013 * Unless required by applicable law or agreed to in writing,
014 * software distributed under the License is distributed on an
015 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
016 * KIND, either express or implied. See the License for the
017 * specific language governing permissions and limitations
018 * under the License.
019 *
020 */
021 package org.apache.qpid.management.domain.model;
022
023 /**
024 * Thrown when an attempt is made in order to update / change the state of an object and a constraint on that state
025 * is violated.
026 *
027 * @author Andrea Gazzarini
028 */
029 public class ValidationException extends Exception
030 {
031 private static final long serialVersionUID = -5218828669655586205L;
032
033 public final static String MAX_LENGTH = "Max Length";
034 public final static String MAX_VALUE = "Max Value";
035 public final static String MIN_VALUE = "Min Value";
036
037 private final String _featureName;
038 private final Object _featureValue;
039
040 private final Number _constraintValue;
041 private final String _constraintName;
042
043 /**
044 * Builds a new validation exception with the specified parameters.
045 *
046 * @param constraintName the name of the violated constraint.
047 * @param constraintValue the value of the violated constraint.
048 * @param featureName the name of the violating feature.
049 * @param featureValue the value of the violating feature.
050 */
051 ValidationException(String constraintName,Number constraintValue, String featureName,Object featureValue)
052 {
053 super(String.format(
054 "Property constraint violation : " +
055 "%s allowed for property %s is %s but received value was %s",
056 constraintName,
057 featureName,
058 constraintValue,
059 featureValue));
060 this._constraintName = constraintName;
061 this._constraintValue = constraintValue;
062 this._featureName = featureName;
063 this._featureValue = featureValue;
064 }
065
066 /**
067 * Returns the value of the violating feature.
068 *
069 * @return the value of the violating feature.
070 */
071 public Object getFeatureValue ()
072 {
073 return _featureValue;
074 }
075
076 /**
077 * Returns the name of the violating feature.
078 *
079 * @return the name of the violating feature.
080 */
081 public String getFeatureName()
082 {
083 return _featureName;
084 }
085
086 /**
087 * Returns the value of the violated constraint.
088 *
089 * @return the value of the violated constraint.
090 */
091 public Number getConstraintValue ()
092 {
093 return _constraintValue;
094 }
095
096 /**
097 * Returns the name of the violated constraint.
098 *
099 * @return the name of the violated constraint.
100 */
101 public String getConstraintName ()
102 {
103 return _constraintName;
104 }
105 }
|