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 {
47 }
48
49
50
51
52
53
54
55
56
57
58
59 @Override
60 public List<ConfigurationKey<?>> createKeyList(
61 final ConfigurationKey<?> key)
62 {
63 final List<ConfigurationKey<?>> list =
64 new ArrayList<ConfigurationKey<?>>();
65 list.add(key);
66
67 final EnvAppConfigurationKey specific = (EnvAppConfigurationKey) key;
68 final EnvironmentId envId = specific.getEnvironmentId();
69 final ApplicationId appId = specific.getApplicationId();
70
71 addAppKeys(list, envId, appId);
72
73 if (envId.getNode() != null)
74 {
75 final EnvironmentId defaultEnv = new EnvironmentId(envId.getName());
76 if (!ApplicationId.ANY_APP.equals(appId))
77 {
78 if (appId.getVersion() != null)
79 {
80 final EnvAppConfigurationKey defaultKey =
81 new EnvAppConfigurationKey(defaultEnv, appId);
82 list.add(defaultKey);
83 }
84
85 addAppKeys(list, defaultEnv, appId);
86 }
87 else
88 {
89 list.add(new EnvAppConfigurationKey(defaultEnv, ApplicationId.ANY_APP));
90 }
91 }
92
93 addAppKeyNoEnv(list, appId);
94
95 final EnvAppConfigurationKey defaultKey =
96 new EnvAppConfigurationKey(EnvironmentId.ANY_ENV, ApplicationId.ANY_APP);
97 list.add(defaultKey);
98
99 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 if (appId.getVersion() != null)
107 {
108 final ApplicationId defaultAppId =
109 new ApplicationId(appId.getGroupId(), appId.getArtifactId(), null);
110 final EnvAppConfigurationKey defaultKey =
111 new EnvAppConfigurationKey(envId, defaultAppId);
112 list.add(defaultKey);
113 }
114
115 if (appId.getArtifactId() != null)
116 {
117 final ApplicationId defaultAppId =
118 new ApplicationId(appId.getGroupId(), null, null);
119 final EnvAppConfigurationKey defaultKey =
120 new EnvAppConfigurationKey(envId, defaultAppId);
121 list.add(defaultKey);
122 }
123
124 if (appId.getGroupId() != null)
125 {
126 final EnvAppConfigurationKey defaultKey =
127 new EnvAppConfigurationKey(envId, ApplicationId.ANY_APP);
128 list.add(defaultKey);
129 }
130 }
131
132 private void addAppKeyNoEnv(final List<ConfigurationKey<?>> list,
133 final ApplicationId appId) throws NullArgumentException,
134 IllegalArgumentException
135 {
136 if (appId.getVersion() != null)
137 {
138 final EnvAppConfigurationKey defaultAppKey =
139 new EnvAppConfigurationKey(EnvironmentId.ANY_ENV, appId);
140 list.add(defaultAppKey);
141 }
142
143 if (appId.getArtifactId() != null)
144 {
145 final ApplicationId noEnvAppId =
146 new ApplicationId(appId.getGroupId(), appId.getArtifactId(), null);
147 final EnvAppConfigurationKey defaultAppKey =
148 new EnvAppConfigurationKey(EnvironmentId.ANY_ENV, noEnvAppId);
149 list.add(defaultAppKey);
150 }
151
152 if (appId.getGroupId() != null)
153 {
154 final ApplicationId noEnvAppId =
155 new ApplicationId(appId.getGroupId(), null, null);
156 final EnvAppConfigurationKey defaultAppKey =
157 new EnvAppConfigurationKey(EnvironmentId.ANY_ENV, noEnvAppId);
158 list.add(defaultAppKey);
159 }
160 }
161
162
163
164 }