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  /**
21   * Signals that a property descriptor has been encountered twice.
22   */
23  public class DuplicatePropertyDeclarationException extends PropertyException
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 previously encountered and currently active property.
41     *
42     * @serial
43     */
44    private final PropertyDescriptor currentDescriptor;
45  
46    /**
47     * The new encountered property descriptor with the same key.
48     *
49     * @serial
50     */
51    private final PropertyDescriptor newDescriptor;
52  
53    // ****************************** Initializer *******************************
54  
55    // ****************************** Constructors ******************************
56  
57    /**
58     * Constructor.
59     *
60     * @param currentDescriptor the previously encountered and currently active
61     *          property.
62     * @param newDescriptor the new encountered property descriptor with the same
63     *          key.
64     * @impl Since this is an exception we do not check that the key of the
65     *       current descriptor and that of the new descriptor matches. But these
66     *       two keys must be equal.
67     */
68    public DuplicatePropertyDeclarationException(
69        final PropertyDescriptor currentDescriptor,
70        final PropertyDescriptor newDescriptor)
71    {
72      super(createMessage(currentDescriptor, newDescriptor), currentDescriptor
73          .getKey());
74  
75      this.currentDescriptor = currentDescriptor;
76      this.newDescriptor = newDescriptor;
77    }
78  
79    // ****************************** Inner Classes *****************************
80  
81    // ********************************* Methods ********************************
82  
83    // --- init -----------------------------------------------------------------
84  
85    private static String createMessage(
86        final PropertyDescriptor currentDescriptor,
87        final PropertyDescriptor newDescriptor)
88    {
89      return String.format(
90          "Duplicate property declaration for key '%s'."
91              + " Active declaration of type '%s' crashes with a new"
92              + " declaration of type '%s'.", currentDescriptor.getKey(),
93          currentDescriptor.getDeclaringType(), newDescriptor.getDeclaringType());
94    }
95  
96    // --- get&set --------------------------------------------------------------
97  
98    /**
99     * Returns the previously encountered and currently active property.
100    *
101    * @return the previously encountered and currently active property.
102    */
103   public final PropertyDescriptor getCurrentDescriptor()
104   {
105     return currentDescriptor;
106   }
107 
108   /**
109    * Returns the new encountered property descriptor with the same key.
110    *
111    * @return the new encountered property descriptor with the same key.
112    */
113   public final PropertyDescriptor getNewDescriptor()
114   {
115     return newDescriptor;
116   }
117 
118   // --- business -------------------------------------------------------------
119 
120   // --- object basics --------------------------------------------------------
121 
122 }