Beispiel #1
0
	def encodeXML(self, msg):

		sb = self.OT + self.FIPA_MESSAGE_TAG
		if msg.getPerformative():
			sb += " " + self.ACT_TAG + '="' + msg.getPerformative() + '"'
		sb += self.CT

		#sender
		if msg.getSender():
			sb += self.OT + self.SENDER_TAG + self.CT
			sb += self.encodeAid(msg.getSender())
			sb += self.ET + self.SENDER_TAG + self.CT

		#receivers
		if len(msg.getReceivers()) > 0:
			sb += self.OT + self.RECEIVER_TAG + self.CT
			for r in msg.getReceivers():
				sb += self.encodeAid(r)
			sb += self.ET + self.RECEIVER_TAG + self.CT

		
		if msg.getContent():
			sb += self.encodeTag(self.CONTENT_TAG, str(msg.getContent()))

		if msg.getLanguage():
			sb += self.encodeTag(self.LANGUAGE_TAG, msg.getLanguage())

		if msg.getEncoding():
			sb += self.encodeTag(self.ENCODING_TAG, msg.getEncoding())

		if msg.getOntology():
			sb += self.encodeTag(self.ONTOLOGY_TAG, msg.getOntology())

		if msg.getProtocol():
			sb += self.encodeTag(self.PROTOCOL_TAG, msg.getProtocol())

		if msg.getReplyWith():
			sb += self.encodeTag(self.REPLY_WITH_TAG, msg.getReplyWith())

		if msg.getInReplyTo():
			sb += self.encodeTag(self.IN_REPLY_TO_TAG, msg.getInReplyTo())

		if msg.getReplyBy():
			date = BasicFipaDateTime()
			date.fromString( str(msg.getReplyBy()) )
			sb += self.encodeTag(self.REPLY_BY_TAG, str(date))

		if len(msg.getReplyTo()) > 0:
			sb += self.OT + self.REPLY_TO_TAG + self.CT
			for e in msg.getReplyTo():
				sb += self.encodeAid(e)
			sb += self.ET + self.REPLY_TO_TAG + self.CT

		if msg.getConversationId():
			sb += self.encodeTag(self.CONVERSATION_ID_TAG, msg.getConversationId())

		sb += self.ET + self.FIPA_MESSAGE_TAG + self.CT

		return sb
Beispiel #2
0
    def encodeXML(self, msg):

        sb = self.OT + self.FIPA_MESSAGE_TAG
        if msg.getPerformative():
            sb += " " + self.ACT_TAG + '="' + msg.getPerformative() + '"'
        sb += self.CT

        #sender
        if msg.getSender():
            sb += self.OT + self.SENDER_TAG + self.CT
            sb += self.encodeAid(msg.getSender())
            sb += self.ET + self.SENDER_TAG + self.CT

        #receivers
        if len(msg.getReceivers()) > 0:
            sb += self.OT + self.RECEIVER_TAG + self.CT
            for r in msg.getReceivers():
                sb += self.encodeAid(r)
            sb += self.ET + self.RECEIVER_TAG + self.CT

        if msg.getContent():
            sb += self.encodeTag(self.CONTENT_TAG, str(msg.getContent()))

        if msg.getLanguage():
            sb += self.encodeTag(self.LANGUAGE_TAG, msg.getLanguage())

        if msg.getEncoding():
            sb += self.encodeTag(self.ENCODING_TAG, msg.getEncoding())

        if msg.getOntology():
            sb += self.encodeTag(self.ONTOLOGY_TAG, msg.getOntology())

        if msg.getProtocol():
            sb += self.encodeTag(self.PROTOCOL_TAG, msg.getProtocol())

        if msg.getReplyWith():
            sb += self.encodeTag(self.REPLY_WITH_TAG, msg.getReplyWith())

        if msg.getInReplyTo():
            sb += self.encodeTag(self.IN_REPLY_TO_TAG, msg.getInReplyTo())

        if msg.getReplyBy():
            date = BasicFipaDateTime()
            date.fromString(str(msg.getReplyBy()))
            sb += self.encodeTag(self.REPLY_BY_TAG, str(date))

        if len(msg.getReplyTo()) > 0:
            sb += self.OT + self.REPLY_TO_TAG + self.CT
            for e in msg.getReplyTo():
                sb += self.encodeAid(e)
            sb += self.ET + self.REPLY_TO_TAG + self.CT

        if msg.getConversationId():
            sb += self.encodeTag(self.CONVERSATION_ID_TAG,
                                 msg.getConversationId())

        sb += self.ET + self.FIPA_MESSAGE_TAG + self.CT

        return sb
Beispiel #3
0
	def endElement(self, localName):
    
		#Capture the value the attributes of class
		if self.AID_NAME.lower() == localName.lower():
			self.aid.setName(self.accumulator)

		elif self.AID_ADDRESS.lower() == localName.lower():
			self.aid.addAddress(self.accumulator)

		elif self.TO_TAG.lower() == localName.lower():
			self.aidTag = ""

		elif self.FROM_TAG.lower() == localName.lower():
			self.aidTag = ""

		elif self.INTENDED_TAG.lower() == localName.lower():
			self.aidTag = ""

		elif self.AID_TAG.lower() == localName.lower():
			if self.aidTag == self.TO_TAG:
				self.env.addTo(self.aid)
			elif self.aidTag == self.FROM_TAG:
				self.env.setFrom(self.aid)
			elif self.aidTag == self.INTENDED_TAG:
				self.env.addIntendedReceiver(self.aid)

		elif self.COMMENTS_TAG.lower() == localName.lower():
			self.env.setComments(self.accumulator)

		elif self.REPRESENTATION_TAG.lower() == localName.lower():
			self.env.setAclRepresentation(self.accumulator)

		elif self.LENGTH_TAG.lower() == localName.lower():
			self.env.setPayloadLength( long(self.accumulator) )
			"""
			if(logger.isLoggable(Logger.WARNING))
				logger.log(Logger.FINE,"Length: "+env.getPayloadLength());
			"""

		elif self.ENCODING_TAG.lower() ==localName.lower():
			self.env.setPayloadEncoding(self.accumulator)

		elif self.DATE_TAG.lower() == localName.lower():
			bfdt= BasicFipaDateTime()
			bfdt.fromString(str(self.accumulator))
			self.env.setDate( bfdt )

		"""
		elif self.PROP_TAG.lower() == localName.lower():
			decodeProp(accumulator, prop);
		"""
		""" 
Beispiel #4
0
    def endElement(self, localName):

        #Capture the value the attributes of class
        if self.AID_NAME.lower() == localName.lower():
            self.aid.setName(self.accumulator)

        elif self.AID_ADDRESS.lower() == localName.lower():
            self.aid.addAddress(self.accumulator)

        elif self.TO_TAG.lower() == localName.lower():
            self.aidTag = ""

        elif self.FROM_TAG.lower() == localName.lower():
            self.aidTag = ""

        elif self.INTENDED_TAG.lower() == localName.lower():
            self.aidTag = ""

        elif self.AID_TAG.lower() == localName.lower():
            if self.aidTag == self.TO_TAG:
                self.env.addTo(self.aid)
            elif self.aidTag == self.FROM_TAG:
                self.env.setFrom(self.aid)
            elif self.aidTag == self.INTENDED_TAG:
                self.env.addIntendedReceiver(self.aid)

        elif self.COMMENTS_TAG.lower() == localName.lower():
            self.env.setComments(self.accumulator)

        elif self.REPRESENTATION_TAG.lower() == localName.lower():
            self.env.setAclRepresentation(self.accumulator)

        elif self.LENGTH_TAG.lower() == localName.lower():
            self.env.setPayloadLength(long(self.accumulator))
            """
            if(logger.isLoggable(Logger.WARNING))
                logger.log(Logger.FINE,"Length: "+env.getPayloadLength());
            """

        elif self.ENCODING_TAG.lower() == localName.lower():
            self.env.setPayloadEncoding(self.accumulator)

        elif self.DATE_TAG.lower() == localName.lower():
            bfdt = BasicFipaDateTime()
            bfdt.fromString(str(self.accumulator))
            self.env.setDate(bfdt)
        """
        elif self.PROP_TAG.lower() == localName.lower():
            decodeProp(accumulator, prop);
        """
        """
