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