All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.concordion.internal.command.SetCommand Maven / Gradle / Ivy

package org.concordion.internal.command;

import java.util.ArrayList;
import java.util.List;

import org.concordion.api.*;
import org.concordion.api.listener.SetEvent;
import org.concordion.api.listener.SetListener;
import org.concordion.internal.util.Check;

public class SetCommand extends AbstractCommand {

    private List listeners = new ArrayList();

    public void addSetListener(SetListener listener) {
        listeners.add(listener);
    }

    public void removeSetListener(SetListener listener) {
        listeners.remove(listener);
    }

    @Override
    public void setUp(CommandCall commandCall, Evaluator evaluator, ResultRecorder resultRecorder, Fixture fixture) {
        Check.isFalse(commandCall.hasChildCommands(), "Nesting commands inside a 'set' is not supported");
        evaluator.setVariable(commandCall.getExpression(), commandCall.getElement().getText());
        announceSetCompleted(commandCall.getElement(), commandCall.getExpression());
    }

    private void announceSetCompleted(Element element, String expression) {
    	for (SetListener listener : listeners) {
    		listener.setCompleted(new SetEvent(element, expression));
		}
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy