001package systems.dmx.config;
002
003import systems.dmx.core.Topic;
004import systems.dmx.core.model.TopicModel;
005
006
007
008public class ConfigDefinition {
009
010    // ---------------------------------------------------------------------------------------------- Instance Variables
011
012    private ConfigTarget target;
013    private String configurableUri;
014    private TopicModel defaultConfigTopic;
015    private ConfigModificationRole role;
016    private ConfigCustomizer customizer;
017
018    // ---------------------------------------------------------------------------------------------------- Constructors
019
020    public ConfigDefinition(ConfigTarget target, String configurableUri, TopicModel defaultConfigTopic,
021                                                                         ConfigModificationRole role) {
022        this(target, configurableUri, defaultConfigTopic, role, null);
023    }
024
025    public ConfigDefinition(ConfigTarget target, String configurableUri, TopicModel defaultConfigTopic,
026                                                 ConfigModificationRole role, ConfigCustomizer customizer) {
027        this.target = target;
028        this.configurableUri = configurableUri;
029        this.defaultConfigTopic = defaultConfigTopic;
030        this.role = role;
031        this.customizer = customizer;
032    }
033
034    // -------------------------------------------------------------------------------------------------- Public Methods
035
036    @Override
037    public boolean equals(Object o) {
038        return getConfigTypeUri().equals(((ConfigDefinition) o).getConfigTypeUri());
039    }
040
041    @Override
042    public int hashCode() {
043        return getConfigTypeUri().hashCode();
044    }
045
046    // ----------------------------------------------------------------------------------------- Package Private Methods
047
048    String getHashKey() {
049        return target.hashKey(configurableUri);
050    }
051
052    String getConfigTypeUri() {
053        return defaultConfigTopic.getTypeUri();
054    }
055
056    TopicModel getConfigValue(Topic topic) {
057        if (customizer != null) {
058            TopicModel configValue = customizer.getConfigValue(topic);
059            if (configValue != null) {
060                return configValue;
061            }
062        }
063        return defaultConfigTopic;
064    }
065
066    ConfigModificationRole getConfigModificationRole() {
067        return role;
068    }
069}