View Javadoc

1   /*
2    * Copyright 2012-2013 smartics, Kronseder & Reiner GmbH
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package de.smartics.properties.api.config.domain;
17  
18  import de.smartics.properties.api.core.domain.PropertyValueConversionException;
19  
20  /**
21   * Signals that the value does not match the given constraints and provides
22   * information about the source location of the culprit.
23   */
24  public class PropertyValueConversionWithSourceException extends
25      PropertyValueConversionException
26  {
27    // ********************************* Fields *********************************
28  
29    // --- constants ------------------------------------------------------------
30  
31    /**
32     * The class version identifier.
33     * <p>
34     * The value of this constant is {@value}.
35     */
36    private static final long serialVersionUID = 1L;
37  
38    // --- members --------------------------------------------------------------
39  
40    /**
41     * The source where the property value has been defined.
42     *
43     * @serial
44     */
45    private final PropertyLocation source;
46  
47    // ****************************** Initializer *******************************
48  
49    // ****************************** Constructors ******************************
50  
51    /**
52     * Default constructor.
53     *
54     * @param original the original property validation exception without the
55     *          origin information.
56     * @param source the source where the property value has been defined.
57     */
58    public PropertyValueConversionWithSourceException(
59        final PropertyValueConversionException original,
60        final PropertyLocation source)
61    {
62      super(createMessage(original, source), original.getCause(), original
63          .getPropertyDescriptor(), original.getValue());
64      this.source = source;
65    }
66  
67    // ****************************** Inner Classes *****************************
68  
69    // ********************************* Methods ********************************
70  
71    // --- init -----------------------------------------------------------------
72  
73    private static String createMessage(
74        final PropertyValueConversionException original,
75        final PropertyLocation source)
76    {
77      final StringBuilder buffer = new StringBuilder(512);
78  
79      buffer.append(original.getMessage())
80          .append("\n    Source location of the property '")
81          .append(original.getPropertyDescriptor().getKey()).append('=')
82          .append(original.getValue()).append("': ").append(source);
83  
84      appendMetaDataMessage(buffer, original.getPropertyDescriptor());
85  
86      return buffer.toString();
87    }
88  
89    // --- get&set --------------------------------------------------------------
90  
91    /**
92     * Returns the source where the property value has been defined.
93     *
94     * @return the source where the property value has been defined.
95     */
96    public final PropertyLocation getSource()
97    {
98      return source;
99    }
100 
101   // --- business -------------------------------------------------------------
102 
103   // --- object basics --------------------------------------------------------
104 
105 }