Beispiel #5
0
	def encodeXML(self, env):
		"""
		General Encoding of the envelope
		"""
     
		#Create the message XML
		sb = self.OT + self.ENVELOPE_TAG + self.CT
		sb = sb + self.OT + self.PARAMS_TAG + self.INDEX_ATTR + "1" + '"' + self.CT
    
		#Create tag TO
		tos = env.getTo()
		for agentid in tos:
			sb = sb + self.OT + self.TO_TAG + self.CT
			sb = sb + self.encodeAid(agentid)
			sb = sb + self.ET + self.TO_TAG + self.CT
    
		#Create tag from
		if env.getFrom() != None:
			sb = sb + self.OT + self.FROM_TAG + self.CT
			sb = sb + self.encodeAid( env.getFrom() )
			sb = sb + self.ET + self.FROM_TAG + self.CT
    
		#Create tag comments
		if env.getComments() != None and len(env.getComments()) > 0:
			sb = sb + self.encodeTag( self.COMMENTS_TAG, env.getComments() )
    
		#Create tag acl-representation
		if env.getAclRepresentation() != None:
			sb = sb + self.encodeTag( self.REPRESENTATION_TAG, env.getAclRepresentation() )
    
		#Create tag payload-length
			if env.getPayloadLength() != None:
				sb = sb + self.encodeTag( self.LENGTH_TAG, str(env.getPayloadLength()) )
    
		#Create tag payload-encoding
		if env.getPayloadEncoding() != None and len(env.getPayloadEncoding()) > 0:
			sb = sb + self.encodeTag( self.ENCODING_TAG, env.getPayloadEncoding() )
    
		#Create tag date
		#Create object BasicFipaDateTime
		if env.getDate() != None:
			date = BasicFipaDateTime()
			date.fromString( str(env.getDate()) )
			sb = sb + self.encodeTag( self.DATE_TAG, str(date) )

    
		#Create tag encrypted (NL: not sure it is still in FIPA)
		"""
		for i in env.getEncrypted():
			sb = sb + self.encodeTag( self.ENCRYPTED_TAG, str(i) )  
		"""
    
		#Create tag intended-receiver
		for i in env.getIntendedReceiver():
			sb = sb + self.OT + self.INTENDED_TAG + self.CT
			sb = sb + self.encodeAid(i)
			sb = sb + self.ET + self.INTENDED_TAG + self.CT
	  
		"""
		#Create tags for user properties
		for (i=env.getAllProperties();i.hasNext();) {
			encodeProp(sb,(Property)i.next());
		"""

		#Create tag received
		ro = env.getReceived()
		if ro != None:
			#Create tag received
			sb = sb + self.OT + self.RECEIVED_TAG + self.CT
			#Date  
			value = BasicFipaDateTime( ro.getDate() )
			if value != None:
				sb = sb + self.encodeOneLineTag( self.RECEIVED_DATE, self.RECEIVED_ATTR, str( value ) )
			#By
			value = ro.getBy()
			if value != None:
				sb = sb + self.encodeOneLineTag( self.RECEIVED_BY, self.RECEIVED_ATTR, value )
			#From
			value = ro.getFrom()
			if value != None:
				sb = sb + self.encodeOneLineTag( self.RECEIVED_FROM, self.RECEIVED_ATTR, value )
			#Id
			value = ro.getId()
			if value != None:
				sb = sb + self.encodeOneLineTag( self.RECEIVED_ID, self.RECEIVED_ATTR, value )
			#Via
			value = ro.getVia()
			if value != None:
				sb = sb + self.encodeOneLineTag( self.RECEIVED_VIA, self.RECEIVED_ATTR, value )

			sb = sb + self.ET + self.RECEIVED_TAG + self.CT 



		sb = sb + self.ET + self.PARAMS_TAG + self.CT
		sb = sb + self.ET + self.ENVELOPE_TAG + self.CT 
    
		return sb
