Package jade.lang.acl

Class StringACLCodec

  • All Implemented Interfaces:
    ACLCodec

    public class StringACLCodec
    extends Object
    implements ACLCodec
    This class implements the FIPA String codec for ACLMessages. Notice that it is not possible to convey a sequence of bytes over a StringACLCodec because the bytes with the 8th bit ON cannot properly converted into a char.
    Version:
    $Date$ $Revision$
    Author:
    Fabio Bellifemine - CSELT S.p.A., Nicolas Lhuillier - Motorola
    • Field Detail

      • NAME

        public static final String NAME
        String constant for the name of the ACL representation managed by this ACL codec.
        See Also:
        Constant Field Values
    • Constructor Detail

      • StringACLCodec

        public StringACLCodec()
        constructor for the codec. The standard input is used as an input stream of ACL messages. The standard output is used to write encoded ACL messages.
      • StringACLCodec

        public StringACLCodec​(Reader r,
                              Writer w)
        constructor for the codec.
    • Method Detail

      • write

        public void write​(ACLMessage msg)
        encodes the message and writes it into the Writer passed in the constructor. Notice that this method does not call flush on the writer.
      • encode

        public byte[] encode​(ACLMessage msg,
                             String charset)
        If the content of the message is a byteSequence, then this method encodes the content in Base64 and automatically sets the value of the encoding slot.
        Specified by:
        encode in interface ACLCodec
        Parameters:
        msg - The ACL message to encode.
        charset - Charset encoding to use (e.g. US_ASCII, UTF-8, etc)
        Returns:
        a byte array, containing the encoded message.
        See Also:
        ACLCodec#encode(ACLMessage msg)
      • decode

        public ACLMessage decode​(byte[] data,
                                 String charset)
                          throws ACLCodec.CodecException
        Description copied from interface: ACLCodec
        Recovers an ACLMessage object back from raw data, using the specific message representation to interpret the byte sequence.
        Specified by:
        decode in interface ACLCodec
        Parameters:
        data - The byte sequence containing the encoded message.
        charset - Charset encoding to use (e.g. US_ASCII, UTF-8, etc)
        Returns:
        A new ACLMessage object, built from the raw data.
        Throws:
        ACLCodec.CodecException - If some kind of syntax error occurs.
        See Also:
        ACLCodec#decode(byte[] data)
      • getName

        public String getName()
        Description copied from interface: ACLCodec
        Query the name of the message representation handled by this Codec object. The FIPA standard representations have a name starting with "fipa.acl.rep.".
        Specified by:
        getName in interface ACLCodec
        Returns:
        the name of this encoding according to the FIPA specifications
      • appendACLExpression

        public static void appendACLExpression​(StringBuffer str,
                                               String slotName,
                                               String slotValue)
        append to the passed StringBuffer the slot name and value separated by a blank char and followed by a newline. If the value contains a blank, then it is quoted. if the value is null or its length is zero, the method does nothing.