Search in sources :

Example 11 with IPersistenceKit

use of org.whole.lang.codebase.IPersistenceKit in project whole by wholeplatform.

the class AbstractReusablesSemanticsVisitor method readModel.

public static IEntity readModel(IEntity resource) {
    Object[] pkpp = (Object[]) resource.wGetValue();
    IPersistenceKit pk = (IPersistenceKit) pkpp[0];
    IPersistenceProvider pp = (IPersistenceProvider) pkpp[1];
    try {
        return pk.readModel(pp);
    } catch (FileNotFoundException e) {
        throw new IllegalArgumentException("Resource not found with the " + pk.getId() + " persistence at " + e.getMessage(), e);
    } catch (Exception e) {
        throw new IllegalArgumentException("Failed to load the resource with the given persistence: " + pk.getId(), e);
    }
}
Also used : FileNotFoundException(java.io.FileNotFoundException) IPersistenceProvider(org.whole.lang.codebase.IPersistenceProvider) IPersistenceKit(org.whole.lang.codebase.IPersistenceKit) FileNotFoundException(java.io.FileNotFoundException)

Example 12 with IPersistenceKit

use of org.whole.lang.codebase.IPersistenceKit in project whole by wholeplatform.

the class WorkflowsInterpreterVisitor method visit.

@Override
public void visit(LoadArtifacts entity) {
    try {
        IArtifactsEntity model = null;
        Variable variable = entity.getModel();
        String variableName = variable.getValue();
        boolean isDefined = getBindings().wIsSet(variableName);
        if (isDefined) {
            variable.accept(this);
            model = (IArtifactsEntity) getResult();
        }
        entity.getRootResource().accept(this);
        String resource = getResultString();
        ResourceKind resourceKind = entity.getRootResourceKind();
        Traverse traverse = Traverse.valueOf(DataTypeUtils.getAsPersistenceString(entity.getTraversalStrategy()));
        Synchronize synchronize = Synchronize.valueOf(DataTypeUtils.getAsPersistenceString(entity.getSynchronizeStrategy()));
        IPersistenceKit defaultPersistenceKit = getPersistenceKit(entity.getDefaultPersistence());
        IArtifactsEntity result = ArtifactsSynchronizerVisitor.synchronize(model, traverse, synchronize, createArtifactsBindings(resource, resourceKind), defaultPersistenceKit, true);
        if (isDefined) {
            if (EntityUtils.hasParent(model))
                model.wGetParent().wSet(model, result);
            getBindings().wSet(variableName, result);
        } else
            getBindings().wDef(variableName, result);
        setResult(result);
    } catch (Exception e) {
        throw IWholeRuntimeException.asWholeException(e, entity, getBindings());
    }
}
Also used : Variable(org.whole.lang.workflows.model.Variable) IArtifactsEntity(org.whole.lang.artifacts.model.IArtifactsEntity) Synchronize(org.whole.lang.artifacts.visitors.ArtifactsSynchronizerVisitor.Synchronize) ResourceKind(org.whole.lang.workflows.model.ResourceKind) IPersistenceKit(org.whole.lang.codebase.IPersistenceKit) MissingVariableException(org.whole.lang.visitors.MissingVariableException) IOException(java.io.IOException) IWholeRuntimeException(org.whole.lang.exceptions.IWholeRuntimeException) VisitException(org.whole.lang.visitors.VisitException) ParseException(org.whole.lang.parsers.ParseException) WholeIllegalArgumentException(org.whole.lang.exceptions.WholeIllegalArgumentException) Traverse(org.whole.lang.artifacts.visitors.ArtifactsSynchronizerVisitor.Traverse)

Example 13 with IPersistenceKit

use of org.whole.lang.codebase.IPersistenceKit in project whole by wholeplatform.

the class WorkflowsInterpreterVisitor method visit.

@Override
public void visit(LoadModel entity) {
    try {
        IPersistenceKit persistenceKit = getPersistenceKit(entity.getPersistence());
        IPersistenceProvider provider = getPersistenceProvider(entity);
        try {
            IEntity model = persistenceKit.readModel(provider);
            setResult(entity.getModel(), model);
        } catch (Exception e) {
            throw new IllegalArgumentException("Failed to load the resource with the given persistence: " + getResourceString(entity) + ", " + getPersistenceId(entity.getPersistence()), e);
        }
    } catch (Exception e) {
        throw IWholeRuntimeException.asWholeException(e, entity, getBindings());
    }
}
Also used : IEntity(org.whole.lang.model.IEntity) IPersistenceProvider(org.whole.lang.codebase.IPersistenceProvider) IPersistenceKit(org.whole.lang.codebase.IPersistenceKit) MissingVariableException(org.whole.lang.visitors.MissingVariableException) IOException(java.io.IOException) IWholeRuntimeException(org.whole.lang.exceptions.IWholeRuntimeException) VisitException(org.whole.lang.visitors.VisitException) ParseException(org.whole.lang.parsers.ParseException) WholeIllegalArgumentException(org.whole.lang.exceptions.WholeIllegalArgumentException) WholeIllegalArgumentException(org.whole.lang.exceptions.WholeIllegalArgumentException)

