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.core.domain;
17  
18  
19  /**
20   * Signals that the value cannot be resolve. Therefore the expression contains
21   * unresolved place holders.
22   */
23  public class PropertyValueResolveException extends PropertyDescriptorException
24  {
25    // ********************************* Fields *********************************
26  
27    // --- constants ------------------------------------------------------------
28  
29    /**
30     * The class version identifier.
31     * <p>
32     * The value of this constant is {@value}.
33     * </p>
34     */
35    private static final long serialVersionUID = 1L;
36  
37    // --- members --------------------------------------------------------------
38  
39    /**
40     * The expression that failed to be resolved.
41     *
42     * @serial
43     */
44    private final String expression;
45  
46    // ****************************** Initializer *******************************
47  
48    // ****************************** Constructors ******************************
49  
50    /**
51     * Convenience constructor with no cause.
52     *
53     * @param propertyDescriptor the key descriptor the property raising the
54     *          exception.
55     * @param expression the expression that failed to be resolved.
56     */
57    public PropertyValueResolveException(
58        final PropertyDescriptor propertyDescriptor, final String expression)
59    {
60      this(null, propertyDescriptor, 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 propertyDescriptor the descriptor of the property raising the
70     *          exception.
71     * @param expression the expression that failed to be resolved.
72     */
73    public PropertyValueResolveException(final Throwable cause,
74        final PropertyDescriptor propertyDescriptor, final String expression)
75    {
76      this(createMessage(cause, propertyDescriptor, expression), cause,
77          propertyDescriptor, expression);
78    }
79  
80    /**
81     * Internal constructor to provide a custom message.
82     *
83     * @param message the detail message (which is saved for later retrieval by
84     *          the {@link #getMessage()} method).
85     * @param cause the cause (which is saved for later retrieval by the
86     *          {@link #getCause()} method). (A <tt>null</tt> value is permitted,
87     *          and indicates that the cause is nonexistent or unknown.)
88     * @param propertyDescriptor the descriptor of the property raising the
89     *          exception.
90     * @param expression the expression that failed to be resolved.
91     */
92    protected PropertyValueResolveException(final String message,
93        final Throwable cause, final PropertyDescriptor propertyDescriptor,
94        final String expression)
95    {
96      super(message, cause, propertyDescriptor);
97  
98      this.expression = expression;
99    }
100 
101   // ****************************** Inner Classes *****************************
102 
103   // ********************************* Methods ********************************
104 
105   // --- init -----------------------------------------------------------------
106 
107   private static String createMessage(final Throwable cause,
108       final PropertyDescriptor propertyDescriptor, final String expression)
109   {
110     return String.format(
111         "For property '%s' the expression '%s' cannot be resolved.%s",
112         propertyDescriptor.getKey(),
113         expression,
114         cause instanceof PropertyValueResolveException ? " Due to: "
115                                                          + cause.getMessage()
116             : "");
117   }
118 
119   // --- get&set --------------------------------------------------------------
120 
121   /**
122    * Returns the expression that failed to be resolved.
123    *
124    * @return the expression that failed to be resolved.
125    */
126   public final String getExpression()
127   {
128     return expression;
129   }
130 
131   // --- business -------------------------------------------------------------
132 
133   // --- object basics --------------------------------------------------------
134 
135 }