Search in sources :

Example 76 with IBindingManager

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

the class TestsUIInterpreterVisitor method reportFailure.

@Override
protected void reportFailure(String name, TestsException e) {
    super.reportFailure(name, e);
    IBindingManager debugEnv = getBindings();
    if ((debugEnv.wIsSet("debug#reportModeEnabled") && !debugEnv.wBooleanValue("debug#reportModeEnabled")) || (debugEnv.wIsSet("debug#debugModeEnabled") && !debugEnv.wBooleanValue("debug#debugModeEnabled")) || (debugEnv.wIsSet("debug#breakpointsEnabled") && !debugEnv.wBooleanValue("debug#breakpointsEnabled")))
        return;
    else
        E4Utils.suspendOperation(SuspensionKind.RECOVERABLE_ERROR, e, e.getSubjectStatement(), e.getBindings());
}
Also used : IBindingManager(org.whole.lang.bindings.IBindingManager)

Example 77 with IBindingManager

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

the class PersistenceLibraryDeployer method stringToModelIterator.

public static IEntityIterator<IEntity> stringToModelIterator() {
    return IteratorFactory.singleValuedRunnableIterator((IEntity selfEntity, IBindingManager bm, IEntity... arguments) -> {
        StringPersistenceProvider pp = new StringPersistenceProvider(selfEntity.wStringValue());
        IPersistenceKit persistenceKit = null;
        try {
            persistenceKit = derivePersistenceKit(bm, pp);
        } catch (Exception e) {
            throw new IllegalArgumentException("Failed to load the persistence kit", e);
        }
        try {
            bm.setResult(persistenceKit.readModel(pp));
        } catch (Exception e) {
            throw new IllegalArgumentException("Failed to load the resource with the given persistence: " + persistenceKit.getId(), e);
        }
    });
}
Also used : StringPersistenceProvider(org.whole.lang.codebase.StringPersistenceProvider) IEntity(org.whole.lang.model.IEntity) IBindingManager(org.whole.lang.bindings.IBindingManager) IPersistenceKit(org.whole.lang.codebase.IPersistenceKit)

Example 78 with IBindingManager

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

the class PersistenceLibraryDeployer method modelToStringIterator.

public static IEntityIterator<IEntity> modelToStringIterator() {
    return IteratorFactory.singleValuedRunnableIterator((IEntity selfEntity, IBindingManager bm, IEntity... arguments) -> {
        StringPersistenceProvider pp = new StringPersistenceProvider();
        pp.getBindings().wDefValue("entityURI", selfEntity.wGetEntityDescriptor().getURI());
        IPersistenceKit persistenceKit = null;
        try {
            persistenceKit = derivePersistenceKit(bm, pp);
        } catch (Exception e) {
            throw new IllegalArgumentException("Failed to load the persistence kit", e);
        }
        try {
            persistenceKit.writeModel(selfEntity, pp);
        } catch (Exception e) {
            throw new IllegalArgumentException("Failed to load the resource with the given persistence: " + persistenceKit.getId(), e);
        }
        bm.setResult(BindingManagerFactory.instance.createValue(pp.getStore()));
    });
}
Also used : StringPersistenceProvider(org.whole.lang.codebase.StringPersistenceProvider) IEntity(org.whole.lang.model.IEntity) IBindingManager(org.whole.lang.bindings.IBindingManager) IPersistenceKit(org.whole.lang.codebase.IPersistenceKit)

Example 79 with IBindingManager

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

the class JavaBuilderPersistenceKit method doReadModel.

@SuppressWarnings("unchecked")
protected IEntity doReadModel(IPersistenceProvider pp) throws Exception {
    IBindingManager bm = pp.getBindings();
    if (bm.wIsSet("compilationUnitName")) {
        ClassLoader classLoader = ReflectionFactory.getClassLoader(bm);
        Class<?> codebaseClass = classLoader.loadClass(bm.wStringValue("compilationUnitName"));
        if (ITemplateFactory.class.isAssignableFrom(codebaseClass))
            return ((ITemplateFactory<IEntity>) codebaseClass.newInstance()).create();
    }
    byte[] buffer = new byte[1024];
    ByteArrayOutputStream baos = new ByteArrayOutputStream(buffer.length * 16);
    BufferedInputStream bis = new BufferedInputStream(pp.getInputStream(), buffer.length);
    int bytesRead;
    while ((bytesRead = bis.read(buffer, 0, buffer.length)) > 0) baos.write(buffer, 0, bytesRead);
    Interpreter javaInterpreter = new Interpreter();
    javaInterpreter.setClassLoader(ReflectionFactory.getPlatformClassLoader());
    Object result = javaInterpreter.eval(toBeanShellScript(baos.toString(pp.getEncoding())));
    if (!(result instanceof IEntity))
        throw new IllegalStateException("not a whole model");
    return (IEntity) result;
}
Also used : Interpreter(bsh.Interpreter) IEntity(org.whole.lang.model.IEntity) BufferedInputStream(java.io.BufferedInputStream) IBindingManager(org.whole.lang.bindings.IBindingManager) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 80 with IBindingManager

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

