Пример #1
0
 /**
  * Writes the message envelope for this message, using the <code>:sender</code> and <code>
  * :receiver</code> message slots to fill in the envelope.
  *
  * @see jade.lang.acl#setEnvelope(Envelope e)
  * @see jade.lang.acl#getEnvelope()
  */
 public void setDefaultEnvelope() {
   messageEnvelope = new Envelope();
   messageEnvelope.setFrom(source);
   // #MIDP_EXCLUDE_BEGIN
   Iterator it = dests.iterator();
   // #MIDP_EXCLUDE_END
   /*#MIDP_INCLUDE_BEGIN
   Iterator it = new EnumIterator(dests.elements());
   #MIDP_INCLUDE_END*/
   while (it.hasNext()) messageEnvelope.addTo((AID) it.next());
   // #MIDP_EXCLUDE_BEGIN
   messageEnvelope.setAclRepresentation(StringACLCodec.NAME);
   // #MIDP_EXCLUDE_END
   messageEnvelope.setDate(new Date());
 }
Пример #2
0
 /**
  * create a new ACLMessage that is a reply to this message. In particular, it sets the following
  * parameters of the new message: receiver, language, ontology, protocol, conversation-id,
  * in-reply-to, reply-with. The programmer needs to set the communicative-act and the content. Of
  * course, if he wishes to do that, he can reset any of the fields.
  *
  * @return the ACLMessage to send as a reply
  */
 public ACLMessage createReply() {
   ACLMessage m = new ACLMessage(getPerformative());
   Iterator it = getAllReplyTo();
   while (it.hasNext()) m.addReceiver((AID) it.next());
   if ((reply_to == null) || reply_to.isEmpty()) m.addReceiver(getSender());
   m.setLanguage(getLanguage());
   m.setOntology(getOntology());
   m.setProtocol(getProtocol());
   m.setInReplyTo(getReplyWith());
   if (source != null) m.setReplyWith(source.getName() + java.lang.System.currentTimeMillis());
   else m.setReplyWith("X" + java.lang.System.currentTimeMillis());
   m.setConversationId(getConversationId());
   // Copy only well defined user-def-params
   String trace = getUserDefinedParameter(TRACE);
   if (trace != null) {
     m.addUserDefinedParameter(TRACE, trace);
   }
   // #CUSTOM_EXCLUDE_BEGIN
   // Set the Aclrepresentation of the reply message to the aclrepresentation of the sent message
   if (messageEnvelope != null) {
     m.setDefaultEnvelope();
     String aclCodec = messageEnvelope.getAclRepresentation();
     if (aclCodec != null) m.getEnvelope().setAclRepresentation(aclCodec);
   } else m.setEnvelope(null);
   // #CUSTOM_EXCLUDE_END
   return m;
 }
Пример #3
0
 /**
  * retrieve the whole list of intended receivers for this message.
  *
  * @return An Iterator over all the intended receivers of this message taking into account the
  *     Envelope ":intended-receiver" first, the Envelope ":to" second and the message ":receiver"
  *     last.
  */
 public Iterator getAllIntendedReceiver() {
   Iterator it = null;
   // #CUSTOM_EXCLUDE_BEGIN
   Envelope env = getEnvelope();
   if (env != null) {
     it = env.getAllIntendedReceiver();
     if (!it.hasNext()) {
       // The ":intended-receiver" field is empty --> try with the ":to" field
       it = env.getAllTo();
     }
   }
   // #CUSTOM_EXCLUDE_END
   if (it == null || !it.hasNext()) {
     // Both the ":intended-receiver" and the ":to" fields are empty -->
     // Use the ACLMessage receivers
     it = getAllReceiver();
   }
   return it;
 }
Пример #4
0
  // #MIDP_EXCLUDE_BEGIN
  public synchronized Object clone() {

    ACLMessage result;

    try {
      result = (ACLMessage) super.clone();
      result.persistentID = null;
      if (source != null) {
        result.source = (AID) source.clone();
      }

      // Deep clone receivers
      if (dests != null) {
        result.dests = new ArrayList(dests.size());
        Iterator it = dests.iterator();
        while (it.hasNext()) {
          AID id = (AID) it.next();
          result.dests.add(id.clone());
        }
      }

      // Deep clone reply_to
      if (reply_to != null) {
        result.reply_to = new ArrayList(reply_to.size());
        Iterator it = reply_to.iterator();
        while (it.hasNext()) {
          AID id = (AID) it.next();
          result.reply_to.add(id.clone());
        }
      }

      // Deep clone user-def-properties if present
      if (userDefProps != null) result.userDefProps = (Properties) userDefProps.clone();
      // Deep clone envelope if present
      if (messageEnvelope != null) result.messageEnvelope = (Envelope) messageEnvelope.clone();
    } catch (CloneNotSupportedException cnse) {
      throw new InternalError(); // This should never happen
    }

    return result;
  }
Пример #5
0
 public final AID getSender() {
   if (msg != null) return msg.getSender();
   else if (env != null) return env.getFrom();
   else return null;
 }