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.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 DeepaMehtaObjectImpl implements Topic { 018 019 // ---------------------------------------------------------------------------------------------- Instance Variables 020 021 private 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 void update(TopicModel updateModel) { 041 model.update((TopicModelImpl) updateModel); // ### FIXME: call through pl for access control 042 } 043 044 // --- 045 046 @Override 047 public Topic findChildTopic(String topicTypeUri) { 048 TopicModelImpl topic = getModel().findChildTopic(topicTypeUri); 049 return topic != null ? topic.instantiate() : null; 050 } 051 052 // --- 053 054 @Override 055 public Topic loadChildTopics() { 056 model.loadChildTopics(); 057 return this; 058 } 059 060 @Override 061 public Topic loadChildTopics(String assocDefUri) { 062 model.loadChildTopics(assocDefUri); 063 return this; 064 } 065 066 // --- 067 068 @Override 069 public TopicModelImpl getModel() { 070 return (TopicModelImpl) model; 071 } 072 073 074 075 // *************************************** 076 // *** DeepaMehtaObject Implementation *** 077 // *************************************** 078 079 080 081 // === Traversal === 082 083 // ### TODO: move logic to model 084 085 // --- Topic Retrieval --- 086 087 @Override 088 public List<RelatedTopic> getRelatedTopics(List assocTypeUris, String myRoleTypeUri, String othersRoleTypeUri, 089 String othersTopicTypeUri) { 090 List<RelatedTopicModelImpl> topics = pl.fetchTopicRelatedTopics(getId(), assocTypeUris, myRoleTypeUri, 091 othersRoleTypeUri, othersTopicTypeUri); 092 return pl.checkReadAccessAndInstantiate(topics); 093 } 094 095 // --- Association Retrieval --- 096 097 @Override 098 public RelatedAssociation getRelatedAssociation(String assocTypeUri, String myRoleTypeUri, String othersRoleTypeUri, 099 String othersAssocTypeUri) { 100 RelatedAssociationModelImpl assoc = pl.fetchTopicRelatedAssociation(getId(), 101 assocTypeUri, myRoleTypeUri, othersRoleTypeUri, othersAssocTypeUri); 102 return assoc != null ? pl.<RelatedAssociation>checkReadAccessAndInstantiate(assoc) : null; 103 } 104 105 @Override 106 public List<RelatedAssociation> getRelatedAssociations(String assocTypeUri, String myRoleTypeUri, 107 String othersRoleTypeUri, String othersAssocTypeUri) { 108 List<RelatedAssociationModelImpl> assocs = pl.fetchTopicRelatedAssociations(getId(), assocTypeUri, 109 myRoleTypeUri, othersRoleTypeUri, othersAssocTypeUri); 110 return pl.checkReadAccessAndInstantiate(assocs); 111 } 112 113 // --- 114 115 @Override 116 public Association getAssociation(String assocTypeUri, String myRoleTypeUri, String othersRoleTypeUri, 117 long othersTopicId) { 118 AssociationModelImpl assoc = pl.fetchAssociation(assocTypeUri, getId(), othersTopicId, myRoleTypeUri, 119 othersRoleTypeUri); 120 return assoc != null ? pl.<Association>checkReadAccessAndInstantiate(assoc) : null; 121 } 122 123 @Override 124 public List<Association> getAssociations() { 125 return pl.checkReadAccessAndInstantiate(pl.fetchTopicAssociations(getId())); 126 } 127}