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.ArrayList; |
19 |
|
import java.util.List; |
20 |
|
|
21 |
|
import de.smartics.properties.api.config.domain.key.ApplicationId; |
22 |
|
import de.smartics.properties.api.config.domain.key.ConfigurationKey; |
23 |
|
import de.smartics.properties.api.config.domain.key.EnvironmentId; |
24 |
|
import de.smartics.util.lang.NullArgumentException; |
25 |
|
|
26 |
|
|
27 |
|
|
28 |
|
|
29 |
|
class KeySetBuilder |
30 |
|
{ |
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
|
35 |
|
|
36 |
|
|
37 |
|
|
38 |
|
|
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
public KeySetBuilder() |
45 |
0 |
{ |
46 |
0 |
} |
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
|
56 |
|
|
57 |
|
|
58 |
|
public List<ConfigurationKey> createKeySet(final ConfigurationKey key) |
59 |
|
{ |
60 |
0 |
final List<ConfigurationKey> list = new ArrayList<ConfigurationKey>(); |
61 |
0 |
list.add(key); |
62 |
|
|
63 |
0 |
final EnvironmentId envId = key.getEnvironmentId(); |
64 |
0 |
final ApplicationId appId = key.getApplicationId(); |
65 |
|
|
66 |
0 |
addAppKeys(list, envId, appId); |
67 |
|
|
68 |
0 |
if (envId.getNode() != null) |
69 |
|
{ |
70 |
0 |
final EnvironmentId defaultEnv = new EnvironmentId(envId.getName()); |
71 |
0 |
if (!ApplicationId.ANY_APP.equals(appId)) |
72 |
|
{ |
73 |
0 |
if (appId.getVersion() != null) |
74 |
|
{ |
75 |
0 |
final ConfigurationKey defaultKey = |
76 |
|
new ConfigurationKey(defaultEnv, appId); |
77 |
0 |
list.add(defaultKey); |
78 |
|
} |
79 |
|
|
80 |
0 |
addAppKeys(list, defaultEnv, appId); |
81 |
|
} |
82 |
|
else |
83 |
|
{ |
84 |
0 |
list.add(new ConfigurationKey(defaultEnv, ApplicationId.ANY_APP)); |
85 |
|
} |
86 |
|
} |
87 |
|
|
88 |
0 |
addAppKeyNoEnv(list, appId); |
89 |
|
|
90 |
0 |
final ConfigurationKey defaultKey = |
91 |
|
new ConfigurationKey(EnvironmentId.ANY_ENV, ApplicationId.ANY_APP); |
92 |
0 |
list.add(defaultKey); |
93 |
|
|
94 |
0 |
return list; |
95 |
|
} |
96 |
|
|
97 |
|
private void addAppKeys(final List<ConfigurationKey> list, |
98 |
|
final EnvironmentId envId, final ApplicationId appId) |
99 |
|
throws IllegalArgumentException, NullArgumentException |
100 |
|
{ |
101 |
0 |
if (appId.getVersion() != null) |
102 |
|
{ |
103 |
0 |
final ApplicationId defaultAppId = |
104 |
|
new ApplicationId(appId.getGroupId(), appId.getArtifactId(), null); |
105 |
0 |
final ConfigurationKey defaultKey = |
106 |
|
new ConfigurationKey(envId, defaultAppId); |
107 |
0 |
list.add(defaultKey); |
108 |
|
} |
109 |
|
|
110 |
0 |
if (appId.getArtifactId() != null) |
111 |
|
{ |
112 |
0 |
final ApplicationId defaultAppId = |
113 |
|
new ApplicationId(appId.getGroupId(), null, null); |
114 |
0 |
final ConfigurationKey defaultKey = |
115 |
|
new ConfigurationKey(envId, defaultAppId); |
116 |
0 |
list.add(defaultKey); |
117 |
|
} |
118 |
|
|
119 |
0 |
if (appId.getGroupId() != null) |
120 |
|
{ |
121 |
0 |
final ConfigurationKey defaultKey = |
122 |
|
new ConfigurationKey(envId, ApplicationId.ANY_APP); |
123 |
0 |
list.add(defaultKey); |
124 |
|
} |
125 |
0 |
} |
126 |
|
|
127 |
|
private void addAppKeyNoEnv(final List<ConfigurationKey> list, |
128 |
|
final ApplicationId appId) throws NullArgumentException, |
129 |
|
IllegalArgumentException |
130 |
|
{ |
131 |
0 |
if (appId.getVersion() != null) |
132 |
|
{ |
133 |
0 |
final ConfigurationKey defaultAppKey = |
134 |
|
new ConfigurationKey(EnvironmentId.ANY_ENV, appId); |
135 |
0 |
list.add(defaultAppKey); |
136 |
|
} |
137 |
|
|
138 |
0 |
if (appId.getArtifactId() != null) |
139 |
|
{ |
140 |
0 |
final ApplicationId noEnvAppId = |
141 |
|
new ApplicationId(appId.getGroupId(), appId.getArtifactId(), null); |
142 |
0 |
final ConfigurationKey defaultAppKey = |
143 |
|
new ConfigurationKey(EnvironmentId.ANY_ENV, noEnvAppId); |
144 |
0 |
list.add(defaultAppKey); |
145 |
|
} |
146 |
|
|
147 |
0 |
if (appId.getGroupId() != null) |
148 |
|
{ |
149 |
0 |
final ApplicationId noEnvAppId = |
150 |
|
new ApplicationId(appId.getGroupId(), null, null); |
151 |
0 |
final ConfigurationKey defaultAppKey = |
152 |
|
new ConfigurationKey(EnvironmentId.ANY_ENV, noEnvAppId); |
153 |
0 |
list.add(defaultAppKey); |
154 |
|
} |
155 |
0 |
} |
156 |
|
|
157 |
|
|
158 |
|
|
159 |
|
} |