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