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