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