/*
 *  Agent's ALLL send message action class
 *
 *  2004 - 2011 Frantisek Zboril jr.
 *  Faculty of Information Technology
 *  zborilf@fit.vutbr.cz
 *  http://www.fit.vutbr.cz/~zborilf
 *
 * (C) Brno University of Technology
 * Freeware licence VUT v Brně
 * https://wis.fit.vutbr.cz/FIT/db/dir.php/dr/VZ2007/externiInformace/softwareNaWebu/Priloha2_rozh23.pdf

 */

package jTMass.core.jAMass.jActions;

import jTMass.core.jAMass.*;
import jTMass.core.jALLL.jTObjects.*;
import jTMass.core.jTMassModel.jModelData.TSpeechAct;
import jTMass.core.jTMassPlatform.TPlatform;


public class TSend extends TAction {
 
    TAtom PReceiverName;

    // ===== CLONING =====

    @Override
    public TObject cloneObject(){
	TSend newInterference=new
        	TSend((TAtom)PReceiverName.cloneObject(),(TList)PList.cloneObject());
	return(newInterference);
    }

    // ===== STRING CONTENT READERS =====

    @Override
    public String getActionName(){
        return("SEND");
    }

    @Override
    public String getContent(){
	return("!("+PReceiverName.getContent()+","+PList.getContent()+")");
    }

    // ===== WRITERS =====

    void setReceiver(TAtom receiverName){
	PReceiverName=receiverName;
    }
	
    // ===== REGISTER MAINTENANCE=====

    @Override
    public TObject substituteRegisters(TAgent agent){
	super.substituteRegisters(agent);
	if(PReceiverName instanceof TRegister)
		PReceiverName=(TAtom)PReceiverName.substituteRegisters(agent);
	return(this);
    }

    @Override
    public void matureRegisters(){
	super.matureRegisters();
	PReceiverName.matureRegisters();
    }
		
    // ===== ACTION EXECUTION =====

    @Override
    public TObject execute(TAgent agent){
	super.execute(agent);
        TSpeechAct newSpeechAct;

        for (int i=1; i<=agent.getPnoOutputGates();i++)
            if(agent.getOutputConnection(i).getInputElement() instanceof TPlatform){
                newSpeechAct=new TSpeechAct(TSpeechAct._SA_Inform,agent.getElementName(),
                        agent.getOutputConnection(i).getInputElement().getElementName()
                        ,TSpeechAct._CL_ALLL,"("+PReceiverName.getContent()+
                        ",("+agent.getElementName()+","+PList.getContent()+"))");
                agent.addOutputData(newSpeechAct);
            }
	return(null);
    }

    // ===== CONSTRUCTOR =====

    public TSend(TAtom receiver_name, TList content){
        super(TConstants._Interference);
	PReceiverName=receiver_name;
	PList=content;
    }
	
}