the class WorkflowsInterpreterVisitorTest method testShallowSaveArtifacts.

@Test
public void testShallowSaveArtifacts() {
    IEntity shallowSaveArtifactsTest = WorkflowsTestTemplateManager.instance().create("shallowSaveArtifactsTest");
    IBindingManager args = BindingManagerFactory.instance.createArguments();
    InterpreterOperation.interpret(shallowSaveArtifactsTest, args);
    Assert.assertTrue(args.wIsSet("artifacts"));
    IEntity artifacts = args.wGet("artifacts");
    Assert.assertTrue(args.wIsSet("shallowResult"));
    IEntity shallowResult = args.wGet("shallowResult");
    Assert.assertTrue(args.wIsSet("deepFileResult"));
    IEntity deepFileResult = args.wGet("deepFileResult");
    Assert.assertTrue(args.wIsSet("deepDirectoryResult"));
    IEntity deepDirectoryResult = args.wGet("deepDirectoryResult");
    Assert.assertTrue(args.wIsSet("deepResult"));
    IEntity deepResult = args.wGet("deepResult");
    // shallow save & deep file load == shallow save & deep
    Assert.assertTrue(OrderedMatcher.match(deepFileResult, deepResult, comparatorsMap));
    // shallow save & deep directory load == shallow save & shallow
    Assert.assertTrue(OrderedMatcher.match(deepDirectoryResult, shallowResult, comparatorsMap));
    // the original model differs from every other model
    Assert.assertFalse(OrderedMatcher.match(artifacts, shallowResult, comparatorsMap));
    Assert.assertFalse(OrderedMatcher.match(artifacts, deepFileResult, comparatorsMap));
    Assert.assertFalse(OrderedMatcher.match(artifacts, deepDirectoryResult, comparatorsMap));
    Assert.assertFalse(OrderedMatcher.match(artifacts, deepResult, comparatorsMap));
    // the only difference is the content on the file artifact
    IEntityIterator<IEntity> iterator = IteratorFactory.matcherIterator(IteratorFactory.descendantOrSelfIterator()).withPattern(ArtifactsFeatureDescriptorEnum.content);
    iterator.reset(deepFileResult);
    while (iterator.hasNext()) {
        iterator.next();
        iterator.remove();
    }
    Assert.assertTrue(OrderedMatcher.match(deepDirectoryResult, deepFileResult, comparatorsMap));
}
Also used : IEntity(org.whole.lang.model.IEntity) IBindingManager(org.whole.lang.bindings.IBindingManager) Test(org.junit.Test)

Aggregations

IBindingManager (org.whole.lang.bindings.IBindingManager)223 IEntity (org.whole.lang.model.IEntity)141 Test (org.junit.Test)91 PathExpression (org.whole.lang.queries.model.PathExpression)49 ITemplateManager (org.whole.lang.templates.ITemplateManager)40 Grammar (org.whole.lang.grammars.model.Grammar)28 TestXmlGrammar (org.whole.lang.grammars.util.TestXmlGrammar)27 ESelectionService (org.eclipse.e4.ui.workbench.modeling.ESelectionService)17 Model (org.whole.lang.models.model.Model)15 Production (org.whole.lang.grammars.model.Production)14 IEntityPartViewer (org.whole.lang.ui.viewers.IEntityPartViewer)14 File (java.io.File)12 QueriesGrammar (org.whole.lang.grammars.codebase.QueriesGrammar)12 XmlModel (org.whole.lang.models.codebase.XmlModel)11 SimpleEntity (org.whole.lang.models.model.SimpleEntity)10 VisitException (org.whole.lang.visitors.VisitException)9 IBindingScope (org.whole.lang.bindings.IBindingScope)6 ModelBuilderOperation (org.whole.lang.builders.ModelBuilderOperation)6 HashMap (java.util.HashMap)5 IFile (org.eclipse.core.resources.IFile)5