001package de.deepamehta.core.impl; 002 003import de.deepamehta.core.Association; 004import de.deepamehta.core.RelatedAssociation; 005import de.deepamehta.core.RelatedTopic; 006import de.deepamehta.core.Topic; 007import de.deepamehta.core.TopicType; 008import de.deepamehta.core.model.TopicModel; 009 010import java.util.List; 011import java.util.logging.Logger; 012 013 014 015/** 016 * A topic that is attached to the {@link CoreService}. 017 */ 018class TopicImpl extends DeepaMehtaObjectImpl implements Topic { 019 020 // ---------------------------------------------------------------------------------------------- Instance Variables 021 022 private Logger logger = Logger.getLogger(getClass().getName()); 023 024 // ---------------------------------------------------------------------------------------------------- Constructors 025 026 TopicImpl(TopicModelImpl model, PersistenceLayer pl) { 027 super(model, pl); 028 } 029 030 // -------------------------------------------------------------------------------------------------- Public Methods 031 032 033 034 // **************************** 035 // *** Topic Implementation *** 036 // **************************** 037 038 039 040 @Override 041 public void update(TopicModel newModel) { 042 model.update(newModel); 043 } 044 045 // --- 046 047 @Override 048 public Topic findChildTopic(String topicTypeUri) { 049 TopicModelImpl topic = getModel().findChildTopic(topicTypeUri); 050 return topic != null ? topic.instantiate() : null; 051 } 052 053 // --- 054 055 @Override 056 public Topic loadChildTopics() { 057 model.loadChildTopics(); 058 return this; 059 } 060 061 @Override 062 public Topic loadChildTopics(String assocDefUri) { 063 model.loadChildTopics(assocDefUri); 064 return this; 065 } 066 067 // --- 068 069 @Override 070 public TopicType getType() { 071 return pl.getTopicType(getTypeUri()); 072 } 073 074 @Override 075 public TopicModelImpl getModel() { 076 return (TopicModelImpl) model; 077 } 078 079 080 081 // *************************************** 082 // *** DeepaMehtaObject Implementation *** 083 // *************************************** 084 085 086 087 // === Traversal === 088 089 // ### TODO: move logic to model 090 091 // --- Topic Retrieval --- 092 093 @Override 094 public List<RelatedTopic> getRelatedTopics(List assocTypeUris, String myRoleTypeUri, String othersRoleTypeUri, 095 String othersTopicTypeUri) { 096 List<RelatedTopicModelImpl> topics = pl.fetchTopicRelatedTopics(getId(), assocTypeUris, myRoleTypeUri, 097 othersRoleTypeUri, othersTopicTypeUri); 098 return pl.checkReadAccessAndInstantiate(topics); 099 } 100 101 // --- Association Retrieval --- 102 103 @Override 104 public RelatedAssociation getRelatedAssociation(String assocTypeUri, String myRoleTypeUri, String othersRoleTypeUri, 105 String othersAssocTypeUri) { 106 RelatedAssociationModelImpl assoc = pl.fetchTopicRelatedAssociation(getId(), 107 assocTypeUri, myRoleTypeUri, othersRoleTypeUri, othersAssocTypeUri); 108 return assoc != null ? pl.<RelatedAssociation>checkReadAccessAndInstantiate(assoc) : null; 109 } 110 111 @Override 112 public List<RelatedAssociation> getRelatedAssociations(String assocTypeUri, String myRoleTypeUri, 113 String othersRoleTypeUri, String othersAssocTypeUri) { 114 List<RelatedAssociationModelImpl> assocs = pl.fetchTopicRelatedAssociations(getId(), assocTypeUri, 115 myRoleTypeUri, othersRoleTypeUri, othersAssocTypeUri); 116 return pl.checkReadAccessAndInstantiate(assocs); 117 } 118 119 // --- 120 121 @Override 122 public Association getAssociation(String assocTypeUri, String myRoleTypeUri, String othersRoleTypeUri, 123 long othersTopicId) { 124 AssociationModelImpl assoc = pl.fetchAssociation(assocTypeUri, getId(), othersTopicId, myRoleTypeUri, 125 othersRoleTypeUri); 126 return assoc != null ? pl.<Association>checkReadAccessAndInstantiate(assoc) : null; 127 } 128 129 @Override 130 public List<Association> getAssociations() { 131 return pl.checkReadAccessAndInstantiate(pl.fetchTopicAssociations(getId())); 132 } 133 134 135 136 // === Properties === 137 138 @Override 139 public void setProperty(String propUri, Object propValue, boolean addToIndex) { 140 pl.storeTopicProperty(getId(), propUri, propValue, addToIndex); 141 } 142 143 @Override 144 public void removeProperty(String propUri) { 145 pl.removeTopicProperty(getId(), propUri); 146 } 147}