From f26dc2ab9cb47bc7e903189bafbad8109d674e6c Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Thu, 26 Jun 2003 18:24:31 +0000 Subject: [PATCH] Adapters! We loves the OOP. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@2684 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- .../presents/util/ConfirmAdapter.java | 46 +++++++++++++++++++ .../presents/util/ResultAdapter.java | 46 +++++++++++++++++++ 2 files changed, 92 insertions(+) create mode 100644 src/java/com/threerings/presents/util/ConfirmAdapter.java create mode 100644 src/java/com/threerings/presents/util/ResultAdapter.java diff --git a/src/java/com/threerings/presents/util/ConfirmAdapter.java b/src/java/com/threerings/presents/util/ConfirmAdapter.java new file mode 100644 index 000000000..75dc57df2 --- /dev/null +++ b/src/java/com/threerings/presents/util/ConfirmAdapter.java @@ -0,0 +1,46 @@ +// +// $Id: ConfirmAdapter.java,v 1.1 2003/06/26 18:24:31 mdb Exp $ + +package com.threerings.presents.util; + +import com.samskivert.util.ResultListener; + +import com.threerings.presents.client.InvocationService.ConfirmListener; +import com.threerings.presents.data.InvocationCodes; +import com.threerings.presents.server.InvocationException; + +/** + * Adapts the response from a {@link ResultListener} to a {@link + * ConfirmListener} if the failure is an instance fo {@link + * InvocationException} the message will be passed on to the confirm + * listener, otherwise they will be provided with {@link + * InvocationCodes#INTERNAL_ERROR}. + */ +public class ConfirmAdapter implements ResultListener +{ + /** + * Creates an adapter with the supplied listener. + */ + public ConfirmAdapter (ConfirmListener listener) + { + _listener = listener; + } + + // documentation inherited from interface + public void requestCompleted (Object result) + { + _listener.requestProcessed(); + } + + // documentation inherited from interface + public void requestFailed (Exception cause) + { + if (cause instanceof InvocationException) { + _listener.requestFailed(cause.getMessage()); + } else { + _listener.requestFailed(InvocationCodes.INTERNAL_ERROR); + } + } + + protected ConfirmListener _listener; +} diff --git a/src/java/com/threerings/presents/util/ResultAdapter.java b/src/java/com/threerings/presents/util/ResultAdapter.java new file mode 100644 index 000000000..932a2c712 --- /dev/null +++ b/src/java/com/threerings/presents/util/ResultAdapter.java @@ -0,0 +1,46 @@ +// +// $Id: ResultAdapter.java,v 1.1 2003/06/26 18:24:31 mdb Exp $ + +package com.threerings.presents.util; + +import com.samskivert.util.ResultListener; + +import com.threerings.presents.client.InvocationService; +import com.threerings.presents.data.InvocationCodes; +import com.threerings.presents.server.InvocationException; + +/** + * Adapts the response from a {@link ResultListener} to an {@link + * InvocationService.ResultListener} if the failure is an instance fo + * {@link InvocationException} the message will be passed on to the result + * listener, otherwise they will be provided with {@link + * InvocationCodes#INTERNAL_ERROR}. + */ +public class ResultAdapter implements ResultListener +{ + /** + * Creates an adapter with the supplied listener. + */ + public ResultAdapter (InvocationService.ResultListener listener) + { + _listener = listener; + } + + // documentation inherited from interface + public void requestCompleted (Object result) + { + _listener.requestProcessed(result); + } + + // documentation inherited from interface + public void requestFailed (Exception cause) + { + if (cause instanceof InvocationException) { + _listener.requestFailed(cause.getMessage()); + } else { + _listener.requestFailed(InvocationCodes.INTERNAL_ERROR); + } + } + + protected InvocationService.ResultListener _listener; +}