001package systems.dmx.core.impl;
002
003import systems.dmx.core.AssociationType;
004import systems.dmx.core.model.AssociationDefinitionModel;
005import systems.dmx.core.model.AssociationModel;
006import systems.dmx.core.model.AssociationTypeModel;
007import systems.dmx.core.model.SimpleValue;
008import systems.dmx.core.model.TypeModel;
009import systems.dmx.core.service.Directive;
010
011import java.util.List;
012
013
014
015/**
016 * Data that underlies a {@link AssociationType}.
017 *
018 * @author <a href="mailto:jri@deepamehta.de">Jörg Richter</a>
019 */
020public class AssociationTypeModelImpl extends TypeModelImpl implements AssociationTypeModel {
021
022    // ---------------------------------------------------------------------------------------------------- Constructors
023
024    AssociationTypeModelImpl(TypeModelImpl type) {
025        super(type);
026    }
027
028    // -------------------------------------------------------------------------------------------------- Public Methods
029
030    @Override
031    public AssociationTypeModel addAssocDef(AssociationDefinitionModel assocDef) {
032        return (AssociationTypeModel) super.addAssocDef(assocDef);
033    }
034
035    // ---
036
037    @Override
038    public AssociationTypeModelImpl clone() {
039        try {
040            return (AssociationTypeModelImpl) super.clone();
041        } catch (Exception e) {
042            throw new RuntimeException("Cloning a AssociationTypeModel failed", e);
043        }
044    }
045
046    // ----------------------------------------------------------------------------------------- Package Private Methods
047
048    @Override
049    String className() {
050        return "association type";
051    }
052
053    @Override
054    AssociationTypeImpl instantiate() {
055        // Note: declaration and assignment is required for type inference to work (at least in Java 6)
056        AssociationTypeModelImpl type = clone().filterReadableAssocDefs();
057        return new AssociationTypeImpl(type, pl);
058    }
059
060
061
062    // === Implementation of abstract TypeModelImpl methods ===
063
064    @Override
065    List<AssociationModelImpl> getAllInstances() {
066        return pl.fetchAssociations("typeUri", new SimpleValue(uri));
067    }
068
069    // ---
070
071    @Override
072    Directive getUpdateTypeDirective() {
073        return Directive.UPDATE_ASSOCIATION_TYPE;
074    }
075
076    @Override
077    Directive getDeleteTypeDirective() {
078        return Directive.DELETE_ASSOCIATION_TYPE;
079    }
080}