001    /**
002     *   GRANITE DATA SERVICES
003     *   Copyright (C) 2006-2013 GRANITE DATA SERVICES S.A.S.
004     *
005     *   This file is part of Granite Data Services.
006     *
007     *   Granite Data Services is free software; you can redistribute it and/or modify
008     *   it under the terms of the GNU Library General Public License as published by
009     *   the Free Software Foundation; either version 2 of the License, or (at your
010     *   option) any later version.
011     *
012     *   Granite Data Services is distributed in the hope that it will be useful, but
013     *   WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
014     *   FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License
015     *   for more details.
016     *
017     *   You should have received a copy of the GNU Library General Public License
018     *   along with this library; if not, see <http://www.gnu.org/licenses/>.
019     */
020    package org.granite.client.messaging.messages.responses;
021    
022    import java.io.IOException;
023    import java.io.ObjectInput;
024    import java.io.ObjectOutput;
025    import java.util.Map;
026    
027    /**
028     * @author Franck WOLFF
029     */
030    public final class ResultMessage extends AbstractResponseMessage {
031    
032            private Object result;
033            
034            public ResultMessage() {
035            }
036    
037            public ResultMessage(String clientId, String correlationId, Object result) {
038                    super(clientId, correlationId);
039                    
040                    this.result = result;
041            }
042    
043            public ResultMessage(
044                    String id,
045                    String clientId,
046                    long timestamp,
047                    long timeToLive,
048                    Map<String, Object> headers,
049                    String correlationId,
050                    Object result) {
051                    
052                    super(id, clientId, timestamp, timeToLive, headers, correlationId);
053                    
054                    this.result = result;
055            }
056    
057            @Override
058            public Type getType() {
059                    return Type.RESULT;
060            }
061    
062            @Override
063            public Object getData() {
064                    return result;
065            }
066    
067            public Object getResult() {
068                    return result;
069            }
070    
071            public void setResult(Object result) {
072                    this.result = result;
073            }
074    
075            @Override
076            public ResultMessage copy() {
077                    ResultMessage message = new ResultMessage();
078    
079                    super.copy(message);
080                    
081                    message.result = result;
082                    
083                    return message;
084            }
085    
086            @Override
087            public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
088                    super.readExternal(in);
089                    
090                    this.result = in.readObject();
091            }
092    
093            @Override
094            public void writeExternal(ObjectOutput out) throws IOException {
095                    super.writeExternal(out);
096                    
097                    out.writeObject(result);
098            }
099    
100            @Override
101            public StringBuilder toString(StringBuilder sb) {
102                    return super.toString(sb).append("\n    result=").append(result);
103            }
104    }