001    package de.deepamehta.core.model;
002    
003    import org.codehaus.jettison.json.JSONObject;
004    
005    
006    
007    public class RelatedTopicModel extends TopicModel {
008    
009        // ---------------------------------------------------------------------------------------------- Instance Variables
010    
011        private AssociationModel relatingAssoc;
012    
013        // ---------------------------------------------------------------------------------------------------- Constructors
014    
015        public RelatedTopicModel(TopicModel topic, AssociationModel relatingAssoc) {
016            super(topic);
017            this.relatingAssoc = relatingAssoc;
018        }
019    
020        // -------------------------------------------------------------------------------------------------- Public Methods
021    
022        public AssociationModel getRelatingAssociation() {
023            return relatingAssoc;
024        }
025    
026        // === Serialization ===
027    
028        @Override
029        public JSONObject toJSON() {
030            try {
031                JSONObject o = super.toJSON();
032                o.put("assoc", relatingAssoc.toJSON());
033                return o;
034            } catch (Exception e) {
035                throw new RuntimeException("Serialization failed (" + this + ")", e);
036            }
037        }
038    
039        // === Java API ===
040    
041        @Override
042        public String toString() {
043            return super.toString() + ", relating " + relatingAssoc;
044        }
045    }