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  import java.io.Serializable;
19  
20  import de.smartics.exceptions.i18n.message.MessageParam;
21  
22  /**
23   * Provides context information for errors concerning a failed change of a
24   * property value.
25   */
26  public class PropertyValueChangeMessageBean extends
27      PropertyDescriptorMessageBean
28  {
29    // ********************************* Fields *********************************
30  
31    // --- constants ------------------------------------------------------------
32  
33    /**
34     * The class version identifier.
35     */
36    private static final long serialVersionUID = 1L;
37  
38    // --- members --------------------------------------------------------------
39  
40    /**
41     * The current value of the property that has not been changed.
42     *
43     * @serial
44     */
45    @MessageParam
46    private final Serializable currentValue;
47  
48    /**
49     * The value the property was requested to change to but has been rejected.
50     *
51     * @serial
52     */
53    @MessageParam
54    private final Serializable rejectedValue;
55  
56    // ****************************** Initializer *******************************
57  
58    // ****************************** Constructors ******************************
59  
60    /**
61     * Default constructor.
62     *
63     * @param code the error or exception code of the exception.
64     * @param propertyDescriptor the descriptor of the property raising the
65     *          exception.
66     * @param currentValue the current value of the property that has not been
67     *          changed.
68     * @param rejectedValue the value the property was requested to change to but
69     *          has been rejected.
70     */
71    public PropertyValueChangeMessageBean(final PropertyCode code,
72        final PropertyDescriptor propertyDescriptor, final Object currentValue,
73        final Object rejectedValue)
74    {
75      super(code, null, propertyDescriptor);
76  
77      this.currentValue = makeSerializable(currentValue);
78      this.rejectedValue = makeSerializable(rejectedValue);
79    }
80  
81    // ****************************** Inner Classes *****************************
82  
83    // ********************************* Methods ********************************
84  
85    // --- init -----------------------------------------------------------------
86  
87    private static Serializable makeSerializable(final Object value)
88    {
89      return value instanceof Serializable ? (Serializable) value : String
90          .valueOf(value);
91    }
92  
93    // --- get&set --------------------------------------------------------------
94  
95    /**
96     * Returns the current value of the property that has not been changed.
97     *
98     * @return the current value of the property that has not been changed.
99     */
100   public final Serializable getCurrentValue()
101   {
102     return currentValue;
103   }
104 
105   /**
106    * Returns the value the property was requested to change to but has been
107    * rejected.
108    *
109    * @return the value the property was requested to change to but has been
110    *         rejected.
111    */
112   public final Serializable getRejectedValue()
113   {
114     return rejectedValue;
115   }
116 
117   // --- business -------------------------------------------------------------
118 
119   // --- object basics --------------------------------------------------------
120 
121 }