001    package de.deepamehta.core.impl;
002    
003    import de.deepamehta.core.AssociationType;
004    import de.deepamehta.core.JSONEnabled;
005    import de.deepamehta.core.model.AssociationTypeModel;
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     * An association type that is attached to the {@link DeepaMehtaService}.
016     */
017    class AttachedAssociationType extends AttachedType implements AssociationType {
018    
019        // ---------------------------------------------------------------------------------------------- Instance Variables
020    
021        private Logger logger = Logger.getLogger(getClass().getName());
022    
023        // ---------------------------------------------------------------------------------------------------- Constructors
024    
025        AttachedAssociationType(AssociationTypeModel model, EmbeddedService dms) {
026            super(model, dms);
027        }
028    
029        // -------------------------------------------------------------------------------------------------- Public Methods
030    
031    
032    
033        // **************************************
034        // *** AssociationType Implementation ***
035        // **************************************
036    
037    
038    
039        @Override
040        public AssociationTypeModel getModel() {
041            return (AssociationTypeModel) super.getModel();
042        }
043    
044        @Override
045        public void update(AssociationTypeModel model, ClientState clientState, Directives directives) {
046            logger.info("Updating association type \"" + getUri() + "\" (new " + model + ")");
047            // Note: the UPDATE_ASSOCIATION_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 AssociationTypeRenderer can render the type.
050            directives.add(Directive.UPDATE_ASSOCIATION_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 "association type";
064        }
065    
066    
067    
068        // === Implementation of abstract AttachedType methods ===
069    
070        @Override
071        final void putInTypeCache() {
072            dms.typeCache.putAssociationType(this);
073        }
074    
075        @Override
076        final void removeFromTypeCache() {
077            dms.typeCache.removeAssociationType(getUri());
078        }
079    
080        // ---
081    
082        @Override
083        final Directive getDeleteTypeDirective() {
084            return Directive.DELETE_ASSOCIATION_TYPE;
085        }
086    }