Search in sources :

Example 6 with StringPersistenceProvider

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

the class ActionFactory method createReplaceFragmentAction.

public IUpdatableAction createReplaceFragmentAction(String label, IEntity predicate, IEntity fragment) {
    try {
        Map<String, Object> parameters = new HashMap<String, Object>();
        StringPersistenceProvider spp = new StringPersistenceProvider();
        ReflectionFactory.getDefaultPersistenceKit().writeModel(fragment, spp);
        parameters.put(FRAGMENT_XWL_PARAMETER_ID, spp.getStore());
        spp = new StringPersistenceProvider();
        ReflectionFactory.getDefaultPersistenceKit().writeModel(predicate, spp);
        parameters.put(PREDICATE_XWL_PARAMETER_ID, spp.getStore());
        return createE4ActionAdapter(label, REPLACE_ICON_URI, REPLACE_FRAGMENT_COMMAND_ID, parameters);
    } catch (Exception e) {
        throw new IllegalStateException(e);
    }
}
Also used : StringPersistenceProvider(org.whole.lang.codebase.StringPersistenceProvider) HashMap(java.util.HashMap)

Example 7 with StringPersistenceProvider

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

the class WorkflowsInterpreterVisitor method afterWriteModel.

protected void afterWriteModel(SaveModel entity, IPersistenceProvider provider) throws Exception {
    if (getResourceKind(entity).wContainsValue(ResourceKindEnum.VARIABLE)) {
        String result = ((StringPersistenceProvider) provider).getStore();
        Variable variable = (Variable) entity.getResource();
        getBindings().wDefValue(variable.getValue(), result);
    }
}
Also used : Variable(org.whole.lang.workflows.model.Variable) StringPersistenceProvider(org.whole.lang.codebase.StringPersistenceProvider)

Example 8 with StringPersistenceProvider

use of org.whole.lang.codebase.StringPersistenceProvider 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 9 with StringPersistenceProvider

use of org.whole.lang.codebase.StringPersistenceProvider 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 10 with StringPersistenceProvider

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

the class XsdMappingTest method testModelsToXmlSchemaXXX.

@Test
public void testModelsToXmlSchemaXXX() throws Exception {
    IBindingManager bm = BindingManagerFactory.instance.createArguments();
    PathExpression path = new ModelToXmlSchemaQuery().create();
    Model model = (Model) ModelsTemplateManager.instance().create("Models model");
    String uri = model.getUri().getValue();
    ILanguageKit lk = ReflectionFactory.getLanguageKit(uri);
    IEntity tuple = BehaviorUtils.evaluateFirstResult(path, model, bm);
    Assert.assertNotNull(tuple);
    InterpreterOperation.interpret(tuple.wGet(1));
    ITemplateManager tm = lk.getTemplateManager();
    IEntity entity = tm.create("Editors model");
    IPersistenceProvider pp = new StringPersistenceProvider();
    XsiPersistenceKit.instance().writeModel(entity, pp);
    IEntity entity2 = XsiPersistenceKit.instance().readModel(pp);
    boolean matches = Matcher.match(entity, entity2);
    Assert.assertTrue(matches);
}
Also used : ModelToXmlSchemaQuery(org.whole.lang.xsd.codebase.ModelToXmlSchemaQuery) PathExpression(org.whole.lang.queries.model.PathExpression) StringPersistenceProvider(org.whole.lang.codebase.StringPersistenceProvider) IEntity(org.whole.lang.model.IEntity) IBindingManager(org.whole.lang.bindings.IBindingManager) Model(org.whole.lang.models.model.Model) ITemplateManager(org.whole.lang.templates.ITemplateManager) IPersistenceProvider(org.whole.lang.codebase.IPersistenceProvider) ILanguageKit(org.whole.lang.reflect.ILanguageKit) Test(org.junit.Test)

Aggregations

StringPersistenceProvider (org.whole.lang.codebase.StringPersistenceProvider)20 IEntity (org.whole.lang.model.IEntity)10 IPersistenceKit (org.whole.lang.codebase.IPersistenceKit)6 HashMap (java.util.HashMap)5 Test (org.junit.Test)4 IBindingManager (org.whole.lang.bindings.IBindingManager)4 CoreException (org.eclipse.core.runtime.CoreException)2 IPersistenceProvider (org.whole.lang.codebase.IPersistenceProvider)2 StreamPersistenceProvider (org.whole.lang.codebase.StreamPersistenceProvider)2 JsonFactory (com.fasterxml.jackson.core.JsonFactory)1 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)1 ArrayList (java.util.ArrayList)1 ChangeBoundsRequest (org.eclipse.gef.requests.ChangeBoundsRequest)1 Shell (org.eclipse.swt.widgets.Shell)1 IBindingScope (org.whole.lang.bindings.IBindingScope)1 ClasspathPersistenceProvider (org.whole.lang.codebase.ClasspathPersistenceProvider)1 JSONGeneratorBuilderOperation (org.whole.lang.json.util.JSONGeneratorBuilderOperation)1 Model (org.whole.lang.models.model.Model)1 PathExpression (org.whole.lang.queries.model.PathExpression)1 ILanguageKit (org.whole.lang.reflect.ILanguageKit)1