blob: 2b0e171ce7a3edfbc38aa6376f05c76fb3a6799b [file] [log] [blame]
/*********************************************************************
* Copyright (c) 2019 The University of York.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
**********************************************************************/
package org.eclipse.epsilon.executors.eol;
import java.util.Collections;
import java.util.List;
import org.eclipse.epsilon.eol.IEolModule;
import org.eclipse.epsilon.eol.concurrent.EolModuleParallel;
import org.eclipse.epsilon.eol.dom.Operation;
import org.eclipse.epsilon.eol.exceptions.EolRuntimeException;
import org.eclipse.epsilon.executors.AbstractLanguageExecutor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* The EOL executor
*
* By default the complete EOL script is executed. Alternatively, a specific operation can be
* invoked by setting the desired operationName name (see {@link #setOperationName(String)}).
*
* Additionally, the {@link #setOperationArguments(List)} method can be used to provide a list of
* arguments to use for invocation of the operation. The arguments are considered to be in the same
* order and of the correct type of the operation signature.
*
* @author Horacio Hoyos Rodriguez
*/
public class EolExecutor extends AbstractLanguageExecutor implements IEolExecutor {
private static final Logger logger = LoggerFactory.getLogger(EolExecutor.class);
private String operationName = "";
private List<Object> arguments = Collections.emptyList();
private EolMode mode = EolMode.COMPLETE;
public EolExecutor() {
this(new EolModuleParallel());
}
public EolExecutor(IEolModule module) {
super(module);
logger.info("Creating the EolStandaloneEngine");
}
@Override
protected Object executeInternal() throws EolRuntimeException {
switch(mode) {
case COMPLETE:
logger.info("Executing complete EOL script.");
return module.execute();
case OPERATION:
if (operationName.length() == 0) {
throw new EolRuntimeException("Can not invoke executor in OPERATION mode without an operation name assigned.");
}
logger.info("Executing EOL operation {} with arguments: {}.", operationName, arguments);
Operation operation = module.getDeclaredOperations().getOperation(operationName);
return operation.execute(null, arguments, module.getContext());
}
return null;
}
@Override
public void setOperationName(String operationName) {
this.operationName = operationName;
if (operationName.length() > 0) {
this.mode = EolMode.OPERATION;
}
else {
this.mode = EolMode.COMPLETE;
}
}
@Override
public void setOperationArguments(List<Object> arguments) {
this.arguments = arguments;
}
@Override
public void setMode(EolMode mode) {
this.mode = mode;
}
}