Search in sources :

Example 11 with IBindingScope

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

the class SequenceIterator method updateCurrentIterator.

protected boolean updateCurrentIterator() {
    final IBindingManager bindings = getBindings();
    final Map<String, IEntity> lookaheadBindings = new HashMap<String, IEntity>();
    IBindingScope currentLookaheadScope = currentIterator().lookaheadScope();
    for (String name : currentLookaheadScope.wLocalNames()) {
        bindings.wUnset(name);
        lookaheadBindings.put(name, currentLookaheadScope.wGet(name));
    }
    if (currentIterator().hasNext())
        return true;
    else {
        for (Entry<String, IEntity> entry : lookaheadBindings.entrySet()) if (bindings.wIsSet(entry.getKey()))
            bindings.wSet(entry.getKey(), entry.getValue());
        else
            bindings.wDef(entry.getKey(), entry.getValue());
        lookaheadScope().getFilterNames().addAll(lookaheadBindings.keySet());
        while (iteratorIndex < iteratorChain.length - 1) {
            iteratorIndex++;
            // currentIterator().reset(resetEntity);
            if (currentIterator().hasNext())
                return true;
        }
        return false;
    }
}
Also used : IEntity(org.whole.lang.model.IEntity) HashMap(java.util.HashMap) IBindingScope(org.whole.lang.bindings.IBindingScope) IBindingManager(org.whole.lang.bindings.IBindingManager)

Example 12 with IBindingScope

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

the class WholeOperationLaunchConfigurationDelegate method launch.

public void launch(ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException {
    if (!"run".equals(mode))
        throw new CoreException(new Status(Status.CANCEL, PLUGIN_ID, 1, "Only 'run' mode supported by this launcher", null));
    String operationId = configuration.getAttribute(OPERATION_ID, (String) null);
    if (operationId == null)
        throw new CoreException(new Status(Status.CANCEL, PLUGIN_ID, 1, "No operation selected", null));
    String targetModelPath = configuration.getAttribute(TARGET_MODEL_PATH, (String) null);
    if (targetModelPath == null)
        throw new CoreException(new Status(Status.CANCEL, PLUGIN_ID, 1, "No target model selected", null));
    String targetModelPersistence = configuration.getAttribute(TARGET_MODEL_PERSISTENCE, (String) null);
    if (targetModelPersistence == null)
        throw new CoreException(new Status(Status.CANCEL, PLUGIN_ID, 1, "No persistence selected", null));
    try {
        monitor.beginTask("Executing " + operationId + " operation...", 100);
        if (monitor.isCanceled())
            return;
        IOperationProgressMonitor operationProgressMonitor = new OperationProgressMonitorAdapter(monitor);
        IFile targetModelFile = ResourcesPlugin.getWorkspace().getRoot().getFile(Path.fromPortableString(targetModelPath));
        IBindingManager bindings = BindingManagerFactory.instance.createBindingManager();
        ResourceUtils.defineResourceBindings(bindings, targetModelFile);
        IBindingScope scope = LaunchConfigurationUtils.loadBindingScope(configuration);
        bindings.wEnterScope(scope, true);
        IPersistenceKit persistenceKit = ReflectionFactory.getPersistenceKit(targetModelPersistence);
        IEntity model = persistenceKit.readModel(new IFilePersistenceProvider(targetModelFile));
        IOperationLauncher operationLauncher = OperationLauncherRegistry.instance.getOperationLauncher(operationId);
        InputStream is = System.in;
        OutputStream os = System.out;
        if (configuration.getAttribute(CONSOLE_VIEW, false)) {
            IOConsole ioConsole = WholeConsoleFactory.getIOConsole();
            is = ioConsole.getInputStream();
            os = ioConsole.newOutputStream();
        }
        operationLauncher.launch(model, bindings, is, os, operationProgressMonitor);
        if (configuration.getAttribute(PERSIST_CHANGES, false))
            persistenceKit.writeModel(model, new IFilePersistenceProvider(targetModelFile));
    } catch (Throwable t) {
        WholePlugin.log(t);
    } finally {
        monitor.done();
    }
}
Also used : Status(org.eclipse.core.runtime.Status) IFile(org.eclipse.core.resources.IFile) IEntity(org.whole.lang.model.IEntity) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) IOperationProgressMonitor(org.whole.lang.operations.IOperationProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) IBindingScope(org.whole.lang.bindings.IBindingScope) IBindingManager(org.whole.lang.bindings.IBindingManager) IFilePersistenceProvider(org.whole.lang.codebase.IFilePersistenceProvider) OperationProgressMonitorAdapter(org.whole.lang.operations.OperationProgressMonitorAdapter) IPersistenceKit(org.whole.lang.codebase.IPersistenceKit) IOConsole(org.eclipse.ui.console.IOConsole)

Example 13 with IBindingScope

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

the class MatcherTest method testSubstituteValue.

@Test
public void testSubstituteValue() {
    SimpleEntity entityPattern = new SimpleEntityPattern().create();
    IBindingScope args = BindingManagerFactory.instance.createSimpleScope();
    args.wDefValue("entityName", "SE");
    Matcher.substitute(entityPattern, args, false);
    assertEquals("SE", entityPattern.getName().wStringValue());
    assertEquals(ModelsEntityDescriptorEnum.SimpleName, entityPattern.getName().wGetEntityDescriptor());
}
Also used : IBindingScope(org.whole.lang.bindings.IBindingScope) SimpleEntity(org.whole.lang.models.model.SimpleEntity) Test(org.junit.Test)

Aggregations

IBindingScope (org.whole.lang.bindings.IBindingScope)13 IEntity (org.whole.lang.model.IEntity)8 IBindingManager (org.whole.lang.bindings.IBindingManager)5 Test (org.junit.Test)3 CoreException (org.eclipse.core.runtime.CoreException)2 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 HashMap (java.util.HashMap)1 IFile (org.eclipse.core.resources.IFile)1 Status (org.eclipse.core.runtime.Status)1 IOConsole (org.eclipse.ui.console.IOConsole)1 IFilePersistenceProvider (org.whole.lang.codebase.IFilePersistenceProvider)1 IPersistenceKit (org.whole.lang.codebase.IPersistenceKit)1 StringPersistenceProvider (org.whole.lang.codebase.StringPersistenceProvider)1 Model (org.whole.lang.models.model.Model)1 SimpleEntity (org.whole.lang.models.model.SimpleEntity)1 SimpleName (org.whole.lang.models.model.SimpleName)1 IOperationProgressMonitor (org.whole.lang.operations.IOperationProgressMonitor)1 OperationProgressMonitorAdapter (org.whole.lang.operations.OperationProgressMonitorAdapter)1 IReusablesEntity (org.whole.lang.reusables.model.IReusablesEntity)1