📄 aclmessage.java
字号:
the <code>getReplyByDate</code> should be used that returns a Date
*/
public String getReplyBy() {
if(reply_byInMillisec != 0)
return ISO8601.toString(new Date(reply_byInMillisec));
else
return null;
}
//#MIDP_EXCLUDE_END
/**
Reads <code>:reply-by</code> slot.
@return The value of <code>:reply-by</code>slot, as a
<code>Date</code> object.
@see jade.lang.acl.ACLMessage#setReplyByDate(Date).
*/
public Date getReplyByDate() {
if(reply_byInMillisec != 0)
return new Date(reply_byInMillisec);
else
return null;
}
/**
Reads <code>:protocol</code> slot.
@return The value of <code>:protocol</code>slot.
@see jade.lang.acl.ACLMessage#setProtocol(String).
*/
public String getProtocol() {
return protocol;
}
/**
Reads <code>:conversation-id</code> slot.
@return The value of <code>:conversation-id</code>slot.
@see jade.lang.acl.ACLMessage#setConversationId(String).
*/
public String getConversationId() {
return conversation_id;
}
/**
* Add a new user defined parameter to this ACLMessage.
* Notice that according to the FIPA specifications, the keyword of a
* user-defined parameter must not contain space inside.
* Note that the user does not need to (and shall not) add the prefix "X-" to the keyword.
* This is automatically added by the StringACLCodec.
* @param key the property key.
* @param value the property value
*/
public void addUserDefinedParameter(String key, String value) {
userDefProps = (userDefProps == null ? new Properties() : userDefProps);
userDefProps.setProperty(key,value);
}
/**
* Searches for the user defined parameter with the specified key.
* The method returns
* <code>null</code> if the parameter is not found.
*
* @param key the parameter key.
* @return the value in this ACLMessage with the specified key value.
*/
public String getUserDefinedParameter(String key){
if (userDefProps == null)
return null;
else
return userDefProps.getProperty(key);
}
/**
* get a clone of the data structure with all the user defined parameters
**/
public Properties getAllUserDefinedParameters() {
userDefProps = (userDefProps == null ? new Properties() : userDefProps);
return userDefProps;
}
/**
* Removes the key and its corresponding value from the list of user
* defined parameters in this ACLMessage.
* @param key the key that needs to be removed
@return true if the property has been found and removed, false otherwise
*/
public boolean removeUserDefinedParameter(String key) {
if (userDefProps == null)
return false;
else
return (userDefProps.remove(key) != null);
}
// #CUSTOM_EXCLUDE_BEGIN
/**
Attaches an envelope to this message. The envelope is used by the
<b><it>ACC</it></b> for inter-platform messaging.
@param e The <code>Envelope</code> object to attach to this
message.
@see jade.lang.acl#getEnvelope()
@see jade.lang.acl#setDefaultEnvelope()
*/
public void setEnvelope(Envelope e) {
messageEnvelope = e;
}
/**
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());
}
/**
Reads the envelope attached to this message, if any.
@return The envelope for this message.
@see jade.lang.acl#setEnvelope(Envelope e)
@see jade.lang.acl#setDefaultEnvelope()
*/
public Envelope getEnvelope() {
return messageEnvelope;
}
// #CUSTOM_EXCLUDE_END
//#MIDP_EXCLUDE_BEGIN
/**
Convert an ACL message to its string representation. This method
writes a representation of this <code>ACLMessage</code> into a
character string.
If the content is a bytesequence, then it is automatically converted
into Base64 encoding.
@return A <code>String</code> representing this message.
*/
public String toString(){
return StringACLCodec.toString(this);
}
//#MIDP_EXCLUDE_END
/**
Clone an <code>ACLMessage</code> object.
@return A copy of this <code>ACLMessage</code> object. The copy
must be casted back to <code>ACLMessage</code> type before being
used.
*/
//#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
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
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());
}
}
if (userDefProps != null)
result.userDefProps = (Properties)userDefProps.clone(); //Deep copy
if(messageEnvelope != null)
result.messageEnvelope = (Envelope)messageEnvelope.clone();
}
catch(CloneNotSupportedException cnse) {
throw new InternalError(); // This should never happen
}
return result;
}
//#MIDP_EXCLUDE_END
/*#MIDP_INCLUDE_BEGIN
public synchronized Object clone() {
ACLMessage result = new ACLMessage(NOT_UNDERSTOOD);
result.performative = performative;
result.source = source;
result.content = content;
result.byteSequenceContent = byteSequenceContent;
result.reply_with = reply_with;
result.in_reply_to = in_reply_to;
result.encoding = encoding;
result.language = language;
result.ontology = ontology;
result.reply_byInMillisec = reply_byInMillisec;
result.protocol = protocol;
result.conversation_id = conversation_id;
result.userDefProps = userDefProps;
//#CUSTOM_EXCLUDE_BEGIN
if(messageEnvelope != null) {
result.messageEnvelope = (Envelope)messageEnvelope.clone();
}
//#CUSTOM_EXCLUDE_END
result.dests = new Vector(dests.size());
for (int i=0; i<dests.size(); i++)
result.dests.addElement(dests.elementAt(i));
if (reply_to != null) {
result.reply_to = new Vector(reply_to.size());
for (int i=0; i<reply_to.size(); i++)
result.reply_to.addElement(reply_to.elementAt(i));
}
return result;
}
#MIDP_INCLUDE_END*/
/**
* Resets all the message slots.
*/
public void reset() {
source = null;
//#MIDP_EXCLUDE_BEGIN
dests.clear();
if (reply_to != null)
reply_to.clear();
//#MIDP_EXCLUDE_END
/*#MIDP_INCLUDE_BEGIN
dests.removeAllElements();
if (reply_to != null)
reply_to.removeAllElements();
#MIDP_INCLUDE_END*/
performative = NOT_UNDERSTOOD;
content = null;
byteSequenceContent = null;
reply_with = null;
in_reply_to = null;
encoding = null;
language = null;
ontology = null;
reply_byInMillisec = 0;
protocol = null;
conversation_id = null;
if (userDefProps != null) {
userDefProps.clear();
}
}
/**
* 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 = (ACLMessage)clone();
m.clearAllReceiver();
Iterator it = getAllReplyTo();
while (it.hasNext())
m.addReceiver((AID)it.next());
if ((reply_to == null) || reply_to.isEmpty())
m.addReceiver(getSender());
m.clearAllReplyTo();
m.setLanguage(getLanguage());
m.setOntology(getOntology());
m.setProtocol(getProtocol());
m.setSender(null);
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());
m.setReplyByDate(null);
m.setContent(null);
m.setEncoding(null);
//#CUSTOM_EXCLUDE_BEGIN
//Set the Aclrepresentation of the reply message to the aclrepresentation of the sent message
if (messageEnvelope != null)
{
m.setDefaultEnvelope(); // reset the envelope after having been cloned
String aclCodec= messageEnvelope.getAclRepresentation();
if (aclCodec != null)
m.getEnvelope().setAclRepresentation(aclCodec);
}
else
m.setEnvelope(null);
//#CUSTOM_EXCLUDE_END
return m;
}
/**
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;
}
//#MIDP_EXCLUDE_BEGIN
// For persistence service
private Long persistentID;
// For persistence service
private Long getPersistentID() {
return persistentID;
}
// For persistence service
private void setPersistentID(Long l) {
persistentID = l;
}
// For persistence service
private void setReceivers(ArrayList al) {
dests = al;
}
// For persistence service
private ArrayList getReceivers() {
return dests;
}
// For persistence service
private void setReplyTo(ArrayList al) {
reply_to = al;
}
// For persistence service
private ArrayList getReplyTo() {
return reply_to;
}
// For persistence service
private void setUserDefinedProperties(Serializable p) {
userDefProps = (Properties)p;
}
// For persistence service
private Serializable getUserDefinedProperties() {
return userDefProps;
}
//#MIDP_EXCLUDE_END
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -