1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package de.smartics.properties.spi.core.metadata;
17
18 import static de.smartics.util.lang.StaticAnalysis.UNCHECKED;
19
20 import java.util.ArrayList;
21 import java.util.List;
22 import java.util.Locale;
23
24 import org.apache.commons.lang.builder.ToStringBuilder;
25
26 import de.smartics.properties.api.core.annotations.AccessType;
27 import de.smartics.properties.api.core.annotations.PropertyDefinitionTime;
28 import de.smartics.properties.api.core.annotations.PropertyUse.UseType;
29 import de.smartics.properties.api.core.domain.DocumentName;
30 import de.smartics.properties.api.core.domain.PropertyCategories;
31 import de.smartics.properties.api.core.domain.PropertyComment;
32 import de.smartics.properties.api.core.domain.PropertyConstraint;
33 import de.smartics.properties.api.core.domain.PropertyContext;
34 import de.smartics.properties.api.core.domain.PropertyDescriptor;
35 import de.smartics.properties.api.core.domain.PropertyExpression;
36 import de.smartics.properties.api.core.domain.PropertyKey;
37 import de.smartics.properties.api.core.domain.PropertyProjectdoc;
38 import de.smartics.properties.api.core.domain.PropertySetProjectdoc;
39 import de.smartics.properties.api.core.domain.PropertyType;
40 import de.smartics.properties.api.core.domain.PropertyValueRange;
41 import de.smartics.properties.spi.core.context.PropertyContextProvider;
42 import de.smartics.util.lang.Arg;
43
44
45
46
47
48 public final class PropertyMetaData implements PropertyDescriptor
49 {
50
51
52
53
54
55
56
57 private static final long serialVersionUID = 1L;
58
59
60
61
62
63
64
65
66 private final PropertyContextProvider contextProxy;
67
68
69
70
71
72
73 private final Class<?> declaringType;
74
75
76
77
78
79
80 private final PropertyKey key;
81
82
83
84
85
86
87 private final PropertyType type;
88
89
90
91
92
93
94
95
96 private final boolean mandatory;
97
98
99
100
101
102
103
104 private final boolean secured;
105
106
107
108
109 private final AccessType accessType;
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139 private final long updateIntervalInMs;
140
141
142
143
144
145
146 private final PropertyDefinitionTime configurationTime;
147
148
149
150
151
152
153
154 private final PropertyExpression defaultExpression;
155
156
157
158
159
160
161 private final PropertyValueRange<?> valueRange;
162
163
164
165
166
167
168
169 private final List<? extends PropertyConstraint<?>> constraints;
170
171
172
173
174
175
176 private final DocumentMetaDataProxy documentMetaDataProxy;
177
178
179
180
181
182
183 private final PropertyCommentProvider commentProxy;
184
185
186
187
188
189
190 private final PropertyCategories categories;
191
192
193
194
195
196
197 private final UseType useType;
198
199
200
201
202
203 @SuppressWarnings(UNCHECKED)
204 private PropertyMetaData(final Builder builder)
205 {
206 this.contextProxy = builder.context;
207 this.declaringType = builder.declaringType;
208 this.key = builder.key;
209 this.type = builder.type;
210
211 this.mandatory = builder.mandatory;
212 this.secured = builder.secured;
213 this.accessType = builder.accessType;
214 this.updateIntervalInMs = builder.updateIntervalInMs;
215 this.configurationTime = builder.configurationTime;
216
217 this.defaultExpression = builder.defaultExpression;
218 this.valueRange = builder.valueRange;
219 this.constraints = builder.constraints;
220
221 this.documentMetaDataProxy = builder.documentMetaDataProxy;
222 this.commentProxy = builder.commentProxy;
223 this.categories = builder.categories;
224 this.useType = builder.useType;
225 }
226
227
228
229
230
231
232 public static final class Builder
233 {
234
235
236
237
238
239
240
241
242
243 private PropertyContextProvider context;
244
245
246
247
248 private Class<?> declaringType;
249
250
251
252
253 private PropertyKey key;
254
255
256
257
258 private PropertyType type;
259
260
261
262
263
264
265 private boolean mandatory;
266
267
268
269
270
271 private boolean secured;
272
273
274
275
276
277
278
279
280
281 private AccessType accessType = AccessType.READ_ONLY;
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314 private long updateIntervalInMs = -1;
315
316
317
318
319
320
321
322
323
324 private PropertyDefinitionTime configurationTime =
325 PropertyDefinitionTime.STARTUP;
326
327
328
329
330
331 private PropertyExpression defaultExpression =
332 PropertyExpression.NO_EXPRESSION;
333
334
335
336
337 private PropertyValueRange<?> valueRange;
338
339
340
341
342
343 @SuppressWarnings("rawtypes")
344 private final List constraints = new ArrayList<PropertyConstraint<?>>();
345
346
347
348
349 private DocumentMetaDataProxy documentMetaDataProxy;
350
351
352
353
354 private PropertyCommentProvider commentProxy;
355
356
357
358
359 private PropertyCategories categories;
360
361
362
363
364 private UseType useType;
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384 public PropertyKey getKey()
385 {
386 return key;
387 }
388
389
390
391
392
393
394
395 public PropertyType getType()
396 {
397 return type;
398 }
399
400
401
402
403
404
405
406
407
408
409 public Builder with(final PropertyContextProvider context)
410 throws NullPointerException
411 {
412 this.context = Arg.checkNotNull("context", context);
413 return this;
414 }
415
416
417
418
419
420
421
422
423 public void setSecured(final boolean secured)
424 {
425 this.secured = secured;
426 }
427
428
429
430
431
432
433
434
435
436
437
438 public Builder withDeclaringType(final Class<?> declaringType)
439 throws NullPointerException
440 {
441 this.declaringType = Arg.checkNotNull("declaringType", declaringType);
442 return this;
443 }
444
445
446
447
448
449
450
451
452 public Builder with(final PropertyKey key) throws NullPointerException
453 {
454 this.key = Arg.checkNotNull("key", key);
455 return this;
456 }
457
458
459
460
461
462
463
464
465 public Builder with(final PropertyType type) throws NullPointerException
466 {
467 this.type = Arg.checkNotNull("type", type);
468 return this;
469 }
470
471
472
473
474
475
476
477
478 public Builder with(final AccessType accessType)
479 throws NullPointerException
480 {
481 this.accessType = Arg.checkNotNull("accessType", accessType);
482 return this;
483 }
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514 public Builder withUpdateIntervalInMs(final long updateIntervalInMs)
515 {
516 this.updateIntervalInMs = updateIntervalInMs;
517 return this;
518 }
519
520
521
522
523
524
525
526
527
528 public Builder with(final PropertyDefinitionTime configurationTime)
529 throws NullPointerException
530 {
531 this.configurationTime =
532 Arg.checkNotNull("configurationTime", configurationTime);
533 return this;
534 }
535
536
537
538
539
540
541
542
543
544
545
546 public Builder with(final PropertyExpression defaultExpression)
547 throws NullPointerException
548 {
549 this.defaultExpression =
550 Arg.checkNotNull("defaultExpression", defaultExpression);
551 return this;
552 }
553
554
555
556
557
558
559
560 public Builder with(final PropertyValueRange<?> valueRange)
561 {
562 this.valueRange = valueRange;
563 return this;
564 }
565
566
567
568
569
570
571
572
573
574 public Builder with(final DocumentMetaDataProxy documentMetaData)
575 throws NullPointerException
576 {
577 this.documentMetaDataProxy =
578 Arg.checkNotNull("documentMetaData", documentMetaData);
579 return this;
580 }
581
582
583
584
585
586
587
588
589
590 public Builder with(final PropertyCommentProvider commentProxy)
591 throws NullPointerException
592 {
593 this.commentProxy = Arg.checkNotNull("commentProxy", commentProxy);
594 return this;
595 }
596
597
598
599
600
601
602
603 @SuppressWarnings(UNCHECKED)
604 public void add(final PropertyConstraint<?> constraint)
605 throws NullPointerException
606 {
607 Arg.checkNotNull("constraint", constraint);
608 this.constraints.add(constraint);
609 }
610
611
612
613
614
615
616
617
618 public Builder with(final PropertyCategories categories)
619 throws NullPointerException
620 {
621 this.categories = Arg.checkNotNull("categories", categories);
622 return this;
623 }
624
625
626
627
628
629
630
631
632 public Builder with(final UseType useType) throws NullPointerException
633 {
634 this.useType = Arg.checkNotNull("useType", useType);
635 return this;
636 }
637
638
639
640
641
642
643
644 @SuppressWarnings(UNCHECKED)
645 public PropertyMetaData build() throws NullPointerException
646 {
647 Arg.checkNotNull("context", context);
648 Arg.checkNotNull("declaringType", declaringType);
649 Arg.checkNotNull("key", key);
650 Arg.checkNotNull("type", type);
651 Arg.checkNotNull("accessType", accessType);
652 Arg.checkNotNull("configurationTime", configurationTime);
653 Arg.checkNotNull("defaultExpression", defaultExpression);
654 Arg.checkNotNull("constraints", constraints);
655 Arg.checkNotNull("documentMetaData", documentMetaDataProxy);
656 Arg.checkNotNull("commentProxy", commentProxy);
657
658 mandatory = containsMandatoryConstaint(constraints);
659
660 if (categories == null)
661 {
662 categories = new PropertyCategories.Builder().build();
663 }
664 if (useType == null)
665 {
666 useType = UseType.CONFIGURATION;
667 }
668
669 return new PropertyMetaData(this);
670 }
671
672 private static boolean containsMandatoryConstaint(
673 final List<? extends PropertyConstraint<?>> constraints)
674 {
675 for (final PropertyConstraint<?> constraint : constraints)
676 {
677 if (constraint.isMandatoryConstraint())
678 {
679 return true;
680 }
681 }
682 return false;
683 }
684
685
686 }
687
688
689
690
691
692
693
694 @Override
695 public PropertyContext getContext()
696 {
697 return contextProxy.getPropertyContext(this);
698 }
699
700 @Override
701 public Class<?> getDeclaringType()
702 {
703 return declaringType;
704 }
705
706 @Override
707 public PropertyKey getKey()
708 {
709 return key;
710 }
711
712 @Override
713 public PropertyType getType()
714 {
715 return type;
716 }
717
718 @Override
719 public boolean isMandatory()
720 {
721 return mandatory;
722 }
723
724
725
726
727
728
729
730
731 @Override
732 public boolean isSecured()
733 {
734 return secured;
735 }
736
737 @Override
738 public AccessType getAccessType()
739 {
740 return accessType;
741 }
742
743 @Override
744 public boolean isRuntimeMutable()
745 {
746 return accessType == AccessType.READ_WRITE;
747 }
748
749 @Override
750 public long getUpdateIntervalInMs()
751 {
752 return updateIntervalInMs;
753 }
754
755 @Override
756 public PropertyDefinitionTime getConfigurationTime()
757 {
758 return configurationTime;
759 }
760
761 @Override
762 public PropertyExpression getDefaultExpression()
763 {
764 return defaultExpression;
765 }
766
767 @Override
768 public PropertyValueRange<?> getValueRange()
769 {
770 return valueRange;
771 }
772
773 @Override
774 public List<? extends PropertyConstraint<?>> getConstraints()
775 {
776 return constraints;
777 }
778
779 @Override
780 public DocumentName getDocumentName()
781 {
782 return documentMetaDataProxy.getDocumentName();
783 }
784
785 @Override
786 public PropertyProjectdoc getDocumentMetaData()
787 {
788 return getDocumentMetaData(null);
789 }
790
791 @Override
792 public PropertyProjectdoc getDocumentMetaData(final Locale locale)
793 {
794 return documentMetaDataProxy.getProjectdocProperty(this, locale);
795 }
796
797 @Override
798 public PropertySetProjectdoc getDocumentMetaDataProjectSet()
799 {
800 return getDocumentMetaDataProjectSet(null);
801 }
802
803 @Override
804 public PropertySetProjectdoc getDocumentMetaDataProjectSet(final Locale locale)
805 {
806 return documentMetaDataProxy.getProjectdocPropertySet(this, locale);
807 }
808
809 @Override
810 public PropertyComment getComment()
811 {
812 return getComment(null);
813 }
814
815 @Override
816 public PropertyComment getComment(final Locale locale)
817 {
818 return commentProxy.getComment(this, locale);
819 }
820
821 @Override
822 public PropertyCategories getCategories()
823 {
824 return categories;
825 }
826
827
828
829
830
831
832 @Override
833 public UseType getUseType()
834 {
835 return useType;
836 }
837
838
839
840
841
842
843
844
845
846
847 @Override
848 public String toString()
849 {
850 return ToStringBuilder.reflectionToString(this);
851 }
852 }