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.config.domain;
17
18 import java.util.List;
19
20 /**
21 * A validated property provides, in addition to a {@link Property} also the
22 * resolved, converted, and validated value.
23 */
24 public final class ValidatedProperty extends DescribedProperty
25 {
26 // ********************************* Fields *********************************
27
28 // --- constants ------------------------------------------------------------
29
30 /**
31 * The class version identifier.
32 */
33 private static final long serialVersionUID = 1L;
34
35 // --- members --------------------------------------------------------------
36
37 /**
38 * The property expression. May be <code>null</code>. If the property value is
39 * <code>null</code>, the expression is checked for default values.
40 *
41 * @serial
42 */
43 private final String expression;
44
45 /**
46 * The validated value. The property value is resolved, converted, and
47 * validated to this value. May be <code>null</code>.
48 *
49 * @serial
50 */
51 private final Object validatedValue;
52
53 // ****************************** Initializer *******************************
54
55 // ****************************** Constructors ******************************
56
57 /**
58 * Default constructor.
59 *
60 * @param describedProperty provides the information to be copied.
61 * @param expression the property expression.
62 * @param validatedValue the validated value. The property value is resolved,
63 * converted, and validated to this value. May be <code>null</code>.
64 */
65 public ValidatedProperty(final DescribedProperty describedProperty,
66 final String expression, final Object validatedValue)
67 {
68 super(describedProperty);
69
70 this.expression = expression;
71 this.validatedValue = validatedValue;
72 }
73
74 // ****************************** Inner Classes *****************************
75
76 // ********************************* Methods ********************************
77
78 // --- init -----------------------------------------------------------------
79
80 // --- get&set --------------------------------------------------------------
81
82 /**
83 * Returns the validated value. The property value is resolved, converted, and
84 * validated to this value.
85 *
86 * @return the validated value. May be <code>null</code>.
87 */
88 public Object getValidatedValue()
89 {
90 return validatedValue;
91 }
92
93 // --- business -------------------------------------------------------------
94
95 /**
96 * Returns the names of properties this property depends on. May be
97 * <code>null</code>, if this property does not refer to other properties.
98 *
99 * @return the names of properties this property depends on.
100 */
101 public List<String> getDependencies()
102 {
103 final DependenciesParser parser = new DependenciesParser();
104 final String value = getValue();
105 final String expression = value != null ? value : this.expression;
106 final List<String> dependencies = parser.getDependencies(expression);
107 return dependencies;
108 }
109
110 // --- object basics --------------------------------------------------------
111
112 @Override
113 public String toString()
114 {
115 return super.toString() + ": " + validatedValue;
116 }
117 }