jadex.bridge.fipa.SFipa Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jadex-platform-bridge Show documentation
Show all versions of jadex-platform-bridge Show documentation
Jadex bridge is a base package for kernels and platforms, i.e., it is used by both and provides commonly used interfaces and classes for active components and their management.
package jadex.bridge.fipa;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import jadex.commons.SUtil;
import jadex.commons.collection.SCollection;
/**
* Helper class for JADE specific issues.
*/
public class SFipa
{
//-------- constants --------
/** The name of the fipa component management ontology. */
public static final String COMPONENT_MANAGEMENT_ONTOLOGY_NAME = "fipa-component-management";
/** The FIPA message type. */
public static final String MESSAGE_TYPE_NAME_FIPA = "fipa";
/** The FIPA AMS local component identifier. */
// public static final IFIPAComponentIdentifier AMS = new ComponentIdentifier("cms", true);
/** The FIPA DF local component identifier. */
// public static final IFIPAComponentIdentifier DF = new ComponentIdentifier("df", true);
/** The default df component name. */
public static final String DF_COMPONENT = "df";
// /** The (standard) DF service name. */
// public static final String DF_SERVICE = "df_service";
//
// /** The (standard) message service name. */
// public static final String MESSAGE_SERVICE = "message_service";
// Protocols
public static final String PROTOCOL_REQUEST = "fipa-request";
public static final String PROTOCOL_QUERY = "fipa-query" ;
public static final String PROTOCOL_REQUEST_WHEN = "fipa-request-when";
public static final String PROTOCOL_BROKERING = "fipa-brokering";
public static final String PROTOCOL_RECRUITING = "fipa-recruiting";
public static final String PROTOCOL_PROPOSE = "fipa-propose";
public static final String PROTOCOL_SUBSCRIBE = "fipa-subscribe";
public static final String PROTOCOL_ENGLISH_AUCTION = "fipa-auction-english";
public static final String PROTOCOL_DUTCH_AUCTION = "fipa-auction-dutch";
public static final String PROTOCOL_CONTRACT_NET = "fipa-contract-net";
public static final String PROTOCOL_ITERATED_CONTRACT_NET = "fipa-iterated-contract-net";
public static final String PROTOCOL_CANCEL_META = "fipa-cancel-meta";
/** The standard protocols. */
public static final Collection PROTOCOLS;
static
{
// cannot use hashset, as order is important for gui usage.
PROTOCOLS = SCollection.createArrayList();
PROTOCOLS.add(PROTOCOL_REQUEST);
PROTOCOLS.add(PROTOCOL_QUERY);
PROTOCOLS.add(PROTOCOL_REQUEST_WHEN);
PROTOCOLS.add(PROTOCOL_BROKERING);
PROTOCOLS.add(PROTOCOL_RECRUITING);
PROTOCOLS.add(PROTOCOL_PROPOSE);
PROTOCOLS.add(PROTOCOL_SUBSCRIBE);
PROTOCOLS.add(PROTOCOL_ENGLISH_AUCTION);
PROTOCOLS.add(PROTOCOL_DUTCH_AUCTION);
PROTOCOLS.add(PROTOCOL_CONTRACT_NET);
PROTOCOLS.add(PROTOCOL_ITERATED_CONTRACT_NET);
PROTOCOLS.add(PROTOCOL_CANCEL_META);
}
// Performatives.
public static final String ACCEPT_PROPOSAL = "accept-proposal";
public static final String AGREE = "agree";
public static final String CANCEL = "cancel";
public static final String CFP = "cfp";
public static final String CONFIRM = "confirm";
public static final String DISCONFIRM = "disconfirm";
public static final String FAILURE = "failure";
public static final String INFORM = "inform";
public static final String INFORM_IF = "inform-if";
public static final String INFORM_REF = "inform-ref";
public static final String NOT_UNDERSTOOD = "not-understood";
public static final String PROPOSE = "propose";
public static final String QUERY_IF = "query-if";
public static final String QUERY_REF = "query-ref";
public static final String REFUSE = "refuse";
public static final String REJECT_PROPOSAL = "reject-proposal";
public static final String REQUEST = "request";
public static final String REQUEST_WHEN = "request-when";
public static final String REQUEST_WHENEVER = "request-whenever";
public static final String SUBSCRIBE = "subscribe";
public static final String PROXY = "proxy";
public static final String PROPAGATE = "propagate";
public static final String UNKNOWN = "unknown";
/** The allowed message attributes. */
public static final Collection PERFORMATIVES;
static
{
// cannot use hashset, as order is important for gui usage.
PERFORMATIVES = SCollection.createArrayList();
PERFORMATIVES.add(ACCEPT_PROPOSAL);
PERFORMATIVES.add(AGREE);
PERFORMATIVES.add(CANCEL);
PERFORMATIVES.add(CFP);
PERFORMATIVES.add(CONFIRM);
PERFORMATIVES.add(DISCONFIRM);
PERFORMATIVES.add(FAILURE);
PERFORMATIVES.add(INFORM);
PERFORMATIVES.add(INFORM_IF);
PERFORMATIVES.add(INFORM_REF);
PERFORMATIVES.add(NOT_UNDERSTOOD);
PERFORMATIVES.add(PROPOSE);
PERFORMATIVES.add(QUERY_IF);
PERFORMATIVES.add(QUERY_REF);
PERFORMATIVES.add(REFUSE);
PERFORMATIVES.add(REJECT_PROPOSAL);
PERFORMATIVES.add(REQUEST);
PERFORMATIVES.add(REQUEST_WHEN);
PERFORMATIVES.add(REQUEST_WHENEVER);
PERFORMATIVES.add(SUBSCRIBE);
PERFORMATIVES.add(PROXY);
PERFORMATIVES.add(PROPAGATE);
PERFORMATIVES.add(UNKNOWN);
}
// Names of the various fields of an ACL message.
// Not FIPA compliant, "receivers" should be "receiver" and "_"'s should be "-"'s.
public static final String ENCODING = "encoding";
public static final String IN_REPLY_TO = "in_reply_to";
public static final String LANGUAGE = "language";
public static final String ONTOLOGY = "ontology";
public static final String PROTOCOL = "protocol";
public static final String REPLY_BY = "reply_by";
public static final String REPLY_WITH = "reply_with";
public static final String RECEIVERS = "receivers";
public static final String REPLY_TO = "reply_to";
public static final String PERFORMATIVE = "performative";
public static final String CONTENT = "content";
public static final String SENDER = "sender";
public static final String CONVERSATION_ID = "conversation_id";
public static final String X_MESSAGE_ID = "x_message_id";
public static final String X_TIMESTAMP = "x_timestamp";
public static final String X_RID = "x_rid";
public static final String X_RECEIVER = "x_receiver";
public static final String X_NONFUNCTIONAL = "x_nonfunctional";
/** The allowed message attributes. */
public static final Set MESSAGE_ATTRIBUTES;
static
{
MESSAGE_ATTRIBUTES = SCollection.createHashSet();
MESSAGE_ATTRIBUTES.add(CONVERSATION_ID);
MESSAGE_ATTRIBUTES.add(ENCODING);
MESSAGE_ATTRIBUTES.add(IN_REPLY_TO);
MESSAGE_ATTRIBUTES.add(LANGUAGE);
MESSAGE_ATTRIBUTES.add(ONTOLOGY);
MESSAGE_ATTRIBUTES.add(PROTOCOL);
MESSAGE_ATTRIBUTES.add(REPLY_BY);
MESSAGE_ATTRIBUTES.add(REPLY_WITH);
MESSAGE_ATTRIBUTES.add(RECEIVERS);
MESSAGE_ATTRIBUTES.add(REPLY_TO);
MESSAGE_ATTRIBUTES.add(PERFORMATIVE);
MESSAGE_ATTRIBUTES.add(CONTENT);
MESSAGE_ATTRIBUTES.add(SENDER);
// MESSAGE_ATTRIBUTES.add(REPLY_BY_DATE);
// MESSAGE_ATTRIBUTES.add(CONTENT_START);
// MESSAGE_ATTRIBUTES.add(CONTENT_CLASS);
// MESSAGE_ATTRIBUTES.add(ACTION_CLASS);
}
// Content languages.
public static final String FIPA_SL0 = "fipa-sl0";
public static final String FIPA_SL1 = "fipa-sl1";
public static final String FIPA_SL2 = "fipa-sl2";
public static final String FIPA_SL = "fipa-sl";
public static final String JAVA_XML = "java-xml"; //JavaXMLContentCodec.JAVA_XML; // Hack!!! avoid dependency
public static final String JADEX_XML = "jadex-xml"; //JadexXMLContentCodec.JADEX_XML; // Hack!!! avoid dependency
public static final String JADEX_RAW = "jadex-raw"; // Use object as content. Might break state isolation when sending local messages!
public static final String JADEX_BINARY = "jadex-binary"; //JadexBinaryContentCodec.JADEX_BINARY; // Hack!!! avoid dependency
public static final String NUGGETS_XML = "nuggets-xml"; //NuggetsXMLContentCodec.NUGGETS_XML; // Hack!!! avoid dependency
//public static final String XSTREAM_XML = "xstream-xml"; //todo
// public static final MessageType FIPA_MESSAGE_TYPE = new FIPAMessageType();
/**
* Clone the component identifier.
* @param source The source component identifier.
* @param cms The cms service.
* /
public IComponentIdentifier cloneComponentIdentifier(IComponentIdentifier source, IComponentManagementService ces)
{
IComponentIdentifier clone = ces.createComponentIdentifier(source.getName(), false, source.getAddresses());
// Deep copy of resolvers.
// ComponentIdentifier[] res = getResolvers();
// for(int i = 0; i < res.length; i++)
// clone.addResolver((ComponentIdentifier)res[i].clone());
return clone;
}*/
/**
* Clone the cms component description.
* @param source The source cms component description.
* @param cms The cms service.
* /
public static IComponentDescription cloneComponentDescription(IComponentDescription source, IComponentManagementService ces)
{
IComponentIdentifier id = source.getName();
id = ces.createComponentIdentifier(id.getName(), false, id.getAddresses());
return ces.createComponentDescription(id, source.getState(), source.getOwnership(), source.getType());
}*/
// /**
// * Clone the df service description.
// * @param source The source df service description.
// * @param df The df service.
// */
// public static IDFServiceDescription cloneDFServiceDescription(IDFServiceDescription source, IDF df)
// {
// IDFServiceDescription clone = df.createDFServiceDescription(source.getName(), source.getType(), source.getOwnership(),
// source.getLanguages(), source.getOntologies(), source.getProtocols(), source.getProperties());
// // todo: deep clone properties?
// return clone;
// }
// /**
// * Clone the df component description.
// * @param source The source df component description.
// * @param df The df service.
// */
// public static IDFComponentDescription cloneDFComponentDescription(IDFComponentDescription source, IDF df)
// {
// IDFServiceDescription[] sds = source.getServices();
// IDFServiceDescription[] tds = null;
// if(sds!=null)
// {
// tds = new IDFServiceDescription[sds.length];
// for(int i=0; i createReply(Map msg)
{
Map ret = new HashMap();
// Copied parameters
if(msg.get(CONVERSATION_ID)!=null)
ret.put(CONVERSATION_ID, msg.get(CONVERSATION_ID));
if(msg.get(PROTOCOL)!=null)
ret.put(PROTOCOL, msg.get(PROTOCOL));
if(msg.get(LANGUAGE)!=null)
ret.put(LANGUAGE, msg.get(LANGUAGE));
if(msg.get(ONTOLOGY)!=null)
ret.put(ONTOLOGY, msg.get(ONTOLOGY));
if(msg.get(ENCODING)!=null)
ret.put(ENCODING, msg.get(ENCODING));
// Mapped parameters
if(msg.get(REPLY_TO)!=null || msg.get(SENDER)!=null)
ret.put(RECEIVERS, msg.get(REPLY_TO)!=null? msg.get(REPLY_TO): msg.get(SENDER));
if(msg.get(REPLY_WITH)!=null)
ret.put(IN_REPLY_TO, msg.get(REPLY_WITH));
return ret;
}
}