Dr. Dobb's is part of the Informa Tech Division of Informa PLC

This site is operated by a business or businesses owned by Informa PLC and all copyright resides with them. Informa PLC's registered office is 5 Howick Place, London SW1P 1WG. Registered in England and Wales. Number 8860726.


Welcome Guest | Log In | Register | Benefits
Channels ▼
RSS

Java@Work | Who Are You, Anyway? (Web Techniques, Feb 2001)


// 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) { }
	}
    }
}

Related Reading


More Insights