001package de.deepamehta.core.impl; 002 003import de.deepamehta.core.Topic; 004import de.deepamehta.core.ViewConfiguration; 005import de.deepamehta.core.model.ChildTopicsModel; 006import de.deepamehta.core.model.RoleModel; 007import de.deepamehta.core.model.TopicModel; 008import de.deepamehta.core.model.ViewConfigurationModel; 009 010 011 012/** 013 * A view configuration that is attached to the {@link PersistenceLayer}. 014 */ 015class ViewConfigurationImpl implements ViewConfiguration { 016 017 // ---------------------------------------------------------------------------------------------- Instance Variables 018 019 /** 020 * The underlying model. 021 */ 022 private ViewConfigurationModelImpl model; 023 024 /** 025 * A role that points to the object this view configuration applies to. 026 * This is either a type (topic role) or an association definition (association role). 027 */ 028 private RoleModel configurable; 029 030 private PersistenceLayer pl; 031 private ModelFactoryImpl mf; 032 033 // ---------------------------------------------------------------------------------------------------- Constructors 034 035 ViewConfigurationImpl(RoleModel configurable, ViewConfigurationModelImpl model, PersistenceLayer pl) { 036 this.configurable = configurable; 037 this.model = model; 038 this.pl = pl; 039 this.mf = pl.mf; 040 } 041 042 // -------------------------------------------------------------------------------------------------- Public Methods 043 044 045 046 // === ViewConfiguration Implementation === 047 048 @Override 049 public Iterable<Topic> getConfigTopics() { 050 return pl.instantiate(model.getConfigTopics()); 051 } 052 053 @Override 054 public Topic getConfigTopic(String configTypeUri) { 055 TopicModelImpl configTopic = model.getConfigTopic(configTypeUri); 056 return configTopic != null ? configTopic.instantiate() : null; 057 } 058 059 @Override 060 public Topic addConfigTopic(TopicModel configTopic) { 061 TopicModelImpl _configTopic = (TopicModelImpl) configTopic; 062 _addConfigTopic(_configTopic); // update memory + DB 063 return _configTopic.instantiate(); 064 } 065 066 @Override 067 public void setConfigValue(String configTypeUri, String childTypeUri, Object value) { 068 ChildTopicsModel childs = mf.newChildTopicsModel().put(childTypeUri, value); 069 TopicModelImpl configTopic = model.getConfigTopic(configTypeUri); 070 if (configTopic == null) { 071 configTopic = mf.newTopicModel(configTypeUri, childs); 072 _addConfigTopic(configTopic); // update memory + DB 073 } else { 074 configTopic.updateWithChildTopics(childs); // update memory + DB 075 } 076 } 077 078 // --- 079 080 @Override 081 public ViewConfigurationModel getModel() { 082 return model; 083 } 084 085 // ------------------------------------------------------------------------------------------------- Private Methods 086 087 public void _addConfigTopic(TopicModelImpl configTopic) { 088 model.addConfigTopic(configTopic); // update memory 089 pl.typeStorage.storeViewConfigTopic(configurable, configTopic); // update DB 090 } 091}