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.PropertyValueResolveException;
19  
20  /**
21   * Signals that the value cannot be resolve and provides information about the
22   * source location of the culprit. Therefore the expression contains unresolved
23   * placeholders.
24   */
25  public class PropertyValueResolveWithSourceException extends
26      PropertyValueResolveException
27  {
28    // ********************************* Fields *********************************
29  
30    // --- constants ------------------------------------------------------------
31  
32    /**
33     * The class version identifier.
34     * <p>
35     * The value of this constant is {@value}.
36     */
37    private static final long serialVersionUID = 1L;
38  
39    // --- members --------------------------------------------------------------
40  
41    /**
42     * The source where the property value has been defined.
43     *
44     * @serial
45     */
46    private final PropertyLocation source;
47  
48    // ****************************** Initializer *******************************
49  
50    // ****************************** Constructors ******************************
51  
52    /**
53     * Default constructor.
54     *
55     * @param original the original property validation exception without the
56     *          origin information.
57     * @param source the source where the property value has been defined.
58     */
59    public PropertyValueResolveWithSourceException(
60        final PropertyValueResolveException original,
61        final PropertyLocation source)
62    {
63      super(createMessage(original, source), original.getCause(), original
64          .getPropertyDescriptor(), original.getExpression());
65      this.source = source;
66    }
67  
68    // ****************************** Inner Classes *****************************
69  
70    // ********************************* Methods ********************************
71  
72    // --- init -----------------------------------------------------------------
73  
74    private static String createMessage(
75        final PropertyValueResolveException original, 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.getExpression()).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 }