/**
* This method puts into the envelope the missing information if required
*/
public void prepareEnvelope(ACLMessage msg, AID receiver, GenericMessage gmsg) {
Envelope env = msg.getEnvelope();
String defaultRepresentation = null;
if (myService.livesHere(receiver)) {
// The agent lives in the platform
if (env == null) {
// Nothing to do
return;
}
else {
defaultRepresentation = LEAPACLCodec.NAME;
}
}
else {
// The agent lives outside the platform
gmsg.setForeignReceiver(true);
if (env == null) {
msg.setDefaultEnvelope();
env = msg.getEnvelope();
}
else {
defaultRepresentation = StringACLCodec.NAME;
}
}
// If no ACL representation is set, use the default one ("LEAP" for
// local receivers and "String" for foreign receivers)
String rep = env.getAclRepresentation();
if(rep == null)
env.setAclRepresentation(defaultRepresentation);
// If no 'to' slot is present, copy the 'to' slot from the
// 'receiver' slot of the ACL message
Iterator itTo = env.getAllTo();
if(!itTo.hasNext()) {
Iterator itReceiver = msg.getAllReceiver();
while(itReceiver.hasNext())
env.addTo((AID)itReceiver.next());
}
// If no 'from' slot is present, copy the 'from' slot from the
// 'sender' slot of the ACL message
AID from = env.getFrom();
if(from == null) {
env.setFrom(msg.getSender());
}
// Set the 'date' slot to 'now' if not present already
Date d = env.getDate();
if(d == null)
env.setDate(new Date());
// Write 'intended-receiver' slot as per 'FIPA Agent Message
// Transport Service Specification': this ACC splits all
// multicasts, since JADE has already split them in the
// handleSend() method
env.clearAllIntendedReceiver();
env.addIntendedReceiver(receiver);
Long payloadLength = env.getPayloadLength();
if(payloadLength == null)
env.setPayloadLength(new Long(-1));
}