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 this.playerId = 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 final void setRoleTypeUri(String roleTypeUri) { 038 if (roleTypeUri == null) { 039 throw new IllegalArgumentException("\"roleTypeUri\" must not be null"); 040 } 041 // 042 this.roleTypeUri = roleTypeUri; 043 } 044 045 // --- 046 047 /** 048 * Checks weather the given role model refers to the same object as this role model. 049 * In case of a topic role model the topic IDs resp. URIs are compared. 050 * In case of an association role model the association IDs are compared. 051 * Note: the role types are not compared. 052 * 053 * @return true if the given role model refers to the same object as this role model. 054 */ 055 public abstract boolean refsSameObject(RoleModel model); 056 057 public abstract JSONObject toJSON(); 058 059 // === Java API === 060 061 @Override 062 public RoleModel clone() { 063 try { 064 return (RoleModel) super.clone(); 065 } catch (Exception e) { 066 throw new RuntimeException("Cloning a RoleModel failed", e); 067 } 068 } 069 }