001/*******************************************************************************
002 * Copyright (c) 2017, 2018 Red Hat Inc
003 * All rights reserved. This program and the accompanying materials
004 * are made available under the terms of the Eclipse Public License v1.0
005 * which accompanies this distribution, and is available at
006 * http://www.eclipse.org/legal/epl-v10.html
007 *
008 * Contributors:
009 *     Jens Reimann - initial API and implementation
010 *******************************************************************************/
011package de.dentrassi.varlink.spi;
012
013import java.util.Map;
014
015import com.google.gson.JsonElement;
016import com.google.gson.JsonObject;
017
018public class CallResponse {
019
020    private JsonObject parameters;
021
022    private String error;
023
024    public void setParameters(final JsonObject parameters) {
025        this.parameters = parameters;
026    }
027
028    public JsonObject getParameters() {
029        return this.parameters;
030    }
031
032    public JsonElement getFirstParameter() {
033        return this.parameters.entrySet().iterator().next().getValue();
034    }
035
036    public void setError(final String error) {
037        this.error = error;
038    }
039
040    public String getError() {
041        return this.error;
042    }
043
044    public boolean isError() {
045        return this.error != null;
046    }
047
048    @Override
049    public String toString() {
050        final StringBuilder sb = new StringBuilder();
051        sb.append("[CallResponse - ");
052
053        if (isError()) {
054            sb.append("ERROR: ").append(this.error);
055        }
056
057        for (final Map.Entry<String, ?> entry : this.parameters.entrySet()) {
058            sb
059                    .append("\n'")
060                    .append(entry.getKey())
061                    .append("' -> '")
062                    .append(entry.getValue())
063                    .append("'");
064        }
065
066        sb.append("]");
067        return sb.toString();
068    }
069}