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.spi.config.resolve;
17
18 import de.smartics.properties.api.config.domain.ConfigurationException;
19 import de.smartics.properties.api.config.domain.key.ConfigurationKey;
20
21 /**
22 * Signals problems resolving expression in a property value.
23 */
24 public class ResolveConfigurationException extends ConfigurationException
25 {
26 // ********************************* Fields *********************************
27
28 // --- constants ------------------------------------------------------------
29
30 /**
31 * The class version identifier.
32 * <p>
33 * The value of this constant is {@value}.
34 * </p>
35 */
36 private static final long serialVersionUID = 1L;
37
38 // --- members --------------------------------------------------------------
39
40 /**
41 * The expression that cannot be resolved.
42 *
43 * @serial
44 */
45 private final String expression;
46
47 // ****************************** Initializer *******************************
48
49 // ****************************** Constructors ******************************
50
51 /**
52 * Convenience constructor without a root cause.
53 *
54 * @param key the key to the configuration that signaled problems.
55 * @param expression the expression that cannot be resolved.
56 */
57 public ResolveConfigurationException(final ConfigurationKey key,
58 final String expression)
59 {
60 this(null, key, expression);
61 }
62
63 /**
64 * Default constructor.
65 *
66 * @param cause the cause (which is saved for later retrieval by the
67 * {@link #getCause()} method). (A <tt>null</tt> value is permitted,
68 * and indicates that the cause is nonexistent or unknown.)
69 * @param key the key to the configuration that signaled problems.
70 * @param expression the expression that cannot be resolved.
71 */
72 public ResolveConfigurationException(final Throwable cause,
73 final ConfigurationKey key, final String expression)
74 {
75 super(createMessage(key, expression), cause, key);
76 this.expression = expression;
77 }
78
79 // ****************************** Inner Classes *****************************
80
81 // ********************************* Methods ********************************
82
83 // --- init -----------------------------------------------------------------
84
85 // --- get&set --------------------------------------------------------------
86
87 private static String createMessage(final ConfigurationKey key,
88 final String expression)
89 {
90 return String.format(
91 "In configuration '%s' the expression '%s' cannot be resolved.", key,
92 expression);
93 }
94
95 /**
96 * Returns the expression that cannot be resolved.
97 *
98 * @return the expression that cannot be resolved.
99 */
100 public final String getExpression()
101 {
102 return expression;
103 }
104
105 // --- business -------------------------------------------------------------
106
107 // --- object basics --------------------------------------------------------
108
109 }