001package systems.dmx.core.impl;
002
003import systems.dmx.core.model.AssociationModel;
004import systems.dmx.core.model.topicmaps.AssociationViewModel;
005import systems.dmx.core.model.topicmaps.ViewProperties;
006
007import org.codehaus.jettison.json.JSONObject;
008
009
010
011// TODO: rethink inheritance. Can we have a common "ObjectViewModel" for both, topics and assocs?
012// Is this a case for Java 8 interfaces, which can have a default implementation?
013class AssociationViewModelImpl extends AssociationModelImpl implements AssociationViewModel {
014
015    // --- Instance Variables ---
016
017    private ViewProperties viewProps;
018
019    // --- Constructors ---
020
021    AssociationViewModelImpl(AssociationModelImpl assoc, ViewProperties viewProps) {
022        super(assoc);
023        this.viewProps = viewProps;
024    }
025
026    // --- Public Methods ---
027
028    @Override
029    public JSONObject toJSON() {
030        try {
031            return super.toJSON().put("viewProps", viewProps.toJSON());
032        } catch (Exception e) {
033            throw new RuntimeException("Serialization failed", e);
034        }
035    }
036}