package cn.com.qmth.stmms.common.session.model;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import javax.persistence.Transient;

public class StmmsSession implements Serializable {

    private static final long serialVersionUID = -1004172926154352747L;

    private String id;

    private Map<String, String> map;

    @Transient
    private boolean invalid;

    public StmmsSession() {
        this.map = new HashMap<String, String>();
    }

    public String getParameter(String key) {
        return map.get(key);
    }

    public void setParameter(String key, String value) {
        map.put(key, value);
    }

    public Set<Entry<String, String>> getParameters() {
        return map.entrySet();
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public void clear() {
        this.id = null;
        this.map.clear();
    }

    public boolean isInvalid() {
        return invalid;
    }

    public void setInvalid(boolean invalid) {
        this.invalid = invalid;
        if (isInvalid()) {
            clear();
        }
    }
}
