src/net/java/otr4j/OtrEngineImpl.java
changeset 933 ca323cff3ac9
parent 928 0ff0059f2ec3
--- a/src/net/java/otr4j/OtrEngineImpl.java	Mon Dec 06 01:06:44 2010 +0100
+++ b/src/net/java/otr4j/OtrEngineImpl.java	Tue Dec 07 22:57:56 2010 +0100
@@ -25,14 +25,14 @@
  */
 public class OtrEngineImpl implements OtrEngine {
 
-	public OtrEngineImpl(OtrEngineHost listener) {
-		if (listener == null)
+	public OtrEngineImpl(OtrEngineHost host) {
+		if (host == null)
 			throw new IllegalArgumentException("OtrEgineHost is required.");
 
-		this.setListener(listener);
+		this.setHost(host);
 	}
 
-	private OtrEngineHost listener;
+	private OtrEngineHost host;
 	private Map<SessionID, Session> sessions;
 
 	private Session getSession(SessionID sessionID) {
@@ -44,7 +44,7 @@
 			sessions = new Hashtable<SessionID, Session>();
 
 		if (!sessions.containsKey(sessionID)) {
-			Session session = new SessionImpl(sessionID, getListener());
+			Session session = new SessionImpl(sessionID, getHost());
 			sessions.put(sessionID, session);
 
 			session.addOtrEngineListener(new OtrEngineListener() {
@@ -54,64 +54,43 @@
 						l.sessionStatusChanged(sessionID);
 				}
 			});
-
-		}
-
-		return sessions.get(sessionID);
+			return session;
+		} else
+			return sessions.get(sessionID);
 	}
 
 	public SessionStatus getSessionStatus(SessionID sessionID) {
 		return this.getSession(sessionID).getSessionStatus();
 	}
 
-	public String transformReceiving(SessionID sessionID, String msgText) {
-		try {
-			return this.getSession(sessionID).transformReceiving(msgText);
-		} catch (OtrException e) {
-			listener.showError(sessionID, e.getMessage());
-			return null;
-		}
+	public String transformReceiving(SessionID sessionID, String msgText)
+			throws OtrException {
+		return this.getSession(sessionID).transformReceiving(msgText);
 	}
 
-	public String transformSending(SessionID sessionID, String msgText) {
-		try {
-			return this.getSession(sessionID).transformSending(msgText, null);
-		} catch (OtrException e) {
-			listener.showError(sessionID, e.getMessage());
-			return null;
-		}
+	public String transformSending(SessionID sessionID, String msgText)
+			throws OtrException {
+		return this.getSession(sessionID).transformSending(msgText, null);
+	}
+
+	public void endSession(SessionID sessionID) throws OtrException {
+		this.getSession(sessionID).endSession();
 	}
 
-	public void endSession(SessionID sessionID) {
-		try {
-			this.getSession(sessionID).endSession();
-		} catch (OtrException e) {
-			listener.showError(sessionID, e.getMessage());
-		}
+	public void startSession(SessionID sessionID) throws OtrException {
+		this.getSession(sessionID).startSession();
 	}
 
-	public void startSession(SessionID sessionID) {
-		try {
-			this.getSession(sessionID).startSession();
-		} catch (OtrException e) {
-			listener.showError(sessionID, e.getMessage());
-		}
+	private void setHost(OtrEngineHost host) {
+		this.host = host;
 	}
 
-	private void setListener(OtrEngineHost listener) {
-		this.listener = listener;
+	private OtrEngineHost getHost() {
+		return host;
 	}
 
-	private OtrEngineHost getListener() {
-		return listener;
-	}
-
-	public void refreshSession(SessionID sessionID) {
-		try {
-			this.getSession(sessionID).refreshSession();
-		} catch (OtrException e) {
-			listener.showError(sessionID, e.getMessage());
-		}
+	public void refreshSession(SessionID sessionID) throws OtrException {
+		this.getSession(sessionID).refreshSession();
 	}
 
 	public PublicKey getRemotePublicKey(SessionID sessionID) {
@@ -125,7 +104,6 @@
 			if (!listeners.contains(l))
 				listeners.add(l);
 		}
-
 	}
 
 	public void removeOtrEngineListener(OtrEngineListener l) {