Beispiel #6
0
    def encodeXML(self, env):
        """
        General Encoding of the envelope
        """

        #Create the message XML
        sb = self.OT + self.ENVELOPE_TAG + self.CT
        sb = sb + self.OT + self.PARAMS_TAG + self.INDEX_ATTR + "1" + '"' + self.CT

        #Create tag TO
        tos = env.getTo()
        for agentid in tos:
            sb = sb + self.OT + self.TO_TAG + self.CT
            sb = sb + self.encodeAid(agentid)
            sb = sb + self.ET + self.TO_TAG + self.CT

        #Create tag from
        if env.getFrom() is not None:
            sb = sb + self.OT + self.FROM_TAG + self.CT
            sb = sb + self.encodeAid(env.getFrom())
            sb = sb + self.ET + self.FROM_TAG + self.CT

        #Create tag comments
        if env.getComments() is not None and len(env.getComments()) > 0:
            sb = sb + self.encodeTag(self.COMMENTS_TAG, env.getComments())

        #Create tag acl-representation
        if env.getAclRepresentation() is not None:
            sb = sb + self.encodeTag(self.REPRESENTATION_TAG,
                                     env.getAclRepresentation())

            #Create tag payload-length
            if env.getPayloadLength() is not None:
                sb = sb + self.encodeTag(self.LENGTH_TAG,
                                         str(env.getPayloadLength()))

        #Create tag payload-encoding
        if env.getPayloadEncoding() is not None and len(
                env.getPayloadEncoding()) > 0:
            sb = sb + self.encodeTag(self.ENCODING_TAG,
                                     env.getPayloadEncoding())

        #Create tag date
        #Create object BasicFipaDateTime
        if env.getDate() is not None:
            date = BasicFipaDateTime()
            date.fromString(str(env.getDate()))
            sb = sb + self.encodeTag(self.DATE_TAG, str(date))

        #Create tag encrypted (NL: not sure it is still in FIPA)
        """
        for i in env.getEncrypted():
            sb = sb + self.encodeTag( self.ENCRYPTED_TAG, str(i) )
        """

        #Create tag intended-receiver
        for i in env.getIntendedReceiver():
            sb = sb + self.OT + self.INTENDED_TAG + self.CT
            sb = sb + self.encodeAid(i)
            sb = sb + self.ET + self.INTENDED_TAG + self.CT
        """
        #Create tags for user properties
        for (i=env.getAllProperties();i.hasNext();) {
            encodeProp(sb,(Property)i.next());
        """

        #Create tag received
        ro = env.getReceived()
        if ro is not None:
            #Create tag received
            sb = sb + self.OT + self.RECEIVED_TAG + self.CT
            #Date
            value = BasicFipaDateTime(ro.getDate())
            if value is not None:
                sb = sb + self.encodeOneLineTag(self.RECEIVED_DATE,
                                                self.RECEIVED_ATTR, str(value))
            #By
            value = ro.getBy()
            if value is not None:
                sb = sb + self.encodeOneLineTag(self.RECEIVED_BY,
                                                self.RECEIVED_ATTR, value)
            #From
            value = ro.getFrom()
            if value is not None:
                sb = sb + self.encodeOneLineTag(self.RECEIVED_FROM,
                                                self.RECEIVED_ATTR, value)
            #Id
            value = ro.getId()
            if value is not None:
                sb = sb + self.encodeOneLineTag(self.RECEIVED_ID,
                                                self.RECEIVED_ATTR, value)
            #Via
            value = ro.getVia()
            if value is not None:
                sb = sb + self.encodeOneLineTag(self.RECEIVED_VIA,
                                                self.RECEIVED_ATTR, value)

            sb = sb + self.ET + self.RECEIVED_TAG + self.CT

        sb = sb + self.ET + self.PARAMS_TAG + self.CT
        sb = sb + self.ET + self.ENVELOPE_TAG + self.CT

        return sb