001package systems.dmx.core.model;
002
003import org.codehaus.jettison.json.JSONArray;
004
005
006
007/**
008 * A container for config topics.
009 * <p>
010 * Config topics can be accessed by their type URI.
011 * A view config can contain only one config topic with a certain type URI.
012 *
013 * @author <a href="mailto:jri@deepamehta.de">Jörg Richter</a>
014 */
015public interface ViewConfigurationModel {
016
017    Iterable<? extends TopicModel> getConfigTopics();
018
019    /**
020     * @return  the config topic for the given type URI, or <code>null</code> if there is none.
021     */
022    TopicModel getConfigTopic(String configTypeUri);
023
024    /**
025     * Adds a config topic to this view config.
026     *
027     * @throws  RuntimeException    if this view config already contains a config topic with the same type URI.
028     */
029    void addConfigTopic(TopicModel configTopic);
030
031    /**
032     * Sets a single value of a certain config topic.
033     * If no such config topic exists in this view config it is created.
034     *
035     * @param   configTypeUri   The type URI of the config topic, e.g. "dmx.webclient.view_config"
036     * @param   childTypeUri    The child type URI of the config value to set, e.g. "dmx.webclient.icon"
037     * @param   value           The config value (String, Integer, Long, Double, or Boolean)
038     */
039    ViewConfigurationModel setConfigValue(String configTypeUri, String childTypeUri, Object value);
040
041    ViewConfigurationModel setConfigValueRef(String configTypeUri, String childTypeUri, Object topicIdOrUri);
042
043    // ### TODO: drop method?
044    void updateConfigTopic(TopicModel configTopic);
045
046    // ---
047
048    /**
049     * ### TODO: drop method?
050     *
051     * Lookup a view config value.
052     * <p>
053     * Compare to client-side counterpart: function get_view_config() in webclient.js
054     *
055     * @param   configTypeUri   The type URI of the config topic, e.g. "dmx.webclient.view_config"
056     * @param   childTypeUri    The child type URI of the config value to lookup, e.g. "dmx.webclient.icon"
057     *
058     * @return  The config value, or <code>null</code> if no value is set
059     */
060    Object getConfigValue(String configTypeUri, String childTypeUri);
061
062    // ---
063
064    JSONArray toJSONArray();
065}