001    /*
002      GRANITE DATA SERVICES
003      Copyright (C) 2012 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    
021    package org.granite.client.messaging.messages.responses;
022    
023    import java.io.IOException;
024    import java.io.ObjectInput;
025    import java.io.ObjectOutput;
026    import java.util.Map;
027    
028    /**
029     * @author Franck WOLFF
030     */
031    public final class ResultMessage extends AbstractResponseMessage {
032    
033            private Object result;
034            
035            public ResultMessage() {
036            }
037    
038            public ResultMessage(String clientId, String correlationId, Object result) {
039                    super(clientId, correlationId);
040                    
041                    this.result = result;
042            }
043    
044            public ResultMessage(
045                    String id,
046                    String clientId,
047                    long timestamp,
048                    long timeToLive,
049                    Map<String, Object> headers,
050                    String correlationId,
051                    Object result) {
052                    
053                    super(id, clientId, timestamp, timeToLive, headers, correlationId);
054                    
055                    this.result = result;
056            }
057    
058            @Override
059            public Type getType() {
060                    return Type.RESULT;
061            }
062    
063            @Override
064            public Object getData() {
065                    return result;
066            }
067    
068            public Object getResult() {
069                    return result;
070            }
071    
072            public void setResult(Object result) {
073                    this.result = result;
074            }
075    
076            @Override
077            public ResultMessage copy() {
078                    ResultMessage message = new ResultMessage();
079    
080                    super.copy(message);
081                    
082                    message.result = result;
083                    
084                    return message;
085            }
086    
087            @Override
088            public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
089                    super.readExternal(in);
090                    
091                    this.result = in.readObject();
092            }
093    
094            @Override
095            public void writeExternal(ObjectOutput out) throws IOException {
096                    super.writeExternal(out);
097                    
098                    out.writeObject(result);
099            }
100    
101            @Override
102            public StringBuilder toString(StringBuilder sb) {
103                    return super.toString(sb).append("\n    result=").append(result);
104            }
105    }