1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package de.smartics.properties.spi.config.support;
17
18 import java.util.Properties;
19
20 import javax.annotation.concurrent.NotThreadSafe;
21
22 import de.smartics.properties.api.config.domain.Property;
23 import de.smartics.properties.api.config.domain.PropertyCollection;
24 import de.smartics.properties.api.config.domain.PropertyLocation;
25 import de.smartics.properties.api.config.domain.PropertyProvider;
26 import de.smartics.properties.api.config.domain.key.ConfigurationKey;
27 import de.smartics.util.lang.Arguments;
28
29
30
31
32
33 @NotThreadSafe
34 public final class PropertiesPropertyProvider implements PropertyProvider
35 {
36
37
38
39
40
41
42
43
44
45 private static final long serialVersionUID = 1L;
46
47
48
49
50
51
52
53
54 private final ConfigurationKey configurationKey;
55
56
57
58
59
60
61 private final PropertyLocation sourceId;
62
63
64
65
66
67
68 private final Properties properties;
69
70
71
72
73
74
75
76
77
78
79
80
81 public PropertiesPropertyProvider(final ConfigurationKey configurationKey,
82 final PropertyLocation sourceId, final Properties properties)
83 throws NullPointerException
84 {
85 Arguments.checkNotNull("configurationKey", configurationKey);
86 Arguments.checkNotNull("sourceId", sourceId);
87 Arguments.checkNotNull("properties", properties);
88
89 this.configurationKey = configurationKey;
90 this.sourceId = sourceId;
91 this.properties = properties;
92 }
93
94
95
96
97
98
99
100
101
102
103
104
105
106 @Override
107 public ConfigurationKey getConfigurationKey()
108 {
109 return configurationKey;
110 }
111
112 @Override
113 public PropertyLocation getSourceId()
114 {
115 return sourceId;
116 }
117
118
119
120 @Override
121 public Property getProperty(final String name) throws NullPointerException,
122 IllegalArgumentException
123 {
124 Arguments.checkNotNull("name", name);
125 final String value = properties.getProperty(name);
126 final Property property = new Property(sourceId, name, value);
127 return property;
128 }
129
130 @Override
131 public PropertyCollection getProperties()
132 {
133 return new PropertiesPropertyCollection(properties);
134 }
135
136 @Override
137 public boolean containsKey(final String name) throws NullPointerException
138 {
139 Arguments.checkNotNull("name", name);
140 return properties.containsKey(name);
141 }
142
143
144
145
146
147
148
149
150 @Override
151 public String toString()
152 {
153 final StringBuilder buffer = new StringBuilder();
154
155 buffer.append(sourceId).append('=').append(properties);
156
157 return buffer.toString();
158 }
159 }