Repository navigation
Expand file tree
/
Copy pathActConfigKey.java
More file actions
145 lines (125 loc) · 4.13 KB
/
Copy pathActConfigKey.java
File metadata and controls
145 lines (125 loc) · 4.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
package act.conf;
import act.Act;
import org.osgl.logging.L;
import org.osgl.logging.Logger;
import org.osgl.util.S;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* {@link Act} configuration keys. General rules:
* <p/>
* <ul>
* <li>When a key is ended with <code>.enabled</code>, then you should be able to set
* the setting without <code>.enabled</code> or replace it with <code>.disabled</code>
* but the value will be inverted. For example, <code>built_in.transformer.enabled</code>
* is equal to <code>built_in.transformer</code> and invert to
* <code>built_in.transformer.disabled</code></li>
* <p/>
* <li>When a key is ended with <code>.impl</code>, then you can either put an instance into
* the configuration map or a string of the class className</li>
* </ul>
*/
public enum ActConfigKey implements ConfigKey {
/**
* {@code act.home.dir} specifies the Act home dir
* <p>This property must be set to start Act. There is no default value for this configuration</p>
*/
HOME("home.dir"),
/**
* {@code act.app.base} specifies the application base in relation to the
* {@link #HOME home dir}.
* <p>Default value: {@code apps}</p>
*/
APP_BASE("app.base", "apps"),
/**
* {@code act.mode} specifies the Act running mode. Options:
* <ul>
* <li>{@code dev} - run Act during development, loading and refreshing class
* directly from srccode code enabled in this mode</li>
* <li>{@code prod} - run Act when system is live</li>
* </ul>
* <p>You pass the mode to Act runtime during start up like:</p>
* <pre><code>act --mode dev</code></pre>
* <p>Or via JVM properties like:</p>
* <pre><code>-Dmode=uat</code></pre>
*/
MODE("mode", Act.Mode.PROD),
/**
* {@code act.xio.impl} specifies the implementation for the network stack implementation
*/
NETWORK_SERVER_IMPL("xio.impl");
private static Logger logger = L.get(AppConfigKey.class);
private static ConfigKeyHelper helper = new ConfigKeyHelper(Act.F.MODE_ACCESSOR, Act.class.getClassLoader());
private String key;
private Object defVal;
private ActConfigKey(String key) {
this(key, null);
}
private ActConfigKey(String key, Object defVal) {
this.key = key;
this.defVal = defVal;
}
/**
* Return the key string
*
* @return the key of the configuration
*/
public String key() {
return key;
}
/**
* Return default value of this setting. The configuration data map
* is passed in in case the default value be variable depending on
* another setting.
*
* @param configuration
* @return return the default value
*/
protected Object getDefVal(Map<String, ?> configuration) {
return defVal;
}
/**
* Calling to this method is equals to calling {@link #key()}
*
* @return key of the configuration
*/
@Override
public String toString() {
return key;
}
@Override
public Object defVal() {
return defVal;
}
public <T> List<T> implList(String key, Map<String, ?> configuration, Class<T> c) {
return helper.getImplList(key, configuration, c);
}
/**
* Return configuration value from the configuration data map using the {@link #key}
* of this {@link AppConfigKey setting} instance
*
* @param configuration
* @param <T>
* @return return the configuration
*/
public <T> T val(Map<String, ?> configuration) {
return helper.getConfiguration(this, configuration);
}
private static Map<String, ActConfigKey> lookup = new HashMap<String, ActConfigKey>(50);
static {
for (ActConfigKey k : values()) {
lookup.put(k.key().toLowerCase(), k);
}
}
/**
* Return key enum instance from the string in case insensitive mode
*
* @param s
* @return configuration key from the string
*/
public static ActConfigKey valueOfIgnoreCase(String s) {
if (S.empty(s)) throw new IllegalArgumentException();
return lookup.get(s.trim().toLowerCase());
}
}