📄 aclmessage.java
字号:
//#MIDP_EXCLUDE_END
/*#MIDP_INCLUDE_BEGIN
reply_to.removeAllElements();
#MIDP_INCLUDE_END*/
}
}
/**
* set the performative of this ACL message object to the passed constant.
* Remind to
* use the set of constants (i.e. <code> INFORM, REQUEST, ... </code>)
* defined in this class
*/
public void setPerformative(int perf) {
performative = perf;
}
/**
* Writes the <code>:content</code> slot. <em><b>Warning:</b> no
* checks are made to validate the slot value.</em> <p>
* <p>Notice that, in general, setting a String content and getting
* back a byte sequence content - or viceversa - does not return
* the same value, i.e. the following relation does not hold
* <code>
* getByteSequenceContent(setByteSequenceContent(getContent().getBytes()))
* is equal to getByteSequenceContent()
* </code>
* @param content The new value for the slot.
* @see jade.lang.acl.ACLMessage#getContent()
* @see jade.lang.acl.ACLMessage#setByteSequenceContent(byte[])
* @see jade.lang.acl.ACLMessage#setContentObject(Serializable s)
*/
public void setContent(String content) {
byteSequenceContent = null; //make to null the other variable
if (content != null) {
this.content = new StringBuffer(content);
}
else {
this.content = null;
}
}
/**
* Writes the <code>:content</code> slot. <em><b>Warning:</b> no
* checks are made to validate the slot value.</em> <p>
* <p>Notice that, in general, setting a String content and getting
* back a byte sequence content - or viceversa - does not return
* the same value, i.e. the following relation does not hold
* <code>
* getByteSequenceContent(setByteSequenceContent(getContent().getBytes()))
* is equal to getByteSequenceContent()
* </code>
* @param content The new value for the slot.
* @see jade.lang.acl.ACLMessage#setContent(String s)
* @see jade.lang.acl.ACLMessage#getByteSequenceContent()
* @see jade.lang.acl.ACLMessage#setContentObject(Serializable s)
*/
public void setByteSequenceContent(byte[] content) {
this.content = null; //make to null the other variable
byteSequenceContent = content;
}
//#MIDP_EXCLUDE_BEGIN
/**
* This method sets the content of this ACLMessage to a Java object.
* It is not FIPA compliant so its usage is not encouraged.
* For example:<br>
* <PRE>
* ACLMessage msg = new ACLMessage(ACLMessage.INFORM);
* Date d = new Date();
* try{
* msg.setContentObject(d);
* }catch(IOException e){}
* </PRE>
*
* @param s the object that will be used to set the content of the ACLMessage.
* @exception IOException if an I/O error occurs.
*/
public void setContentObject(java.io.Serializable s) throws IOException
{
ByteArrayOutputStream c = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(c);
oos.writeObject(s);
oos.flush();
setByteSequenceContent(c.toByteArray());
}
/**
* This method returns the content of this ACLMessage when they have
* been written via the method <code>setContentObject</code>.
* It is not FIPA compliant so its usage is not encouraged.
* For example to read Java objects from the content
* <PRE>
* ACLMessage msg = blockingReceive();
* try{
* Date d = (Date)msg.getContentObject();
* }catch(UnreadableException e){}
* </PRE>
*
* @return the object read from the content of this ACLMessage
* @exception UnreadableException when an error occurs during the decoding.
*/
public java.io.Serializable getContentObject() throws UnreadableException
{
try{
byte[] data = getByteSequenceContent();
if (data == null)
return null;
ObjectInputStream oin = new ObjectInputStream(new ByteArrayInputStream(data));
java.io.Serializable s = (java.io.Serializable)oin.readObject();
return s;
}
catch (java.lang.Error e) {
throw new UnreadableException(e.getMessage());
}
catch (IOException e1) {
throw new UnreadableException(e1.getMessage());
}
catch(ClassNotFoundException e2) {
throw new UnreadableException(e2.getMessage());
}
}
//#MIDP_EXCLUDE_END
/**
Writes the <code>:reply-with</code> slot. <em><b>Warning:</b> no
checks are made to validate the slot value.</em>
@param reply The new value for the slot.
@see jade.lang.acl.ACLMessage#getReplyWith()
*/
public void setReplyWith(String reply) {
reply_with = reply;
}
/**
Writes the <code>:in-reply-to</code> slot. <em><b>Warning:</b> no
checks are made to validate the slot value.</em>
@param reply The new value for the slot.
@see jade.lang.acl.ACLMessage#getInReplyTo()
*/
public void setInReplyTo(String reply) {
in_reply_to = reply;
}
/**
Writes the <code>:encoding</code> slot. <em><b>Warning:</b> no
checks are made to validate the slot value.</em>
@param str The new value for the slot.
@see jade.lang.acl.ACLMessage#getEncoding()
*/
public void setEncoding(String str) {
encoding = str;
}
/**
Writes the <code>:language</code> slot. <em><b>Warning:</b> no
checks are made to validate the slot value.</em>
@param str The new value for the slot.
@see jade.lang.acl.ACLMessage#getLanguage()
*/
public void setLanguage(String str) {
language = str;
}
/**
Writes the <code>:ontology</code> slot. <em><b>Warning:</b> no
checks are made to validate the slot value.</em>
@param str The new value for the slot.
@see jade.lang.acl.ACLMessage#getOntology()
*/
public void setOntology(String str) {
ontology = str;
}
/**
Writes the <code>:reply-by</code> slot. <em><b>Warning:</b> no
checks are made to validate the slot value.</em>
@param date The new value for the slot.
@see jade.lang.acl.ACLMessage#getReplyByDate()
*/
public void setReplyByDate(Date date) {
reply_byInMillisec = (date==null?0:date.getTime());
}
/**
Writes the <code>:protocol</code> slot. <em><b>Warning:</b> no
checks are made to validate the slot value.</em>
@param str The new value for the slot.
@see jade.lang.acl.ACLMessage#getProtocol()
*/
public void setProtocol( String str ) {
protocol = str;
}
/**
Writes the <code>:conversation-id</code> slot. <em><b>Warning:</b> no
checks are made to validate the slot value.</em>
@param str The new value for the slot.
@see jade.lang.acl.ACLMessage#getConversationId()
*/
public void setConversationId( String str ) {
conversation_id = str;
}
/**
Reads <code>:receiver</code> slot.
@return An <code>Iterator</code> containing the Agent IDs of the
receiver agents for this message.
*/
public Iterator getAllReceiver() {
//#MIDP_EXCLUDE_BEGIN
return dests.iterator();
//#MIDP_EXCLUDE_END
/*#MIDP_INCLUDE_BEGIN
return new EnumIterator(dests.elements());
#MIDP_INCLUDE_END*/
}
/**
Reads <code>:reply_to</code> slot.
@return An <code>Iterator</code> containing the Agent IDs of the
reply_to agents for this message.
*/
public Iterator getAllReplyTo() {
if (reply_to == null) {
return EmptyIterator.getInstance();
}
else {
//#MIDP_EXCLUDE_BEGIN
return reply_to.iterator();
//#MIDP_EXCLUDE_END
/*#MIDP_INCLUDE_BEGIN
return new EnumIterator(reply_to.elements());
#MIDP_INCLUDE_END*/
}
}
/**
Reads <code>:sender</code> slot.
@return The value of <code>:sender</code>slot.
@see jade.lang.acl.ACLMessage#setSender(AID).
*/
public AID getSender() {
return source;
}
/**
Returns the string corresponding to the integer for the performative
@return the string corresponding to the integer for the performative;
"NOT-UNDERSTOOD" if the integer is out of range.
*/
public static String getPerformative(int perf){
try {
return performatives[perf];
} catch (Exception e) {
return performatives[NOT_UNDERSTOOD];
}
}
/**
Returns the integer corresponding to the performative
@returns the integer corresponding to the performative; -1 otherwise
*/
public static int getInteger(String perf)
{
String tmp = perf.toUpperCase();
for (int i=0; i<performatives.length; i++)
if (performatives[i].equals(tmp))
return i;
return -1;
}
/**
* return the integer representing the performative of this object
* @return an integer representing the performative of this object
*/
public int getPerformative() {
return performative;
}
/**
* This method allows to check if the content of this ACLMessage
* is a byteSequence or a String
* @return true if it is a byteSequence, false if it is a String
**/
public boolean hasByteSequenceContent(){
return (byteSequenceContent != null);
}
/**
* Reads <code>:content</code> slot. <p>
* <p>Notice that, in general, setting a String content and getting
* back a byte sequence content - or viceversa - does not return
* the same value, i.e. the following relation does not hold
* <code>
* getByteSequenceContent(setByteSequenceContent(getContent().getBytes()))
* is equal to getByteSequenceContent()
* </code>
* @return The value of <code>:content</code> slot.
* @see jade.lang.acl.ACLMessage#setContent(String)
* @see jade.lang.acl.ACLMessage#getByteSequenceContent()
* @see jade.lang.acl.ACLMessage#getContentObject()
* @see java.io.ObjectInputStream
*/
public String getContent() {
if(content != null)
return new String(content);
else if (byteSequenceContent != null)
return new String(byteSequenceContent);
return null;
}
/**
* Reads <code>:content</code> slot. <p>
* <p>Notice that, in general, setting a String content and getting
* back a byte sequence content - or viceversa - does not return
* the same value, i.e. the following relation does not hold
* <code>
* getByteSequenceContent(setByteSequenceContent(getContent().getBytes()))
* is equal to getByteSequenceContent()
* </code>
* @return The value of <code>:content</code> slot.
* @see jade.lang.acl.ACLMessage#setContent(String)
* @see jade.lang.acl.ACLMessage#getContent()
* @see jade.lang.acl.ACLMessage#getContentObject()
* @see java.io.ObjectInputStream
*/
public byte[] getByteSequenceContent() {
if (content != null)
return content.toString().getBytes();
else if (byteSequenceContent != null)
return byteSequenceContent;
return null;
}
/**
Reads <code>:reply-with</code> slot.
@return The value of <code>:reply-with</code>slot.
@see jade.lang.acl.ACLMessage#setReplyWith(String).
*/
public String getReplyWith() {
return reply_with;
}
/**
Reads <code>:reply-to</code> slot.
@return The value of <code>:reply-to</code>slot.
@see jade.lang.acl.ACLMessage#setInReplyTo(String).
*/
public String getInReplyTo() {
return in_reply_to;
}
/**
Reads <code>:encoding</code> slot.
@return The value of <code>:encoding</code>slot.
@see jade.lang.acl.ACLMessage#setEncoding(String).
*/
public String getEncoding() {
return encoding;
}
/**
Reads <code>:language</code> slot.
@return The value of <code>:language</code>slot.
@see jade.lang.acl.ACLMessage#setLanguage(String).
*/
public String getLanguage() {
return language;
}
/**
Reads <code>:ontology</code> slot.
@return The value of <code>:ontology</code>slot.
@see jade.lang.acl.ACLMessage#setOntology(String).
*/
public String getOntology() {
return ontology;
}
//#MIDP_EXCLUDE_BEGIN
/**
Reads <code>:reply-by</code> slot.
@return The value of <code>:reply-by</code>slot, as a string.
@see jade.lang.acl.ACLMessage#getReplyByDate().
@deprecated Since the value of this slot is a Date by definition, then
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -