001package de.deepamehta.core.impl;
002
003import de.deepamehta.core.Role;
004import de.deepamehta.core.model.RoleModel;
005
006
007
008abstract class RoleModelImpl implements RoleModel {
009
010    // ---------------------------------------------------------------------------------------------- Instance Variables
011
012    long playerId;                  // id of the player (a topic, or an association)
013    String roleTypeUri;             // is never null
014
015    PersistenceLayer pl;
016    ModelFactoryImpl mf;
017
018    // ---------------------------------------------------------------------------------------------------- Constructors
019
020    // ### TODO: drop this?
021    RoleModelImpl() {
022    }
023
024    RoleModelImpl(long playerId, String roleTypeUri, PersistenceLayer pl) {
025        setPlayerId(playerId);
026        setRoleTypeUri(roleTypeUri);
027        this.pl = pl;
028        this.mf = pl.mf;
029    }
030
031    // -------------------------------------------------------------------------------------------------- Public Methods
032
033    @Override
034    public long getPlayerId() {
035        return playerId;
036    }
037
038    @Override
039    public final String getRoleTypeUri() {
040        return roleTypeUri;
041    }
042
043    // ---
044
045    // ### TODO: to be dropped?
046    @Override
047    public void setPlayerId(long playerId) {
048        this.playerId = playerId;
049    }
050
051    @Override
052    public final void setRoleTypeUri(String roleTypeUri) {
053        if (roleTypeUri == null) {
054            throw new IllegalArgumentException("\"roleTypeUri\" must not be null");
055        }
056        //
057        this.roleTypeUri = roleTypeUri;
058    }
059
060    // ---
061
062    // Note: refsSameObject() remain abstract
063
064
065
066    // === Java API ===
067
068    @Override
069    public RoleModel clone() {
070        try {
071            return (RoleModel) super.clone();
072        } catch (Exception e) {
073            throw new RuntimeException("Cloning a RoleModel failed", e);
074        }
075    }
076
077    // ----------------------------------------------------------------------------------------- Package Private Methods
078
079    /**
080     * @param   assoc   the association this role is involved in
081     */
082    abstract Role instantiate(AssociationModelImpl assoc);
083
084    /**
085     * @param   assoc   the association this role is involved in
086     */
087    abstract DeepaMehtaObjectModelImpl getPlayer(AssociationModelImpl assoc);
088}