Search in sources :

Example 26 with ITransactionScope

use of org.whole.lang.bindings.ITransactionScope in project whole by wholeplatform.

the class PerformHandler method canExecute.

@CanExecute
public boolean canExecute(@Named(BEHAVIOR_XWL_PARAMETER_ID) String behaviorXwl, @Named(PREDICATE_XWL_PARAMETER_ID) String predicateXwl, @Optional @Named(IServiceConstants.ACTIVE_SELECTION) IBindingManager bm) throws Exception {
    ITransactionScope ts = BindingManagerFactory.instance.createTransactionScope();
    try {
        bm.wEnterScope(ts);
        defineBindings(behaviorXwl, predicateXwl, bm);
        return HandlersBehavior.canPerform(bm);
    } catch (Exception e) {
        return false;
    } finally {
        ts.rollback();
        bm.wExitScope();
    }
}
Also used : ITransactionScope(org.whole.lang.bindings.ITransactionScope) CanExecute(org.eclipse.e4.core.di.annotations.CanExecute)

Example 27 with ITransactionScope

use of org.whole.lang.bindings.ITransactionScope in project whole by wholeplatform.

the class TestsInterpreterVisitor method visit.

@Override
public void visit(Test entity) {
    ITransactionScope ts = BindingManagerFactory.instance.createTransactionScope();
    getBindings().wEnterScope(ts);
    String name = entity.getName().getValue();
    Outcome outcome = TestsEntityFactory.instance.createOutcome(OutcomeEnum.SUCCESS);
    StringLiteral location = CommonsEntityAdapterFactory.createResolver(StringLiteral);
    StringLiteral cause = CommonsEntityAdapterFactory.createResolver(StringLiteral);
    Result result = TestsEntityFactory.instance.createResult(outcome, location, cause);
    try {
        for (BeforeTest beforeTest : BehaviorUtils.<BeforeTest>compileAndLazyEvaluate(createAspectPath("BeforeTest"), entity)) {
            beforeTest.accept(this);
            getResult();
        }
        entity.getBody().accept(this);
        getResult();
        for (AfterTest afterTest : BehaviorUtils.<AfterTest>compileAndLazyEvaluate(createAspectPath("AfterTest"), entity)) {
            afterTest.accept(this);
            getResult();
        }
        printWriter().printf("    %32s(...) OK\n", name);
    } catch (OperationCanceledException e) {
        throw e;
    } catch (TestsException e) {
        outcome.wSetValue(OutcomeEnum.FAILURE);
        location.setValue(EntityUtils.getLocation(e.getSubjectStatement()));
        cause.setValue(e.getMessage());
        reportFailure(name, e);
    } catch (RuntimeException e) {
        outcome.wSetValue(OutcomeEnum.ERROR);
        IEntity sourceEntity = null;
        if (e instanceof IWholeRuntimeException) {
            sourceEntity = ((IWholeRuntimeException) e).getSourceEntity();
            if (EntityUtils.getCompoundRoot(sourceEntity) != EntityUtils.getCompoundRoot(entity))
                // FIXME replace with outer aspect or statement
                sourceEntity = null;
        }
        if (sourceEntity == null)
            sourceEntity = entity;
        location.setValue(EntityUtils.getLocation(sourceEntity));
        cause.setValue(e.getMessage());
        reportError(name, e);
    } finally {
        ts.rollback();
        getBindings().wExitScope();
    }
    if (EntityUtils.isResolver(entity.getExpectedResult()))
        entity.setExpectedResult(EntityUtils.clone(result));
    if (!Matcher.match(result, entity.getActualResult()))
        entity.setActualResult(result);
    setResult(result);
}
Also used : IWholeRuntimeException(org.whole.lang.exceptions.IWholeRuntimeException) ITransactionScope(org.whole.lang.bindings.ITransactionScope) StringLiteral(org.whole.lang.tests.model.StringLiteral) IWholeRuntimeException(org.whole.lang.exceptions.IWholeRuntimeException) IEntity(org.whole.lang.model.IEntity) Outcome(org.whole.lang.tests.model.Outcome) OperationCanceledException(org.whole.lang.operations.OperationCanceledException) BeforeTest(org.whole.lang.tests.model.BeforeTest) AfterTest(org.whole.lang.tests.model.AfterTest) Result(org.whole.lang.tests.model.Result)

Aggregations

ITransactionScope (org.whole.lang.bindings.ITransactionScope)27 IEntity (org.whole.lang.model.IEntity)14 CanExecute (org.eclipse.e4.core.di.annotations.CanExecute)10 Execute (org.eclipse.e4.core.di.annotations.Execute)4 CommandStack (org.eclipse.gef.commands.CommandStack)4 IBindingManager (org.whole.lang.bindings.IBindingManager)4 RollbackException (org.whole.lang.lifecycle.RollbackException)4 ModelTransactionCommand (org.whole.lang.ui.commands.ModelTransactionCommand)4 OperationCanceledException (org.whole.lang.operations.OperationCanceledException)3 FeatureDescriptor (org.whole.lang.reflect.FeatureDescriptor)3 IEntityPartViewer (org.whole.lang.ui.viewers.IEntityPartViewer)3 IWholeRuntimeException (org.whole.lang.exceptions.IWholeRuntimeException)2 InternalIEntity (org.whole.lang.model.InternalIEntity)2 IVisitor (org.whole.lang.visitors.IVisitor)2 MissingVariableException (org.whole.lang.visitors.MissingVariableException)2 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1