all-050311a-beforeStart: of impl. userSettings
2 * Created on Jun 24, 2003
4 * To change the template for this generated file go to
5 * Window>Preferences>Java>Code Generation>Code and Comments
9 import isac.browserdialog.BDialog;
10 import isac.browserdialog.BrowserDialog;
11 import isac.gui.WindowApplication;
12 import isac.wsdialog.DGuide;
14 import java.io.Serializable;
15 import java.rmi.RemoteException;
16 import java.rmi.server.UnicastRemoteObject;
17 import java.util.HashMap;
18 import java.util.Iterator;
20 import java.util.Vector;
22 import org.apache.log4j.Logger;
23 import org.apache.xmlrpc.WebServer;
26 * @author Andreas Griesmayer
28 public class SessionDialog extends UnicastRemoteObject implements SDialog,
31 static Logger logger_ = Logger.getLogger(SessionDialog.class.getName());
33 //private Map dguide_map_ = new HashMap();//WN0503 unused
37 private static UMHandler um_handler_ = new UMHandler();
39 private static WSDHandler dg_handler_ = new WSDHandler();
41 private Map sessionmap_ = new HashMap();
43 private Map bdialogmap_ = new HashMap();
45 private static SessionDialog instance_;
47 private SessionDialog() throws RemoteException {
49 System.out.println("SessionDialog constructor");
53 * returns the instance of the singleton SessionDialog. The SessionDialog is
54 * responsible for maintaining all session-relevant informations like Browser-
55 * and WorksheetDialog and UserModel it provides its functions using RMI and
60 public static SessionDialog getInstance() {
61 if (instance_ == null) {
63 instance_ = new SessionDialog();
64 } catch (RemoteException e) {
71 // LK 04.09.02: user control with the UserManager
77 * @return vector with the sessionid as first and only element on success or
78 * empty vector on failure
80 public Vector login(String username, String pass) {
81 Vector return_val = new Vector();
82 User user = UserManager.getUser(username, pass);
83 String sessionid = null;
85 //WN050222 String sessionid;
86 if ((sessionid = (String) sessionmap_.get(username)) == null) {
87 sessionmap_.put(username, (sessionid = username + counter_++));
88 um_handler_.newUserModel(username, sessionid);
90 return_val.add(sessionid);
92 logger_.fatal("WA<-SH: login <- sessionid=" + sessionid);
98 * @return the user for the session id
100 public User getUser(String sessionId) {
106 * returns the name of the user which owns the given session.
109 * ID of the session for which the owner is requested
110 * @return the name of the owner of the session
111 * TODO.WN050311 encapsulate User#getName !!!
113 public String getUsername(String session) {
114 Iterator keys = sessionmap_.keySet().iterator();
116 while (keys.hasNext()) {
117 if (session.equals(sessionmap_.get((username = (String) keys.next())))) {
125 * create a new WSDialog and assign it to session <code>session</code>
127 public String openDGuide(String session) {
128 return dg_handler_.newDGuide(this, session);
131 public DGuide getDGuide(String dg_id) {
132 return (DGuide) dg_handler_.getDGuide(dg_id);
136 * used if the SessionDialog is used in standalone mode for testing-purposes.
137 * Registers its XML-RPC services on port 1050 of the local machine
142 public static void main(String[] args) {
146 private static void init() {
148 // Invoke me as <http://localhost:8080/RPC2>.
149 System.out.println("SessionDialog main");
150 WebServer server = new WebServer(1050);//WN0503 fixed port !
151 server.setParanoid(false);
152 // server.addHandler("sample", new JavaServer());
153 server.addHandler("SDialog", getInstance());
154 server.addHandler(" WSDialog", dg_handler_);
155 // LK 04.09.02: new temorary user management
156 //server.addHandler("UserModel", um_handler_);
158 } catch (Exception exception) {
159 System.err.println("SessionDialog: " + exception.toString());
164 public void finalize() {
165 System.out.println("SessionDialog finalize!");
169 * returns the BrowserDialog identified by <code>bdialog_id</code> or
173 * ID of the BrowserDialog to open.
174 * @return RMI-Object of the requested BrowserDialog
176 public BDialog getBDialog(String bdialog_id) {
177 BDialog browser_dialog = (BDialog) bdialogmap_.get(bdialog_id);
178 if (browser_dialog == null) {
180 bdialogmap_.put(bdialog_id, (browser_dialog = new BrowserDialog(
182 } catch (RemoteException e) {
183 System.err.println("unable to create new BrowserDialog for session "
188 return browser_dialog;