package org.helloworld;

import ptolemy.actor.TypedCompositeActor;
import ptolemy.actor.TypedIOPort;
import ptolemy.actor.TypedIORelation;
import ptolemy.actor.lib.ElementsToArray;
import ptolemy.actor.lib.Expression;
import ptolemy.actor.lib.hoc.IterateOverArray;
import ptolemy.actor.lib.hoc.MirrorPort;
import ptolemy.kernel.CompositeEntity;
import ptolemy.kernel.util.IllegalActionException;
import ptolemy.kernel.util.NameDuplicationException;

public class HelloWorld extends TypedCompositeActor {

    public HelloWorld(CompositeEntity container, String name)
            throws NameDuplicationException, IllegalActionException {
        super(container, name);


        params = new TypedIOPort(this, "params", true, false);
        params.setMultiport(true);


        output = new TypedIOPort(this, "output", false, true);


        elems2Arr = new ElementsToArray(this, "elems2Arr");
        relation1 = new TypedIORelation(this, "realtion1");
        params.link(relation1);
        elems2Arr.input.link(relation1);


        iter = new IterateOverArray(this, "iter");
        //mpInput = new MirrorPort(iter, "input"); mpInput.setInput(true);
        mpInput = new IterateOverArray.IteratePort(iter, "input");
        //mpOutput = new MirrorPort(iter, "output"); mpOutput.setOutput(true);
        mpOutput = new IterateOverArray.IteratePort(iter, "output");
        exp = new Expression(iter, "exp");
        exp.expression.setExpression("input + ' - ' + iterationCount");
        relation2 = new TypedIORelation(this, "realtion2");
        elems2Arr.output.link(relation2);
        iter.getPort("input").link(relation2);


        relation3 = new TypedIORelation(this, "realtion3");
        iter.getPort("output").link(relation3);
        output.link(relation3);
    }


    public TypedIOPort params;
    public TypedIOPort output;

    //private MirrorPort mpInput;
    //private MirrorPort mpOutput;

    private IterateOverArray.IteratePort mpInput;
    private IterateOverArray.IteratePort mpOutput;


    private ElementsToArray elems2Arr;
    private IterateOverArray iter;
    private Expression exp;

    private TypedIORelation relation1;
    private TypedIORelation relation2;
    private TypedIORelation relation3;


    @Override
    public void fire() throws IllegalActionException {
        super.fire();
    }


}