Example 14 with IPersistenceKit

use of org.whole.lang.codebase.IPersistenceKit in project whole by wholeplatform.

the class WorkflowsInterpreterVisitor method visit.

@Override
public void visit(SaveArtifacts entity) {
    try {
        entity.getModel().accept(this);
        IArtifactsEntity model = (IArtifactsEntity) getResult();
        entity.getRootResource().accept(this);
        String resource = getResultString();
        ResourceKind resourceKind = entity.getRootResourceKind();
        Traverse traverse = Traverse.valueOf(DataTypeUtils.getAsPersistenceString(entity.getTraversalStrategy()));
        Synchronize synchronize = Synchronize.valueOf(DataTypeUtils.getAsPersistenceString(entity.getSynchronizeStrategy()));
        IPersistenceKit defaultPersistenceKit = getPersistenceKit(entity.getDefaultPersistence());
        ArtifactsSynchronizerVisitor.synchronize(model, traverse, synchronize, createArtifactsBindings(resource, resourceKind), defaultPersistenceKit, false);
    } catch (Exception e) {
        throw IWholeRuntimeException.asWholeException(e, entity, getBindings());
    }
}
Also used : IArtifactsEntity(org.whole.lang.artifacts.model.IArtifactsEntity) Synchronize(org.whole.lang.artifacts.visitors.ArtifactsSynchronizerVisitor.Synchronize) ResourceKind(org.whole.lang.workflows.model.ResourceKind) IPersistenceKit(org.whole.lang.codebase.IPersistenceKit) MissingVariableException(org.whole.lang.visitors.MissingVariableException) IOException(java.io.IOException) IWholeRuntimeException(org.whole.lang.exceptions.IWholeRuntimeException) VisitException(org.whole.lang.visitors.VisitException) ParseException(org.whole.lang.parsers.ParseException) WholeIllegalArgumentException(org.whole.lang.exceptions.WholeIllegalArgumentException) Traverse(org.whole.lang.artifacts.visitors.ArtifactsSynchronizerVisitor.Traverse)

Example 15 with IPersistenceKit

use of org.whole.lang.codebase.IPersistenceKit in project whole by wholeplatform.

the class AbstractReusablesSemanticsVisitor method writeModel.

public static void writeModel(IEntity model, IEntity resource) {
    Object[] pkpp = (Object[]) resource.wGetValue();
    IPersistenceKit pk = (IPersistenceKit) pkpp[0];
    IPersistenceProvider pp = (IPersistenceProvider) pkpp[1];
    try {
        pk.writeModel(model, pp);
    } catch (Exception e) {
        throw new IllegalArgumentException("Failed to write the resource with the given persistence: " + pp + ", " + pk.getId(), e);
    }
}
Also used : IPersistenceProvider(org.whole.lang.codebase.IPersistenceProvider) IPersistenceKit(org.whole.lang.codebase.IPersistenceKit) FileNotFoundException(java.io.FileNotFoundException)

Aggregations

IPersistenceKit (org.whole.lang.codebase.IPersistenceKit)33 IEntity (org.whole.lang.model.IEntity)13 IPersistenceProvider (org.whole.lang.codebase.IPersistenceProvider)7 StringPersistenceProvider (org.whole.lang.codebase.StringPersistenceProvider)6 IOException (java.io.IOException)4 IFile (org.eclipse.core.resources.IFile)4 GridData (org.eclipse.swt.layout.GridData)4 Shell (org.eclipse.swt.widgets.Shell)4 IBindingManager (org.whole.lang.bindings.IBindingManager)4 IFilePersistenceProvider (org.whole.lang.codebase.IFilePersistenceProvider)4 IWholeRuntimeException (org.whole.lang.exceptions.IWholeRuntimeException)4 WholeIllegalArgumentException (org.whole.lang.exceptions.WholeIllegalArgumentException)4 ParseException (org.whole.lang.parsers.ParseException)4 IImportAsModelDialog (org.whole.lang.ui.dialogs.IImportAsModelDialog)4 MissingVariableException (org.whole.lang.visitors.MissingVariableException)4 VisitException (org.whole.lang.visitors.VisitException)4 ArrayList (java.util.ArrayList)3 IEclipseContext (org.eclipse.e4.core.contexts.IEclipseContext)3 SelectionEvent (org.eclipse.swt.events.SelectionEvent)3 Label (org.eclipse.swt.widgets.Label)3