Android Open Source - sony-camera-remote-java Base Response






From Project

Back to project page sony-camera-remote-java.

License

The source code is released under:

Apache License

If you think the Android project sony-camera-remote-java listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.praetoriandroid.cameraremote.rpc;
/*  w  w  w  .  j  a  v  a  2s.com*/
import java.util.Arrays;

/**
 * Base API call response class.
 * @param <Result> type of <code>result</code> array item. See 'Sony Camera Remote API Developer Guide' for more details.
 */
@SuppressWarnings("UnusedDeclaration")
public abstract class BaseResponse<Result> {

    public static final int ERROR_OK = 0; // WTF???
    public static final int ERROR_ANY = 1;
    public static final int ERROR_TIMEOUT = 2;
    public static final int ERROR_ILLEGAL_ARGUMENT = 3;
    public static final int ERROR_ILLEGAL_DATA_FORMAT = 4;
    public static final int ERROR_ILLEGAL_REQUEST = 5;
    public static final int ERROR_ILLEGAL_RESPONSE = 6;
    public static final int ERROR_ILLEGAL_STATE = 7;
    public static final int ERROR_ILLEGAL_TYPE = 8;
    public static final int ERROR_INDEX_OUT_OF_BOUNDS = 9;
    public static final int ERROR_NO_SUCH_ELEMENT = 10;
    public static final int ERROR_NO_SUCH_FIELD = 11;
    public static final int ERROR_NO_SUCH_METHOD = 12;
    public static final int ERROR_NULL_POINTER = 13;
    public static final int ERROR_UNSUPPORTED_VERSION = 14;
    public static final int ERROR_UNSUPPORTED_OPERATION = 15;
    public static final int ERROR_SHOOTING_FAIL = 40400;
    public static final int ERROR_CAMERA_NOT_READY = 40401;
    public static final int ERROR_ALREADY_RUNNING_POLLING_API = 40402;
    public static final int ERROR_STILL_CAPTURING_NOT_FINISHED = 40403;

    private Result[] result;

    private Result[] results;

    private String[] error;

    private int id;

    public void validate() throws ValidationException {
        if (result != null && results != null) {
            throw new ValidationException("Both 'result' and 'results' are not allowed");
        }

        if (getResult() != null && error != null) {
            throw new ValidationException("Both 'result[s]' and 'error' are not allowed");
        }

        if (getResult() == null && error == null) {
            throw new ValidationException("Both 'result[s]' and 'error' could not be null");
        }

        if (error != null) {
            if (error.length != 2) {
                throw new IllegalResultSizeException(2, error.length);
            }

            try {
                //noinspection ResultOfMethodCallIgnored
                Integer.parseInt(error[0]);
            } catch (NumberFormatException e) {
                throw new ValidationException("Illegal error code value: " + error[0]);
            }
        }
    }

    public boolean isOk() {
        return error == null;
    }

    /**
     * Returns error code or 0 if there is no valid error code.
     */
    public int getErrorCode() {
        if (error == null) {
            return 0;
        }

        if (error.length != 2) {
            return 0;
        }

        try {
            return Integer.parseInt(error[0]);
        } catch (NumberFormatException e) {
            return 0;
        }
    }

    protected Result[] getResult() {
        if (result == null) {
            return results;
        }
        return result;
    }

    @Override
    public String toString() {
        return Arrays.toString(getResult()) + '/' + Arrays.toString(error) + '[' + id + ']';
    }

}




Java Source Code List

