org.gwt4e.sema4g.client.context.commands.proxies.SeMa4gRequestCallbackProxy.java Source code

Java tutorial

Introduction

Here is the source code for org.gwt4e.sema4g.client.context.commands.proxies.SeMa4gRequestCallbackProxy.java

Source

/*
 * Copyright 2014 Frank Hossfeld
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

package org.gwt4e.sema4g.client.context.commands.proxies;

import com.google.gwt.http.client.Request;
import com.google.gwt.http.client.RequestCallback;
import com.google.gwt.http.client.Response;
import org.gwt4e.sema4g.client.context.commands.SeMa4gRcpCommand;

public class SeMa4gRequestCallbackProxy implements SeMa4gProxy, RequestCallback {

    private final RequestCallback asyncCallback;
    /* execution command of this proxy */
    private SeMa4gRcpCommand command;

    //------------------------------------------------------------------------------

    public SeMa4gRequestCallbackProxy(SeMa4gRcpCommand command, RequestCallback asyncCallback) {
        super();
        this.command = command;
        this.asyncCallback = asyncCallback;
    }

    //------------------------------------------------------------------------------

    @Override
    public void onResponseReceived(Request request, Response response) {
        // do the default handling
        asyncCallback.onResponseReceived(request, response);
        // do the SeMa4g handling
        command.onSuccess();
    }

    @Override
    public void onError(Request request, Throwable exception) {
        // do the default handling
        asyncCallback.onError(request, exception);
        // do the SeMa4g handling
        command.onFailure(exception);
    }
}