001 package de.deepamehta.core.model;
002
003 import org.codehaus.jettison.json.JSONObject;
004
005
006
007 public abstract class RoleModel implements Cloneable {
008
009 // ---------------------------------------------------------------------------------------------- Instance Variables
010
011 protected long playerId; // id of the player (a topic, or an association)
012 protected String roleTypeUri; // is never null
013
014 // ---------------------------------------------------------------------------------------------------- Constructors
015
016 // ### TODO: drop this?
017 protected RoleModel() {
018 }
019
020 protected RoleModel(long playerId, String roleTypeUri) {
021 setPlayerId(playerId);
022 setRoleTypeUri(roleTypeUri);
023 }
024
025 // -------------------------------------------------------------------------------------------------- Public Methods
026
027 public long getPlayerId() {
028 return playerId;
029 }
030
031 public final String getRoleTypeUri() {
032 return roleTypeUri;
033 }
034
035 // ---
036
037 public void setPlayerId(long playerId) {
038 this.playerId = playerId;
039 }
040
041 public final void setRoleTypeUri(String roleTypeUri) {
042 if (roleTypeUri == null) {
043 throw new IllegalArgumentException("\"roleTypeUri\" must not be null");
044 }
045 //
046 this.roleTypeUri = roleTypeUri;
047 }
048
049 // ---
050
051 /**
052 * Checks weather the given role model refers to the same object as this role model.
053 * In case of a topic role model the topic IDs resp. URIs are compared.
054 * In case of an association role model the association IDs are compared.
055 * Note: the role types are not compared.
056 *
057 * @return true if the given role model refers to the same object as this role model.
058 */
059 public abstract boolean refsSameObject(RoleModel model);
060
061 public abstract JSONObject toJSON();
062
063 // === Java API ===
064
065 @Override
066 public RoleModel clone() {
067 try {
068 return (RoleModel) super.clone();
069 } catch (Exception e) {
070 throw new RuntimeException("Cloning a RoleModel failed", e);
071 }
072 }
073 }