// UserDB object
import java.io.IOException;
import javax.servlet.http.*;

abstract public class UserDB implements HttpSessionBindingListener {
    protected String user;
    protected String dir;
    protected boolean autosave = false;
    protected boolean dirty=false;
    public boolean getAutosave() { return autosave; }
    public void setAutoSave(boolean b) { autosave=b; }
    public String getUser() { return user; }
    public void setUser(String user) { this.user=user; }
    public String getDir() { return dir; }
    public void setDir(String dir) { this.dir=dir; }
    abstract public String getProperty(String key,String deflt);
    abstract public void writeProperty(String key,String value);
    abstract public void save() throws IOException;
    abstract public boolean create(String password) throws IOException;
    abstract public boolean load(String password);
// methods to manage sessions
    public void valueBound(HttpSessionBindingEvent event) {
	// no action
    }
    public void valueUnbound(HttpSessionBindingEvent event) {
	if (autosave && dirty) {
	    try {
		save();
		dirty=false;
	    }
	    catch (IOException e) { }
	}
    }
}
