001package de.deepamehta.core.impl;
002
003import de.deepamehta.core.AssociationDefinition;
004import de.deepamehta.core.DeepaMehtaType;
005import de.deepamehta.core.ViewConfiguration;
006import de.deepamehta.core.model.AssociationDefinitionModel;
007import de.deepamehta.core.model.IndexMode;
008import de.deepamehta.core.model.RoleModel;
009import de.deepamehta.core.model.TypeModel;
010
011import java.util.Collection;
012import java.util.List;
013
014
015
016abstract class DeepaMehtaTypeImpl extends TopicImpl implements DeepaMehtaType {
017
018    // ---------------------------------------------------------------------------------------------------- Constructors
019
020    DeepaMehtaTypeImpl(TypeModelImpl model, PersistenceLayer pl) {
021        super(model, pl);
022    }
023
024    // -------------------------------------------------------------------------------------------------- Public Methods
025
026
027
028    // *************************************
029    // *** DeepaMehtaType Implementation ***
030    // *************************************
031
032
033
034    // --- Data Type ---
035
036    @Override
037    public final String getDataTypeUri() {
038        return getModel().getDataTypeUri();
039    }
040
041    @Override
042    public final DeepaMehtaType setDataTypeUri(String dataTypeUri) {
043        _getModel().updateDataTypeUri(dataTypeUri);
044        return this;
045    }
046
047    // --- Index Modes ---
048
049    @Override
050    public final List<IndexMode> getIndexModes() {
051        return getModel().getIndexModes();
052    }
053
054    @Override
055    public final DeepaMehtaType addIndexMode(IndexMode indexMode) {
056        _getModel()._addIndexMode(indexMode);
057        return this;
058    }
059
060    // --- Association Definitions ---
061
062    @Override
063    public final Collection<AssociationDefinition> getAssocDefs() {
064        return pl.instantiate(getModel().getAssocDefs());
065    }
066
067    @Override
068    public final AssociationDefinition getAssocDef(String assocDefUri) {
069        return getModel().getAssocDef(assocDefUri).instantiate();
070    }
071
072    @Override
073    public final boolean hasAssocDef(String assocDefUri) {
074        return getModel().hasAssocDef(assocDefUri);
075    }
076
077    @Override
078    public final DeepaMehtaType addAssocDef(AssociationDefinitionModel assocDef) {
079        return addAssocDefBefore(assocDef, null);   // beforeAssocDefUri=null
080    }
081
082    @Override
083    public final DeepaMehtaType addAssocDefBefore(AssociationDefinitionModel assocDef, String beforeAssocDefUri) {
084        _getModel()._addAssocDefBefore((AssociationDefinitionModelImpl) assocDef, beforeAssocDefUri);
085        return this;
086    }
087
088    @Override
089    public final DeepaMehtaType removeAssocDef(String assocDefUri) {
090        _getModel()._removeAssocDef(assocDefUri);
091        return this;
092    }
093
094    // --- Label Configuration ---
095
096    @Override
097    public final List<String> getLabelConfig() {
098        return getModel().getLabelConfig();
099    }
100
101    @Override
102    public final DeepaMehtaType setLabelConfig(List<String> labelConfig) {
103        _getModel().updateLabelConfig(labelConfig);
104        return this;
105    }
106
107    // --- View Configuration ---
108
109    @Override
110    public final ViewConfiguration getViewConfig() {
111        RoleModel configurable = pl.typeStorage.newTypeRole(getId());   // ### type ID is uninitialized
112        return new ViewConfigurationImpl(configurable, getModel().getViewConfigModel(), pl);
113    }
114
115    @Override
116    public final Object getViewConfig(String typeUri, String settingUri) {
117        return getModel().getViewConfig(typeUri, settingUri);
118    }
119
120    // ---
121
122    @Override
123    public void update(TypeModel newModel) {
124        _getModel().update((TypeModelImpl) newModel);   // ### FIXME: call through pl for access control
125    }
126
127    // ---
128
129    @Override
130    public TypeModelImpl getModel() {
131        return (TypeModelImpl) model;
132    }
133
134    // ----------------------------------------------------------------------------------------- Package Private Methods
135
136    /**
137     * Returns the <i>internal</i> (= <b>kernel</b>) model underlying this type.
138     * <p>
139     * Note: type updates must be performed on the internal type model, not the userland's type model (as returned by
140     * <code>getModel()</code>). Performing an update on the <b>userland</b>'s type model would have no effect, as it
141     * is transient. The userland's type model is always a <i>cloned</i> and filtered (= "projected") version of a
142     * kernel type model which is created on-the-fly each time a specific user requests it.
143     */
144    abstract TypeModelImpl _getModel();
145}