1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package de.smartics.properties.admin.domain.service;
17
18 import java.io.Serializable;
19 import java.util.Collection;
20
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
23
24 import de.smartics.properties.api.config.app.ConfigurationPropertiesFactoryFactory;
25 import de.smartics.properties.api.config.domain.ConfigurationPropertiesManagement;
26 import de.smartics.properties.api.config.domain.ConfigurationValidationException;
27 import de.smartics.properties.api.config.domain.key.ConfigurationKey;
28 import de.smartics.properties.impl.config.ds.DataSourceConfiguration;
29 import de.smartics.properties.impl.config.resource.AutodetectDataSourceResourceConfigurationPropertiesFactory;
30 import de.smartics.properties.resource.domain.ArtifactId;
31 import de.smartics.properties.spi.config.support.ConfigurationPropertiesManagementFactory;
32 import de.smartics.util.lang.Arg;
33
34
35
36
37 public class ConfigurationService implements Serializable
38 {
39
40
41
42
43
44
45
46
47
48
49 private static final long serialVersionUID = 1L;
50
51
52
53
54 private static final Logger LOG = LoggerFactory
55 .getLogger(ConfigurationService.class);
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88 public RemoteConfigurationPropertiesManagementFactory createFactory(
89 final ArtifactId applicationId,
90 final DataSourceConfiguration dataSourceConfig)
91 throws NullPointerException
92 {
93 Arg.checkNotNull("applicationId", applicationId);
94
95 final ConfigurationPropertiesManagementFactory factory;
96 if (dataSourceConfig != null)
97 {
98 factory =
99 new AutodetectDataSourceResourceConfigurationPropertiesFactory(
100 dataSourceConfig);
101 }
102 else
103 {
104 factory =
105 (ConfigurationPropertiesManagementFactory) ConfigurationPropertiesFactoryFactory
106 .createDefaultFactory();
107 }
108 final String remoteUrl = factory.addRootUrls(applicationId);
109
110 final Collection<ConfigurationKey<?>> keys = factory.materialize();
111 logKeysFound(keys);
112
113 return new RemoteConfigurationPropertiesManagementFactory(factory,
114 remoteUrl);
115 }
116
117 private static void logKeysFound(final Collection<ConfigurationKey<?>> keys)
118 {
119 if (LOG.isDebugEnabled())
120 {
121 final StringBuilder buffer = new StringBuilder();
122
123 for (final ConfigurationKey<?> key : keys)
124 {
125 buffer.append(' ').append(key);
126 }
127
128 LOG.debug("Found the following configurations:{}", buffer.toString());
129 }
130 }
131
132
133
134
135
136
137
138
139
140
141
142
143 public void validate(final ConfigurationPropertiesManagementFactory factory,
144 final ConfigurationKey<?> key, final boolean lenient)
145 throws NullPointerException, ConfigurationValidationException
146 {
147 final ConfigurationPropertiesManagement config =
148 Arg.checkNotNull("factory", factory).create(key);
149 config.validate(lenient);
150 }
151
152
153
154 }