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