1.1 --- a/src/java/isac/util/InformationProcessor.java Mon Aug 30 18:57:59 2004 +0200
1.2 +++ b/src/java/isac/util/InformationProcessor.java Mon Aug 30 18:57:59 2004 +0200
1.3 @@ -1,8 +1,5 @@
1.4 /*
1.5 * Created on Aug 16, 2003
1.6 - *
1.7 - * To change the template for this generated file go to
1.8 - * Window>Preferences>Java>Code Generation>Code and Comments
1.9 */
1.10 package isac.util;
1.11
1.12 @@ -19,179 +16,183 @@
1.13
1.14 import org.apache.xmlrpc.XmlRpcClient;
1.15 import org.apache.xmlrpc.XmlRpcException;
1.16 +
1.17 /**
1.18 - * @author gismo
1.19 - *
1.20 - * The InformationProcessor builds the bridge between BrowserFrontend
1.21 - * and BrowserDialog. It encapsulates all tasks regarding communication and
1.22 - * connects to the proper dialog-modules.
1.23 + * @author Andreas Griesmayer
1.24 *
1.25 - * Because the final communication-protocol is not fixed yet, it provides methods
1.26 - * to communicate via RMI as well as XML-RPC
1.27 + * The InformationProcessor builds the bridge between BrowserFrontend and
1.28 + * BrowserDialog. It encapsulates all tasks regarding communication and connects
1.29 + * to the proper dialog-modules.
1.30 + *
1.31 + * Because the final communication-protocol is not fixed yet, it provides
1.32 + * methods to communicate via RMI as well as XML-RPC
1.33 */
1.34 public class InformationProcessor {
1.35
1.36 -/**
1.37 - * Performes an login on the session dialog using the XML-RPC protocol. It assumes that the
1.38 - * SessionDialog is running its XML-RPC-handler on port 1050 of the local machine.
1.39 - *
1.40 - * @param username username of the user who wants to login.
1.41 - * @param password corresponding password for the user.
1.42 - * @return the id of the current sesson the user logged in or null if the login did not succeed
1.43 - * @throws NullPointerException carrying the error-message if an communication error occured.
1.44 - */
1.45 - static protected String xmlLogin(String username, String password){
1.46 - try{
1.47 - XmlRpcClient sdialog = new XmlRpcClient("http://localhost:1050");
1.48 - Vector params = new Vector();
1.49 - params.add(username);
1.50 - params.add(password);
1.51 - Vector response = (Vector) sdialog.execute("SDialog.login", params);
1.52 - if(response.size()>0)
1.53 - return (String)response.elementAt(0);
1.54 - }catch(MalformedURLException e) {
1.55 - throw new NullPointerException(getErrorXML("Sorry, MalformedURLException while accessing the SDialog to login - is the SDialog runnig ?"+e.getMessage()));
1.56 - } catch (XmlRpcException e) {
1.57 - throw new NullPointerException(getErrorXML("Sorry, XmlRpcException while accessing the SDialog to login - is the SDialog runnig ?"+e.getMessage()));
1.58 - } catch (IOException e) {
1.59 - throw new NullPointerException(getErrorXML("Sorry, IOException while accessing the SDialog to login - is the SDialog runnig ?"+e.getMessage()));
1.60 + /**
1.61 + * Performes an login on the session dialog using the XML-RPC protocol. It
1.62 + * assumes that the SessionDialog is running its XML-RPC-handler on port
1.63 + * 1050 of the local machine.
1.64 + *
1.65 + * @param username
1.66 + * username of the user who wants to login.
1.67 + * @param password
1.68 + * corresponding password for the user.
1.69 + * @return the id of the current sesson the user logged in or null if the
1.70 + * login did not succeed
1.71 + * @throws NullPointerException
1.72 + * carrying the error-message if an communication error occured.
1.73 + */
1.74 + static protected String xmlLogin(String username, String password) {
1.75 + try {
1.76 + XmlRpcClient sdialog = new XmlRpcClient("http://localhost:1050");
1.77 + Vector params = new Vector();
1.78 + params.add(username);
1.79 + params.add(password);
1.80 + Vector response = (Vector) sdialog.execute("SDialog.login", params);
1.81 + if (response.size() > 0)
1.82 + return (String) response.elementAt(0);
1.83 + } catch (MalformedURLException e) {
1.84 + throw new NullPointerException(
1.85 + getErrorXML("Sorry, MalformedURLException while accessing the SDialog to login - is the SDialog runnig ?"
1.86 + + e.getMessage()));
1.87 + } catch (XmlRpcException e) {
1.88 + throw new NullPointerException(
1.89 + getErrorXML("Sorry, XmlRpcException while accessing the SDialog to login - is the SDialog runnig ?"
1.90 + + e.getMessage()));
1.91 + } catch (IOException e) {
1.92 + throw new NullPointerException(
1.93 + getErrorXML("Sorry, IOException while accessing the SDialog to login - is the SDialog runnig ?"
1.94 + + e.getMessage()));
1.95 + }
1.96 + return null;
1.97 }
1.98 - return null;
1.99 - }
1.100
1.101 -/**
1.102 - * Performes a login on the Session dialog using RMI. It assumes the SessionDialog to be found
1.103 - * at //localhost/isac-ObjectManager
1.104 - *
1.105 - * @param username username of the user who wants to login.
1.106 - * @param password corresponding password for the user.
1.107 - * @return the id of the current sesson the user logged in or null if the login did not succeed
1.108 - * @throws NullPointerException carrying the error-message if an communication error occured.
1.109 - */
1.110 - static public String login(String username, String password){
1.111 + /**
1.112 + * Performes a login on the Session dialog using RMI. It assumes the
1.113 + * SessionDialog to be found at //localhost/isac-ObjectManager
1.114 + *
1.115 + * @param username
1.116 + * username of the user who wants to login.
1.117 + * @param password
1.118 + * corresponding password for the user.
1.119 + * @return the id of the current sesson the user logged in or null if the
1.120 + * login did not succeed
1.121 + * @throws NullPointerException
1.122 + * carrying the error-message if an communication error occured.
1.123 + */
1.124 + static public String login(String username, String password) {
1.125 SDialog sd = getSDialog();
1.126 try {
1.127 /* LK 04.08.27 */
1.128 //if username != pwd -> empty Vector
1.129 - Vector v = sd.login(username,password);
1.130 + Vector v = sd.login(username, password);
1.131 if (v.size() == 0) {
1.132 return null;
1.133 } else {
1.134 - return (String)v.elementAt(0);
1.135 + return (String) v.elementAt(0);
1.136 }
1.137 } catch (RemoteException e) {
1.138 - throw new NullPointerException(getErrorXML("Sorry, RemoteEcxeption while accessing the SDialog to login - is the SDialog runnig ?"+e.getMessage()));
1.139 + throw new NullPointerException(
1.140 + getErrorXML("Sorry, RemoteEcxeption while accessing the SDialog to login - is the SDialog runnig ?"
1.141 + + e.getMessage()));
1.142 }
1.143 }
1.144 -
1.145 - public static BDialog getBDialog(String session){
1.146 +
1.147 + public static BDialog getBDialog(String session) {
1.148 String name = "//localhost/isac-ObjectManager";
1.149 - try{
1.150 - System.out.println("connect to ObjectManager"+name);
1.151 + try {
1.152 + System.out.println("connect to ObjectManager" + name);
1.153 Object lookup = Naming.lookup(name);
1.154 - return ((OManager)lookup).getBrowserDialog(session);
1.155 - }
1.156 - catch(RemoteException exc){
1.157 - System.err.println("no rmiregistry runing on server "+name+
1.158 - " no connection possible --- try later");
1.159 + return ((OManager) lookup).getBrowserDialog(session);
1.160 + } catch (RemoteException exc) {
1.161 + System.err.println("no rmiregistry runing on server " + name
1.162 + + " no connection possible --- try later");
1.163 System.err.println("serverCom exception: " + exc.getMessage());
1.164 - }
1.165 - catch(NotBoundException exc){
1.166 - System.err.println("servercom: notboundexc: "+ exc.getMessage());
1.167 + } catch (NotBoundException exc) {
1.168 + System.err.println("servercom: notboundexc: " + exc.getMessage());
1.169 System.err.println("server not found - try to connect to Proxy");
1.170 - }
1.171 - catch(java.net.MalformedURLException exc){
1.172 - System.err.println("servercom: MalformedURLException: "+ exc.getMessage());
1.173 + } catch (java.net.MalformedURLException exc) {
1.174 + System.err.println("servercom: MalformedURLException: "
1.175 + + exc.getMessage());
1.176 exc.printStackTrace();
1.177 }
1.178 return null;
1.179 }
1.180
1.181 - public static SDialog getSDialog(){
1.182 - String name= "//localhost/isac-ObjectManager";
1.183 - try {
1.184 - System.out.println("connect to ObjectManager: "+name);
1.185 - Object lookup = Naming.lookup(name);
1.186 - return ((OManager) lookup).getSessionDialog();
1.187 + public static SDialog getSDialog() {
1.188 + String name = "//localhost/isac-ObjectManager";
1.189 + try {
1.190 + System.out.println("connect to ObjectManager: " + name);
1.191 + Object lookup = Naming.lookup(name);
1.192 + return ((OManager) lookup).getSessionDialog();
1.193 + } catch (RemoteException exc) {
1.194 + System.err.println("no rmiregistry runing on server " + name
1.195 + + " no connection possible --- try later");
1.196 + System.err.println("serverCom exception: " + exc.getMessage());
1.197 + } catch (NotBoundException exc) {
1.198 + System.err.println("servercom: notboundexc: " + exc.getMessage());
1.199 + System.err.println("server not found - try to connect to Proxy");
1.200 + } catch (java.net.MalformedURLException exc) {
1.201 + System.err.println("servercom: MalformedURLException: "
1.202 + + exc.getMessage());
1.203 + exc.printStackTrace();
1.204 + }
1.205 + return null;
1.206 }
1.207 - catch(RemoteException exc){
1.208 - System.err.println("no rmiregistry runing on server "+name+
1.209 - " no connection possible --- try later");
1.210 - System.err.println("serverCom exception: " + exc.getMessage());
1.211 - }
1.212 - catch(NotBoundException exc){
1.213 - System.err.println("servercom: notboundexc: "+ exc.getMessage());
1.214 - System.err.println("server not found - try to connect to Proxy");
1.215 - }
1.216 - catch(java.net.MalformedURLException exc){
1.217 - System.err.println("servercom: MalformedURLException: "+ exc.getMessage());
1.218 - exc.printStackTrace();
1.219 - }
1.220 - return null;
1.221 -}
1.222
1.223 -/*
1.224 - static protected String oldloadString(String function, Vector parameter){
1.225 - XmlRpcClient bdialog;
1.226 - String xmlsource="";
1.227 - try {
1.228 - bdialog = new XmlRpcClient("http://localhost:1040");
1.229 - Vector result = (Vector) bdialog.execute(function, parameter);
1.230 - xmlsource = (String)result.firstElement();
1.231 - } catch (MalformedURLException e) {
1.232 - e.printStackTrace();
1.233 - } catch (XmlRpcException e) {
1.234 - e.printStackTrace();
1.235 - } catch (IOException e) {
1.236 - e.printStackTrace();
1.237 - }
1.238 - return xmlsource;
1.239 - }
1.240 -*/
1.241 -/*
1.242 - static protected Vector oldloadVector(String function, Vector parameter){
1.243 - Vector return_vect=new Vector();
1.244 - XmlRpcClient bdialog;
1.245 - String xmlsource="";
1.246 - try {
1.247 - bdialog = new XmlRpcClient("http://localhost:1040");
1.248 - return_vect = (Vector) bdialog.execute(function, parameter);
1.249 - } catch (MalformedURLException e) {
1.250 - e.printStackTrace();
1.251 - } catch (XmlRpcException e) {
1.252 - e.printStackTrace();
1.253 - } catch (IOException e) {
1.254 - e.printStackTrace();
1.255 - }
1.256 - return return_vect;
1.257 - }
1.258 -*/
1.259 + /*
1.260 + * static protected String oldloadString(String function, Vector parameter){
1.261 + * XmlRpcClient bdialog; String xmlsource=""; try { bdialog = new
1.262 + * XmlRpcClient("http://localhost:1040"); Vector result = (Vector)
1.263 + * bdialog.execute(function, parameter); xmlsource =
1.264 + * (String)result.firstElement(); } catch (MalformedURLException e) {
1.265 + * e.printStackTrace(); } catch (XmlRpcException e) { e.printStackTrace(); }
1.266 + * catch (IOException e) { e.printStackTrace(); } return xmlsource; }
1.267 + */
1.268 + /*
1.269 + * static protected Vector oldloadVector(String function, Vector parameter){
1.270 + * Vector return_vect=new Vector(); XmlRpcClient bdialog; String
1.271 + * xmlsource=""; try { bdialog = new XmlRpcClient("http://localhost:1040");
1.272 + * return_vect = (Vector) bdialog.execute(function, parameter); } catch
1.273 + * (MalformedURLException e) { e.printStackTrace(); } catch (XmlRpcException
1.274 + * e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); }
1.275 + * return return_vect; }
1.276 + */
1.277
1.278 -/**
1.279 - * Loads the hierarchy for the information-type <code>type</type>
1.280 - * @param session session to identify on the SessionDialog
1.281 - * @param type type of the hierarchy to load
1.282 - * @return the requested hierarchy in its XML-representation, in case of an RemoteException, a XML-code
1.283 - * carrying the error-message is returned
1.284 - */
1.285 - static public String loadHierarchy(String session, String type){
1.286 + /**
1.287 + * Loads the hierarchy for the information-type <code>type</type>
1.288 + * @param session session to identify on the SessionDialog
1.289 + * @param type type of the hierarchy to load
1.290 + * @return the requested hierarchy in its XML-representation, in case of an RemoteException, a XML-code
1.291 + * carrying the error-message is returned
1.292 + */
1.293 + static public String loadHierarchy(String session, String type) {
1.294 BDialog bd = getBDialog(session);
1.295 try {
1.296 return bd.loadHierarchy(type);
1.297 } catch (RemoteException e) {
1.298 - return getErrorXML("Sorry, RemoteEcxeption while accessing the BDialog to login - is the BDialog runnig ?"+e.getMessage());
1.299 + return getErrorXML("Sorry, RemoteEcxeption while accessing the BDialog to login - is the BDialog runnig ?"
1.300 + + e.getMessage());
1.301 }
1.302 }
1.303
1.304 /**
1.305 * Loads binary files from the KE-Base
1.306 - * @param session session to identify on the SessionDialog
1.307 - * @param type to identify the location of the binary file. An id has only to be unique within a type, although
1.308 - * a globally unique id should be used.
1.309 - * @param content_id Id of the binary-file to load
1.310 - * @return the requested binary-file as byte-array, in case of an RemoteException, an empty array is returned
1.311 + *
1.312 + * @param session
1.313 + * session to identify on the SessionDialog
1.314 + * @param type
1.315 + * to identify the location of the binary file. An id has only to
1.316 + * be unique within a type, although a globally unique id should
1.317 + * be used.
1.318 + * @param content_id
1.319 + * Id of the binary-file to load
1.320 + * @return the requested binary-file as byte-array, in case of an
1.321 + * RemoteException, an empty array is returned
1.322 */
1.323 - static public byte[] loadBinary(String session, String type, String content_id){
1.324 + static public byte[] loadBinary(String session, String type,
1.325 + String content_id) {
1.326 BDialog bd = getBDialog(session);
1.327 try {
1.328 return bd.loadBinary(type, content_id);
1.329 @@ -199,107 +200,121 @@
1.330 return new byte[0];
1.331 }
1.332 }
1.333 - static public String loadXML(String session, String type, Vector idvect){
1.334 +
1.335 + static public String loadXML(String session, String type, Vector idvect) {
1.336 BDialog bd = getBDialog(session);
1.337 - try{
1.338 + try {
1.339 return bd.loadContent(type, idvect);
1.340 - } catch(RemoteException e){
1.341 + } catch (RemoteException e) {
1.342 return getErrorXML("Sorry, RemoteException while accessing the BDialog to fetch your content");
1.343 }
1.344 }
1.345
1.346 /**
1.347 * Loads content-files from the KE-Base
1.348 - * @param session session to identify on the SessionDialog
1.349 - * @param type to identify the location of the KE-Object. An id has only to be unique within a type, although
1.350 - * a globally unique id should be used.
1.351 - * @param content_id Id of the KE-Object to load
1.352 - * @return the requested KE-Object in its XML-representation, in case of an RemoteException, a XML-code
1.353 - * carrying the error-message is returned
1.354 + *
1.355 + * @param session
1.356 + * session to identify on the SessionDialog
1.357 + * @param type
1.358 + * to identify the location of the KE-Object. An id has only to
1.359 + * be unique within a type, although a globally unique id should
1.360 + * be used.
1.361 + * @param content_id
1.362 + * Id of the KE-Object to load
1.363 + * @return the requested KE-Object in its XML-representation, in case of an
1.364 + * RemoteException, a XML-code carrying the error-message is
1.365 + * returned
1.366 */
1.367 - static public String loadXML(String session, String type, String content_id){
1.368 + static public String loadXML(String session, String type, String content_id) {
1.369 BDialog bd = getBDialog(session);
1.370 try {
1.371 return bd.loadContent(type, content_id);
1.372 } catch (RemoteException e) {
1.373 - return getErrorXML("Sorry, RemoteException while accessing the BDialog to fetch your file \""+content_id+"\" is the BDialog running?");
1.374 + return getErrorXML("Sorry, RemoteException while accessing the BDialog to fetch your file \""
1.375 + + content_id + "\" is the BDialog running?");
1.376 }
1.377 }
1.378
1.379 /**
1.380 - * Evaluates the requested content in the given worksheet using the BrowserDialog
1.381 - * @param session session to identify on the SessionDialog
1.382 - * @param type to identify the location of the KE-Object. An id has only to be unique within a type, although
1.383 - * a globally unique id should be used.
1.384 - * @param content_id Id of the KE-Object to load
1.385 - * @param wd_id id of the worksheet the contanct for evaluating
1.386 - * @return the requested KE-Object in its XML-representation, in case of an RemoteException, a XML-code
1.387 - * carrying the error-message is returned
1.388 + * Evaluates the requested content in the given worksheet using the
1.389 + * BrowserDialog
1.390 + *
1.391 + * @param session
1.392 + * session to identify on the SessionDialog
1.393 + * @param type
1.394 + * to identify the location of the KE-Object. An id has only to
1.395 + * be unique within a type, although a globally unique id should
1.396 + * be used.
1.397 + * @param content_id
1.398 + * Id of the KE-Object to load
1.399 + * @param wd_id
1.400 + * id of the worksheet the contanct for evaluating
1.401 + * @return the requested KE-Object in its XML-representation, in case of an
1.402 + * RemoteException, a XML-code carrying the error-message is
1.403 + * returned
1.404 * @see BDialog#evaluateContent
1.405 */
1.406 - static public String evaluateXML(String session, String type, String content_id, String wd_id){
1.407 + static public String evaluateXML(String session, String type,
1.408 + String content_id, String wd_id) {
1.409 BDialog bd = getBDialog(session);
1.410 try {
1.411 return bd.evaluateContent(type, content_id, wd_id);
1.412 } catch (RemoteException e) {
1.413 - return getErrorXML("Sorry, RemoteException while accessing the BDialog to evaluate \""+content_id+"\" is the BDialog running?");
1.414 - }
1.415 + return getErrorXML("Sorry, RemoteException while accessing the BDialog to evaluate \""
1.416 + + content_id + "\" is the BDialog running?");
1.417 + }
1.418 }
1.419 -
1.420 +
1.421 /*
1.422 - static protected Reader loadsKEObject(String function, Vector parameter){
1.423 - XmlRpcClient bdialog;
1.424 - String xmlsource="";
1.425 - try {
1.426 - bdialog = new XmlRpcClient("http://localhost:1040");
1.427 - Vector result = (Vector) bdialog.execute(function, parameter);
1.428 - if(result.size()>0)
1.429 - xmlsource = (String)result.firstElement();
1.430 - else
1.431 - xmlsource = "";
1.432 - } catch (MalformedURLException e) {
1.433 - return new StringReader(getErrorXML("Sorry, MalformedURLException while accessing the KEStore"));
1.434 - } catch (XmlRpcException e) {
1.435 - return new StringReader(getErrorXML("Sorry, XmlRpcException while accessing the KEStore"));
1.436 - } catch (IOException e) {
1.437 - return new StringReader(getErrorXML("Sorry, IOException while accessing the KEStore"));
1.438 - }
1.439 - return new StringReader(xmlsource);
1.440 - }
1.441 -*/
1.442 + * static protected Reader loadsKEObject(String function, Vector parameter){
1.443 + * XmlRpcClient bdialog; String xmlsource=""; try { bdialog = new
1.444 + * XmlRpcClient("http://localhost:1040"); Vector result = (Vector)
1.445 + * bdialog.execute(function, parameter); if(result.size()>0) xmlsource =
1.446 + * (String)result.firstElement(); else xmlsource = ""; } catch
1.447 + * (MalformedURLException e) { return new StringReader(getErrorXML("Sorry,
1.448 + * MalformedURLException while accessing the KEStore")); } catch
1.449 + * (XmlRpcException e) { return new StringReader(getErrorXML("Sorry,
1.450 + * XmlRpcException while accessing the KEStore")); } catch (IOException e) {
1.451 + * return new StringReader(getErrorXML("Sorry, IOException while accessing
1.452 + * the KEStore")); } return new StringReader(xmlsource); }
1.453 + */
1.454
1.455 -/**
1.456 - * Get the corresponding user for a session.
1.457 - * @param session_id id of the session to identify the user
1.458 - * @return username or null if an invalid sessionid was given
1.459 - * @throws NullPointerException carrying the error-message if an RemoteException occures.
1.460 - */
1.461 - public static String getUsername(String session_id){
1.462 + /**
1.463 + * Get the corresponding user for a session.
1.464 + *
1.465 + * @param session_id
1.466 + * id of the session to identify the user
1.467 + * @return username or null if an invalid sessionid was given
1.468 + * @throws NullPointerException
1.469 + * carrying the error-message if an RemoteException occures.
1.470 + */
1.471 + public static String getUsername(String session_id) {
1.472 SDialog sd = getSDialog();
1.473 try {
1.474 String username;
1.475 - if((username=sd.getUsername(session_id)).equals(""))
1.476 + if ((username = sd.getUsername(session_id)).equals(""))
1.477 return null;
1.478 return username;
1.479 } catch (RemoteException e) {
1.480 - throw new NullPointerException(getErrorXML("Sorry, RemoteException while accesing the SDialog - is it running ?"));
1.481 + throw new NullPointerException(
1.482 + getErrorXML("Sorry, RemoteException while accesing the SDialog - is it running ?"));
1.483 }
1.484 }
1.485
1.486 -
1.487 /**
1.488 * @param session_id
1.489 * @return
1.490 */
1.491 private static String xmlGetUsername(String session_id) {
1.492 XmlRpcClient bdialog;
1.493 - String xmlsource="";
1.494 - Vector parameter=new Vector();
1.495 + String xmlsource = "";
1.496 + Vector parameter = new Vector();
1.497 parameter.add(session_id);
1.498 try {
1.499 bdialog = new XmlRpcClient("http://localhost:1050");
1.500 - String result = (String) bdialog.execute("SDialog.getUsername", parameter);
1.501 - if(result.equals(""))
1.502 + String result = (String) bdialog.execute("SDialog.getUsername",
1.503 + parameter);
1.504 + if (result.equals(""))
1.505 return null;
1.506 return result;
1.507 } catch (MalformedURLException e) {
1.508 @@ -308,10 +323,11 @@
1.509 return getErrorXML("Sorry, XmlRpcException while accesing the SDialog - is it running ?");
1.510 } catch (IOException e) {
1.511 return getErrorXML("Sorry, IOException while accesing the SDialog - is it running ?");
1.512 - }
1.513 + }
1.514 }
1.515
1.516 private static String getErrorXML(String string) {
1.517 - return "<ERROR><DESCRIPTION> <h1> Error in file InformationPrecessor.java </h1>"+string+"</DESCRIPTION></ERROR>";
1.518 + return "<ERROR><DESCRIPTION> <h1> Error in file InformationPrecessor.java </h1>"
1.519 + + string + "</DESCRIPTION></ERROR>";
1.520 }
1.521 -}
1.522 +}
1.523 \ No newline at end of file