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.report.data;
17  
18  import org.apache.commons.lang.StringUtils;
19  
20  import de.smartics.properties.api.core.domain.DocumentMetaData;
21  import de.smartics.properties.api.core.domain.PropertyDescriptor;
22  
23  /**
24   * Report information for a particular property.
25   */
26  public final class PropertyReportItem
27  {
28    // ********************************* Fields *********************************
29  
30    // --- constants ------------------------------------------------------------
31  
32    // --- members --------------------------------------------------------------
33  
34    /**
35     * The descriptor to the property.
36     */
37    private final PropertyDescriptor descriptor;
38  
39    /**
40     * The Javadoc comment to the descriptor.
41     */
42    private final String comment;
43  
44    /**
45     * The documentation of the possible values to property.
46     */
47    private final ValueComment valueComment;
48  
49    /**
50     * The information about the source the property was defined in.
51     */
52    private final SourceInfo sourceInfo;
53  
54    /**
55     * The optional value in case this is a runtime report.
56     */
57    private Object value;
58  
59    // ****************************** Initializer *******************************
60  
61    // ****************************** Constructors ******************************
62  
63    private PropertyReportItem(final Builder builder)
64    {
65      this.descriptor = builder.descriptor;
66      this.comment = builder.comment;
67      this.valueComment = builder.valueComment;
68      this.sourceInfo = builder.sourceInfo;
69    }
70  
71    // ****************************** Inner Classes *****************************
72  
73    /**
74     * Builder to create instances of enclosing class.
75     */
76    public static final class Builder
77    {
78      // ******************************** Fields ********************************
79  
80      // --- constants ----------------------------------------------------------
81  
82      // --- members ------------------------------------------------------------
83  
84      /**
85       * The descriptor to the property.
86       */
87      private PropertyDescriptor descriptor;
88  
89      /**
90       * The Javadoc comment to the descriptor.
91       */
92      private String comment;
93  
94      /**
95       * The documentation of the possible values to property.
96       */
97      private ValueComment valueComment;
98  
99      /**
100      * The information about the source the property was defined in.
101      */
102     private SourceInfo sourceInfo;
103 
104     // ***************************** Initializer ******************************
105 
106     // ***************************** Constructors *****************************
107 
108     // ***************************** Inner Classes ****************************
109 
110     // ******************************** Methods *******************************
111 
112     // --- init ---------------------------------------------------------------
113 
114     // --- get&set ------------------------------------------------------------
115 
116     /**
117      * Sets the descriptor to the property.
118      *
119      * @param descriptor the descriptor to the property.
120      * @return a reference to the builder.
121      */
122     public Builder with(final PropertyDescriptor descriptor)
123     {
124       this.descriptor = descriptor;
125       return this;
126     }
127 
128     /**
129      * Sets the Javadoc comment to the descriptor.
130      *
131      * @param comment the Javadoc comment to the descriptor.
132      * @return a reference to the builder.
133      */
134     public Builder withComment(final String comment)
135     {
136       this.comment = comment;
137       return this;
138     }
139 
140     /**
141      * Sets the documentation of the possible values to property.
142      *
143      * @param valueComment the documentation of the possible values to property.
144      * @return a reference to the builder.
145      */
146     public Builder with(final ValueComment valueComment)
147     {
148       this.valueComment = valueComment;
149       return this;
150     }
151 
152     /**
153      * Sets the information about the source the property was defined in.
154      *
155      * @param sourceInfo the information about the source the property was
156      *          defined in.
157      * @return a reference to the builder.
158      */
159     public Builder with(final SourceInfo sourceInfo)
160     {
161       this.sourceInfo = sourceInfo;
162       return this;
163     }
164 
165     // --- business -----------------------------------------------------------
166 
167     /**
168      * Creates the report item.
169      *
170      * @return the report item.
171      */
172     public PropertyReportItem build()
173     {
174       if (valueComment == null)
175       {
176         valueComment = new ValueComment(null);
177       }
178       return new PropertyReportItem(this);
179     }
180 
181     // --- object basics ------------------------------------------------------
182   }
183 
184   // ********************************* Methods ********************************
185 
186   // --- init -----------------------------------------------------------------
187 
188   // --- get&set --------------------------------------------------------------
189 
190   /**
191    * Returns the descriptor to the property.
192    *
193    * @return the descriptor to the property.
194    */
195   public PropertyDescriptor getDescriptor()
196   {
197     return descriptor;
198   }
199 
200   /**
201    * Returns the Javadoc comment to the descriptor.
202    *
203    * @return the Javadoc comment to the descriptor.
204    */
205   public String getComment()
206   {
207     return comment;
208   }
209 
210   /**
211    * Returns the documentation of the possible values to property.
212    *
213    * @return the documentation of the possible values to property.
214    */
215   public ValueComment getValueComment()
216   {
217     return valueComment;
218   }
219 
220   /**
221    * Returns the information about the source the property was defined in.
222    *
223    * @return the information about the source the property was defined in.
224    */
225   public SourceInfo getSourceInfo()
226   {
227     return sourceInfo;
228   }
229 
230   /**
231    * Returns the document instance metadata.
232    *
233    * @return the document instance metadata.
234    */
235   public DocumentMetaData getMetaData()
236   {
237     return descriptor.getDocumentMetaData();
238   }
239 
240   /**
241    * Returns the optional value in case this is a runtime report.
242    *
243    * @return the optional value in case this is a runtime report.
244    */
245   public Object getValue()
246   {
247     return value;
248   }
249 
250   /**
251    * Sets the optional value in case this is a runtime report.
252    *
253    * @param value the optional value in case this is a runtime report.
254    */
255   public void setValue(final Object value)
256   {
257     this.value = value;
258   }
259 
260   /**
261    * Returns the name that uniquely identifies the property report within the
262    * report set.
263    *
264    * @return the name that uniquely identifies the property report within the
265    *         report set.
266    */
267   public String getLocalName()
268   {
269     final String metadataValue = descriptor.getDocumentMetaData().getName();
270     if (StringUtils.isBlank(metadataValue))
271     {
272       return descriptor.getKey().toString();
273     }
274 
275     return metadataValue;
276   }
277 
278   /**
279    * Returns the name that uniquely identifies the property report document.
280    *
281    * @return the name that uniquely identifies the property report document.
282    */
283   public String getName()
284   {
285     // final String set = getPropertySet();
286     final String name = getLocalName();
287     // final String id = set + '.' + name;
288     return name;
289   }
290 
291   /**
292    * Returns the space the report item belongs to.
293    *
294    * @return the space the report item belongs to.
295    */
296   public String getSpace()
297   {
298     final String metadataValue = descriptor.getDocumentMetaData().getSpace();
299     if (StringUtils.isBlank(metadataValue))
300     {
301       return "property:" + sourceInfo.getElementTypeName();
302     }
303 
304     return metadataValue;
305   }
306 
307   /**
308    * Returns the unique title of the report within the space.
309    *
310    * @return the unique title of the report within the space.
311    */
312   public String getTitle()
313   {
314     final String metadataValue = descriptor.getDocumentMetaData().getTitle();
315     if (StringUtils.isBlank(metadataValue))
316     {
317       return getLocalName();
318     }
319 
320     return metadataValue;
321   }
322 
323   /**
324    * Returns the set of properties this property belongs to.
325    *
326    * @return the set of properties this property belongs to.
327    */
328   public String getPropertySet()
329   {
330     final String descriptorValue = descriptor.getKey().getPropertySet();
331     if (StringUtils.isBlank(descriptorValue))
332     {
333       return sourceInfo.getElementTypeName();
334     }
335 
336     return descriptorValue;
337   }
338 
339   // --- business -------------------------------------------------------------
340 
341   // --- object basics --------------------------------------------------------
342 
343 }