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