001package systems.dmx.core.impl;
002
003import systems.dmx.core.Association;
004import systems.dmx.core.RelatedAssociation;
005import systems.dmx.core.RelatedTopic;
006import systems.dmx.core.Topic;
007import systems.dmx.core.model.TopicModel;
008
009import java.util.List;
010import java.util.logging.Logger;
011
012
013
014/**
015 * A topic that is attached to the {@link CoreService}.
016 */
017class TopicImpl extends DMXObjectImpl implements Topic {
018
019    // ---------------------------------------------------------------------------------------------- Instance Variables
020
021    private final Logger logger = Logger.getLogger(getClass().getName());
022
023    // ---------------------------------------------------------------------------------------------------- Constructors
024
025    TopicImpl(TopicModelImpl model, PersistenceLayer pl) {
026        super(model, pl);
027    }
028
029    // -------------------------------------------------------------------------------------------------- Public Methods
030
031
032
033    // ****************************
034    // *** Topic Implementation ***
035    // ****************************
036
037
038
039    @Override
040    public final void update(TopicModel updateModel) {
041        pl.updateTopic(getModel(), (TopicModelImpl) updateModel);
042    }
043
044    @Override
045    public final void delete() {
046        pl.deleteTopic(getModel());
047    }
048
049    // ---
050
051    @Override
052    public final Topic findChildTopic(String topicTypeUri) {
053        TopicModelImpl topic = getModel().findChildTopic(topicTypeUri);
054        return topic != null ? topic.instantiate() : null;
055    }
056
057    // ---
058
059    @Override
060    public final Topic loadChildTopics() {
061        super.loadChildTopics();
062        return this;
063    }
064
065    @Override
066    public final Topic loadChildTopics(String assocDefUri) {
067        super.loadChildTopics(assocDefUri);
068        return this;
069    }
070
071    // ---
072
073    // Note: overridden by DMXTypeImpl
074    @Override
075    public TopicModelImpl getModel() {
076        return (TopicModelImpl) model;
077    }
078
079
080
081    // ***************************************
082    // *** DMXObject Implementation ***
083    // ***************************************
084
085
086
087    // === Traversal ===
088
089    // ### TODO: consider adding model convenience, would require model renamings (get -> fetch)
090
091    // --- Topic Retrieval ---
092
093    @Override
094    public final List<RelatedTopic> getRelatedTopics(List assocTypeUris, String myRoleTypeUri,
095                                                     String othersRoleTypeUri, String othersTopicTypeUri) {
096        return pl.instantiate(pl.getTopicRelatedTopics(getId(), assocTypeUris, myRoleTypeUri, othersRoleTypeUri,
097            othersTopicTypeUri));
098    }
099
100    // --- Association Retrieval ---
101
102    @Override
103    public final RelatedAssociation getRelatedAssociation(String assocTypeUri, String myRoleTypeUri,
104                                                          String othersRoleTypeUri, String othersAssocTypeUri) {
105        RelatedAssociationModelImpl assoc = pl.getTopicRelatedAssociation(getId(), assocTypeUri, myRoleTypeUri,
106            othersRoleTypeUri, othersAssocTypeUri);
107        return assoc != null ? assoc.instantiate() : null;
108    }
109
110    @Override
111    public final List<RelatedAssociation> getRelatedAssociations(String assocTypeUri, String myRoleTypeUri,
112                                                                 String othersRoleTypeUri, String othersAssocTypeUri) {
113        return pl.instantiate(pl.getTopicRelatedAssociations(getId(), assocTypeUri, myRoleTypeUri, othersRoleTypeUri,
114            othersAssocTypeUri));
115    }
116
117    // ---
118
119    @Override
120    public final Association getAssociation(String assocTypeUri, String myRoleTypeUri, String othersRoleTypeUri,
121                                                                                       long othersTopicId) {
122        return pl.getAssociation(assocTypeUri, getId(), othersTopicId, myRoleTypeUri, othersRoleTypeUri);
123    }
124
125    @Override
126    public final List<Association> getAssociations() {
127        return pl.instantiate(pl.getTopicAssociations(getId()));
128    }
129}