/*
 * $Id: AccessorInfo.java,v 1.6 2007/10/30 13:21:54 marbobo Exp $
 * 
 * Copyright (c) Siemens AG 2008 
 *           (c) Universität Paderborn 2008 
 * Licensed under EUPL 1.1. 
 * 
 * $Log: AccessorInfo.java,v $
 * Revision 1.6  2007/10/30 13:21:54  marbobo
 * + removed unnecessary statements
 *
 * Revision 1.5  2004/10/26 13:40:39  vchris
 * *** empty log message ***
 *
 * Revision 1.4  2004/06/24 23:30:03  marbobo
 * Quellcode maintenance
 *
 * Revision 1.3  2003/12/24 10:12:11  bigmac
 * Projektweite Import-Optimierung
 *
 * Revision 1.2  2003/11/04 16:19:45  vchris
 * *** empty log message ***
 *
 * 
 * Created on 15.10.2003
 */

package vkc.security;

import java.io.Serializable;

import vkc.db.entities.VKCAclType;

/**
 * @author vchris
 */
public class AccessorInfo implements Serializable {

    private String accessorName;
    private Integer accessorTypeId;
    private Integer accessorId;

    /**
     * Keine Instanzen mit leerem Konstruktor erlauben
     */
    private AccessorInfo() {
    }

    public AccessorInfo(String accessorName, Integer accessorTypeId, Integer accessorId) {
        this();
        this.accessorName = accessorName;
        this.accessorTypeId = accessorTypeId;
        this.accessorId = accessorId;
    }

    public AccessorInfo(String accessorName, String accessorType, Integer accessorId) {
        this();
        this.accessorName = accessorName;
        this.accessorTypeId = getAccessorTypeIntegerValue(accessorType);
        this.accessorId = accessorId;
    }

    /**
     * Liefert den Integer-Wert zu einem gegebenen Integer AccessorType
     * 
     * @param accessorType
     * @return
     */
    public static Integer getAccessorTypeIntegerValue(String accessorType) {
        if (accessorType.equals(VKCAclType.USER))
            return new Integer(VKCAclType.USER_TYPE);
        else if (accessorType.equals(VKCAclType.GROUP))
            return new Integer(VKCAclType.GROUP_TYPE);
        else if (accessorType.equals(VKCAclType.MASK))
            return new Integer(VKCAclType.MASK_TYPE);
        else if (accessorType.equals(VKCAclType.OWNER))
            return new Integer(VKCAclType.OWNER_TYPE);
        else if (accessorType.equals(VKCAclType.LDAP_GROUP))
            return new Integer(VKCAclType.LDAP_GROUP_TYPE);
        else
            return new Integer(VKCAclType.ANYOTHER_TYPE);
    }

    /**
     * Liefert den String-Wert zu einem gegebenen Integer AccessorTypeId
     * 
     * @param accessorTypeId
     * @return
     */
    public static String getAccessorTypeStringValue(Integer accessorTypeId) {
        if (accessorTypeId.intValue() == VKCAclType.USER_TYPE)
            return VKCAclType.USER;
        else if (accessorTypeId.intValue() == VKCAclType.GROUP_TYPE)
            return VKCAclType.GROUP;
        else if (accessorTypeId.intValue() == VKCAclType.MASK_TYPE)
            return VKCAclType.MASK;
        else if (accessorTypeId.intValue() == VKCAclType.OWNER_TYPE)
            return VKCAclType.OWNER;
        else if (accessorTypeId.intValue() == VKCAclType.LDAP_GROUP_TYPE)
            return VKCAclType.LDAP_GROUP;
        else
            return VKCAclType.ANYOTHER;
    }

    /**
     * Gibt "true" zurück, falls alle Werte des übergebenen Objektes mit dem aktuellen Objekt übereinstimmen.
     * 
     * @return boolean
     */
    public boolean equals(Object o) {
        if (!(o instanceof AccessorInfo))
            return false;
        AccessorInfo ai = (AccessorInfo) o;
        
        if (ai.getAccessorId().equals(this.getAccessorId()) && ai.getAccessorName().equals(this.getAccessorName()) && ai.getAccessorTypeId().equals(this.getAccessorTypeId()))
            return true;
        
        return false;

    }

    /**
     * Gibt einen String zurück, der den Typen und die ID enthält. Zur Verwendung z.B. in Select-Box.
     * 
     * @return String
     */
    public String getSelectIdString() {
        return getAccessorTypeStringValue(accessorTypeId) + "_" + accessorId;
    }

    /**
     * @return
     */
    public String getAccessorType() {
        return getAccessorTypeStringValue(accessorTypeId);
    }

    /**
     * @param accessorType
     */
    public void setAccessorType(String accessorType) {
        accessorTypeId = getAccessorTypeIntegerValue(accessorType);
    }

    /**
     * @return
     */
    public Integer getAccessorId() {
        return accessorId;
    }

    /**
     * @return
     */
    public String getAccessorName() {
        return accessorName;
    }

    /**
     * @return
     */
    public Integer getAccessorTypeId() {
        return accessorTypeId;
    }

    /**
     * @param integer
     */
    public void setAccessorId(Integer integer) {
        accessorId = integer;
    }

    /**
     * @param string
     */
    public void setAccessorName(String string) {
        accessorName = string;
    }

    /**
     * @param integer
     */
    public void setAccessorTypeId(Integer integer) {
        accessorTypeId = integer;
    }
}