001    package de.deepamehta.core.impl;
002    
003    import de.deepamehta.core.JSONEnabled;
004    import de.deepamehta.core.TopicType;
005    import de.deepamehta.core.model.TopicTypeModel;
006    import de.deepamehta.core.service.ClientState;
007    import de.deepamehta.core.service.Directive;
008    import de.deepamehta.core.service.Directives;
009    
010    import java.util.logging.Logger;
011    
012    
013    
014    /**
015     * A topic type that is attached to the {@link DeepaMehtaService}.
016     */
017    class AttachedTopicType extends AttachedType implements TopicType {
018    
019        // ---------------------------------------------------------------------------------------------- Instance Variables
020    
021        private Logger logger = Logger.getLogger(getClass().getName());
022    
023        // ---------------------------------------------------------------------------------------------------- Constructors
024    
025        AttachedTopicType(TopicTypeModel model, EmbeddedService dms) {
026            super(model, dms);
027        }
028    
029        // -------------------------------------------------------------------------------------------------- Public Methods
030    
031    
032    
033        // ********************************
034        // *** TopicType Implementation ***
035        // ********************************
036    
037    
038    
039        @Override
040        public TopicTypeModel getModel() {
041            return (TopicTypeModel) super.getModel();
042        }
043    
044        @Override
045        public void update(TopicTypeModel model, ClientState clientState, Directives directives) {
046            logger.info("Updating topic type \"" + getUri() + "\" (new " + model + ")");
047            // Note: the UPDATE_TOPIC_TYPE directive must be added *before* a possible UPDATE_TOPIC directive (added
048            // by super.update()). In case of a changed type URI the webclient's type cache must be updated *before*
049            // the TopicTypeRenderer can render the type.
050            directives.add(Directive.UPDATE_TOPIC_TYPE, this);
051            //
052            super.update(model, clientState, directives);
053        }
054    
055        // ----------------------------------------------------------------------------------------- Package Private Methods
056    
057    
058    
059        // === AttachedTopic Overrides ===
060    
061        @Override
062        final String className() {
063            return "topic type";
064        }
065    
066    
067    
068        // === Implementation of abstract AttachedType methods ===
069    
070        @Override
071        final void putInTypeCache() {
072            dms.typeCache.putTopicType(this);
073        }
074    
075        @Override
076        final void removeFromTypeCache() {
077            dms.typeCache.removeTopicType(getUri());
078        }
079    
080        // ---
081    
082        @Override
083        final Directive getDeleteTypeDirective() {
084            return Directive.DELETE_TOPIC_TYPE;
085        }
086    }