com.praetoriandroid.cameraremote.BadHttpStatusException.java
com.praetoriandroid.cameraremote.DeviceDescription.java
com.praetoriandroid.cameraremote.HttpClient.java
com.praetoriandroid.cameraremote.InvalidDataFormatException.java
com.praetoriandroid.cameraremote.LiveViewDisconnectedException.java
com.praetoriandroid.cameraremote.LiveViewFetcher.java
com.praetoriandroid.cameraremote.Logger.java
com.praetoriandroid.cameraremote.ParseException.java
com.praetoriandroid.cameraremote.RpcClient.java
com.praetoriandroid.cameraremote.RpcException.java
com.praetoriandroid.cameraremote.ServiceNotSupportedException.java
com.praetoriandroid.cameraremote.SsdpClient.java
com.praetoriandroid.cameraremote.SsdpException.java
com.praetoriandroid.cameraremote.app.LiveView.java
com.praetoriandroid.cameraremote.app.MainActivity.java
com.praetoriandroid.cameraremote.app.Rpc.java
com.praetoriandroid.cameraremote.app.SelfTimerSelector.java
com.praetoriandroid.cameraremote.app.ThisApp.java
com.praetoriandroid.cameraremote.rpc.ActTakePictureRequest.java
com.praetoriandroid.cameraremote.rpc.ActTakePictureResponse.java
com.praetoriandroid.cameraremote.rpc.AwaitTakePictureRequest.java
com.praetoriandroid.cameraremote.rpc.BaseRequest.java
com.praetoriandroid.cameraremote.rpc.BaseResponse.java
com.praetoriandroid.cameraremote.rpc.CustomizableEntity.java
com.praetoriandroid.cameraremote.rpc.EventEntity.java
com.praetoriandroid.cameraremote.rpc.GetApplicationInfoRequest.java
com.praetoriandroid.cameraremote.rpc.GetApplicationInfoResponse.java
com.praetoriandroid.cameraremote.rpc.GetAvailableApiListRequest.java
com.praetoriandroid.cameraremote.rpc.GetAvailableApiListResponse.java
com.praetoriandroid.cameraremote.rpc.GetAvailableSelfTimerRequest.java
com.praetoriandroid.cameraremote.rpc.GetAvailableSelfTimerResponse.java
com.praetoriandroid.cameraremote.rpc.GetEventRequest.java
com.praetoriandroid.cameraremote.rpc.GetEventResponse.java
com.praetoriandroid.cameraremote.rpc.GetExposureModeRequest.java
com.praetoriandroid.cameraremote.rpc.GetMethodTypesRequest.java
com.praetoriandroid.cameraremote.rpc.GetMethodTypesResponse.java
com.praetoriandroid.cameraremote.rpc.GetSelfTimerRequest.java
com.praetoriandroid.cameraremote.rpc.GetSupportedSelfTimerRequest.java
com.praetoriandroid.cameraremote.rpc.GetSupportedSelfTimerResponse.java
com.praetoriandroid.cameraremote.rpc.GetVersionsRequest.java
com.praetoriandroid.cameraremote.rpc.GetVersionsResponse.java
com.praetoriandroid.cameraremote.rpc.IllegalResultSizeException.java
com.praetoriandroid.cameraremote.rpc.MethodTypesEntity.java
com.praetoriandroid.cameraremote.rpc.RpcMethod.java
com.praetoriandroid.cameraremote.rpc.SetSelfTimerRequest.java
com.praetoriandroid.cameraremote.rpc.SimpleResponse.java
com.praetoriandroid.cameraremote.rpc.StartLiveViewRequest.java
com.praetoriandroid.cameraremote.rpc.StartLiveViewResponse.java
com.praetoriandroid.cameraremote.rpc.StartMovieRecRequest.java
com.praetoriandroid.cameraremote.rpc.StartRecModeRequest.java
com.praetoriandroid.cameraremote.rpc.StopLiveviewRequest.java
com.praetoriandroid.cameraremote.rpc.StopMovieRecRequest.java
com.praetoriandroid.cameraremote.rpc.StopMovieRecResponse.java
com.praetoriandroid.cameraremote.rpc.StopRecModeRequest.java
com.praetoriandroid.cameraremote.rpc.ValidationException.java
com.praetoriandroid.cameraremote.rpc._DummyResponse.java
com.praetoriandroid.cameraremote.tool.Cache.java
com.praetoriandroid.cameraremote.tool.RemoteControl.java
com.praetoriandroid.widget.ItemViewCreator.java
com.praetoriandroid.widget.RadialFreeSpace.java
com.praetoriandroid.widget.RadialSelector.java