001package systems.dmx.core.impl;
002
003import systems.dmx.core.DMXObject;
004import systems.dmx.core.Role;
005import systems.dmx.core.model.RoleModel;
006
007import org.codehaus.jettison.json.JSONObject;
008
009
010
011abstract class RoleImpl implements Role {
012
013    // ---------------------------------------------------------------------------------------------- Instance Variables
014
015    RoleModelImpl model;            // underlying model
016
017    AssociationModelImpl assoc;     // the association this role is involved in
018
019    // ---------------------------------------------------------------------------------------------------- Constructors
020
021    RoleImpl(RoleModelImpl model, AssociationModelImpl assoc) {
022        this.model = model;
023        this.assoc = assoc;
024    }
025
026    // -------------------------------------------------------------------------------------------------- Public Methods
027
028
029
030    // === Role Implementation ===
031
032    @Override
033    public String getRoleTypeUri() {
034        return model.getRoleTypeUri();
035    }
036
037    @Override
038    public long getPlayerId() {
039        return model.getPlayerId();
040    }
041
042    @Override
043    public DMXObject getPlayer() {
044        return model.getPlayer(assoc).instantiate();    // ### TODO: permission check?
045    }
046
047    // ---
048
049    @Override
050    public void setRoleTypeUri(String roleTypeUri) {
051        assoc.updateRoleTypeUri(model, roleTypeUri);
052    }
053
054    // ---
055
056    @Override
057    public RoleModel getModel() {
058        return model;
059    }
060
061    // ---
062
063    @Override
064    public JSONObject toJSON() {
065        return model.toJSON();
066    }
067}