-
Notifications
You must be signed in to change notification settings - Fork 4
/
IncludeValue.java
90 lines (75 loc) · 2.38 KB
/
IncludeValue.java
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
package org.configureme.repository;
import org.configureme.ConfigurationManager;
import org.configureme.Environment;
import org.configureme.sources.ConfigurationSourceKey;
/**
* Value of a include attribute. Link to the another config with a configurable attribute name.
*
* @version $Id: $Id
*/
public class IncludeValue implements Value {
/**
* Needed attribute name in the configuration.
*/
private final String attributeName;
/**
* Name of the target configuration.
*/
private String configurationName;
@Override
public Object getRaw() {
return new PlainValue(attributeName+"->"+configurationName);
}
/**
* Resolves included value dynamically from the linked config in the specified environment.
*
* @param in target environment.
* @return a {@link org.configureme.repository.Value} object.
*/
public Value getIncludedValue(Environment in){
return ConfigurationManager.INSTANCE.getConfiguration(configurationName, in).getAttribute(attributeName);
}
/**
* Get configuration name of the linked config
*
* @return configuration name of the linked config
*/
public ConfigurationSourceKey getConfigName() {
return new ConfigurationSourceKey(ConfigurationSourceKey.Type.FILE, ConfigurationSourceKey.Format.JSON, configurationName);
}
/**
* Default constructor.
*/
public IncludeValue() {
attributeName = "";
}
/**
* Constructs new include attribute value.
*
* @param configurationName name config to load
* @param attributeName name of the attribute to get from loaded config
*/
public IncludeValue(String configurationName, String attributeName) {
this.attributeName = attributeName;
this.configurationName = configurationName;
}
@Override
public String toString() {
return attributeName+"->"+configurationName;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof IncludeValue)) return false;
IncludeValue that = (IncludeValue) o;
if (attributeName != null ? !attributeName.equals(that.attributeName) : that.attributeName != null)
return false;
return configurationName != null ? configurationName.equals(that.configurationName) : that.configurationName == null;
}
@Override
public int hashCode() {
int result = attributeName != null ? attributeName.hashCode() : 0;
result = 31 * result + (configurationName != null ? configurationName.hashCode() : 0);
return result;
}
}