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.util.List;
19  import java.util.Locale;
20  
21  import de.smartics.exceptions.i18n.message.MessageParam;
22  import de.smartics.properties.api.core.annotations.AccessType;
23  import de.smartics.properties.api.core.annotations.PropertyDefinitionTime;
24  import de.smartics.properties.api.core.annotations.PropertyUse.UseType;
25  import de.smartics.properties.api.core.app.PropertiesCode;
26  
27  /**
28   * Provides context information for errors concerning a property.
29   */
30  public class PropertyDescriptorMessageBean extends PropertyMessageBean
31  {
32    // ********************************* Fields *********************************
33  
34    // --- constants ------------------------------------------------------------
35  
36    /**
37     * The class version identifier.
38     * <p>
39     * The value of this constant is {@value}.
40     * </p>
41     */
42    private static final long serialVersionUID = 1L;
43  
44    // --- members --------------------------------------------------------------
45  
46    /**
47     * The descriptor of the property raising the exception.
48     *
49     * @serial
50     */
51    @MessageParam("propertyDescriptorDeclaringType:declaringType,propertyKey:key")
52    private final PropertyDescriptor propertyDescriptor;
53  
54    // ****************************** Initializer *******************************
55  
56    // ****************************** Constructors ******************************
57  
58    /**
59     * Default constructor.
60     *
61     * @param code the error or exception code of the exception.
62     * @param cause the cause to the problem.
63     * @param propertyDescriptor the descriptor of the property raising the
64     *          exception.
65     */
66    public PropertyDescriptorMessageBean(final PropertiesCode code,
67        final Throwable cause, final PropertyDescriptor propertyDescriptor)
68    {
69      super(code, cause, provide(propertyDescriptor).getKey());
70      this.propertyDescriptor = provide(propertyDescriptor);
71    }
72  
73    // ****************************** Inner Classes *****************************
74  
75    /**
76     * Null object for rendering.
77     */
78    private static final class DefaultPropertyDescriptor implements
79        PropertyDescriptor
80    {
81      /**
82       * The class version identifier.
83       * <p>
84       * The value of this constant is {@value}.
85       * </p>
86       */
87      private static final long serialVersionUID = 1L;
88  
89      @Override
90      public PropertyContext getContext()
91      {
92        return null;
93      }
94  
95      @Override
96      public Class<?> getDeclaringType()
97      {
98        return Void.class;
99      }
100 
101     @Override
102     public PropertyKey getKey()
103     {
104       return new PropertyKey("n/a");
105     }
106 
107     @Override
108     public PropertyType getType()
109     {
110       return null;
111     }
112 
113     @Override
114     public boolean isMandatory()
115     {
116       return false;
117     }
118 
119     @Override
120     public boolean isSecured()
121     {
122       return false;
123     }
124 
125     @Override
126     public AccessType getAccessType()
127     {
128       return null;
129     }
130 
131     @Override
132     public boolean isRuntimeMutable()
133     {
134       return false;
135     }
136 
137     @Override
138     public long getUpdateIntervalInMs()
139     {
140       return 0;
141     }
142 
143     @Override
144     public PropertyDefinitionTime getConfigurationTime()
145     {
146       return null;
147     }
148 
149     @Override
150     public PropertyExpression getDefaultExpression()
151     {
152       return null;
153     }
154 
155     @Override
156     public PropertyValueRange<?> getValueRange()
157     {
158       return null;
159     }
160 
161     @Override
162     public List<? extends PropertyConstraint<?>> getConstraints()
163     {
164       return null;
165     }
166 
167     @Override
168     public DocumentName getDocumentName()
169     {
170       return null;
171     }
172 
173     @Override
174     public PropertyProjectdoc getDocumentMetaData()
175     {
176       return null;
177     }
178 
179     @Override
180     public PropertyProjectdoc getDocumentMetaData(final Locale locale)
181     {
182       return null;
183     }
184 
185     @Override
186     public PropertySetProjectdoc getDocumentMetaDataProjectSet()
187     {
188       return null;
189     }
190 
191     @Override
192     public PropertySetProjectdoc getDocumentMetaDataProjectSet(
193         final Locale locale)
194     {
195       return null;
196     }
197 
198     @Override
199     public PropertyComment getComment()
200     {
201       return null;
202     }
203 
204     @Override
205     public PropertyComment getComment(final Locale locale)
206     {
207       return null;
208     }
209 
210     @Override
211     public PropertyCategories getCategories()
212     {
213       return null;
214     }
215 
216     @Override
217     public UseType getUseType()
218     {
219       return null;
220     }
221   }
222 
223   // ********************************* Methods ********************************
224 
225   // --- init -----------------------------------------------------------------
226 
227   private static PropertyDescriptor provide(
228       final PropertyDescriptor propertyDescriptor)
229   {
230     return propertyDescriptor != null ? propertyDescriptor
231         : new DefaultPropertyDescriptor();
232   }
233 
234   // --- get&set --------------------------------------------------------------
235 
236   /**
237    * Returns the descriptor of the property raising the exception.
238    *
239    * @return the descriptor of the property raising the exception.
240    */
241   public final PropertyDescriptor getPropertyDescriptor()
242   {
243     return propertyDescriptor;
244   }
245 
246   // --- business -------------------------------------------------------------
247 
248   // --- object basics --------------------------------------------------------
249 
250 }