Package com.xmage.ws.json

Source Code of com.xmage.ws.json.ResponseBuilder

package com.xmage.ws.json;

import com.xmage.ws.model.DomainErrors;
import com.xmage.ws.resource.Resource;
import net.minidev.json.JSONObject;

public class ResponseBuilder {

    public static JSONObject build(int code) {
        JSONObject response = new JSONObject();
        response.put("code", code);

        return response;
    }

    public static JSONObject build(int code, String name, JSONObject jsonObject) {
        JSONObject response = new JSONObject();
        response.put("code", code);
        response.put(name, jsonObject);

        return response;
    }

    public static JSONObject build(Resource resource) {
        if (resource.getError() != DomainErrors.Errors.STATUS_OK.getCode()) {
            JSONObject response = ResponseBuilder.build(resource.getError());
            response.put("message", resource.getErrorMessage());
            return response;
        } else {
            JSONObject json = resource.getJSONBody();
            return ResponseBuilder.build(DomainErrors.Errors.STATUS_OK.getCode(), resource.getName(), json);
        }

    }

}
TOP

Related Classes of com.xmage.ws.json.ResponseBuilder

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.