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