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