Search in sources :

Example 6 with IPersistenceProvider

use of org.whole.lang.codebase.IPersistenceProvider 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)

Example 7 with IPersistenceProvider

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

the class XsdMappingTest method testPain.

@Category(SlowTests.class)
@Test
public void testPain() throws Exception {
    InputStream is = loader.getResourceAsStream("pain.xsd");
    StreamSource ss = new StreamSource(is);
    Schema schema = factory.newSchema(ss);
    is = loader.getResourceAsStream("pain.xml");
    Validator v = schema.newValidator();
    v.validate(new StreamSource(is));
    is = loader.getResourceAsStream("pain.xml");
    IPersistenceProvider pp = new StreamPersistenceProvider(is);
    pp.getBindings().wDefValue("packageName", "org.whole.lang.xsd.mapping.samples");
    IEntity model = XsiPersistenceKit.instance().readModel(pp);
    Assert.assertTrue(Matcher.match(new PainInstance().create(), model));
}
Also used : IEntity(org.whole.lang.model.IEntity) InputStream(java.io.InputStream) StreamSource(javax.xml.transform.stream.StreamSource) Schema(javax.xml.validation.Schema) PainInstance(org.whole.lang.xsd.mapping.samples.PainInstance) IPersistenceProvider(org.whole.lang.codebase.IPersistenceProvider) StreamPersistenceProvider(org.whole.lang.codebase.StreamPersistenceProvider) Validator(javax.xml.validation.Validator) Category(org.junit.experimental.categories.Category) Test(org.junit.Test)

Example 8 with IPersistenceProvider

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

the class XsdMappingTest method testDatatypes.

@Category(SlowTests.class)
@Test
public void testDatatypes() throws Exception {
    InputStream is = loader.getResourceAsStream("datatypes.xsd");
    StreamSource ss = new StreamSource(is);
    Schema schema = factory.newSchema(ss);
    is = loader.getResourceAsStream("datatypes.xml");
    Validator v = schema.newValidator();
    v.validate(new StreamSource(is));
    is = loader.getResourceAsStream("datatypes.xml");
    IPersistenceProvider pp = new StreamPersistenceProvider(is);
    pp.getBindings().wDefValue("packageName", "org.whole.lang.xsd.mapping.samples");
    IEntity model = XsiPersistenceKit.instance().readModel(pp);
    Assert.assertTrue(Matcher.match(new DatatypesInstance().create(), model));
}
Also used : DatatypesInstance(org.whole.lang.xsd.mapping.samples.DatatypesInstance) IEntity(org.whole.lang.model.IEntity) InputStream(java.io.InputStream) StreamSource(javax.xml.transform.stream.StreamSource) Schema(javax.xml.validation.Schema) IPersistenceProvider(org.whole.lang.codebase.IPersistenceProvider) StreamPersistenceProvider(org.whole.lang.codebase.StreamPersistenceProvider) Validator(javax.xml.validation.Validator) Category(org.junit.experimental.categories.Category) Test(org.junit.Test)

Example 9 with IPersistenceProvider

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

the class AbstractE4Part method save.

@Persist
public void save() {
    if (modelInput != null) {
        workspace.removeResourceChangeListener(resourceListener);
        IPersistenceProvider pp = modelInput.getPersistenceProvider();
        try {
            RootFragment rootFragment = (RootFragment) viewer.getContents().getModel();
            modelInput.getPersistenceKit().writeModel(rootFragment.wGetRoot(), pp);
            viewer.getCommandStack().markSaveLocation();
            part.setDirty(false);
        } catch (Exception e) {
        } finally {
            workspace.addResourceChangeListener(resourceListener);
        }
    }
}
Also used : IPersistenceProvider(org.whole.lang.codebase.IPersistenceProvider) RootFragment(org.whole.lang.commons.model.RootFragment) Persist(org.eclipse.e4.ui.di.Persist)

Example 10 with IPersistenceProvider

use of org.whole.lang.codebase.IPersistenceProvider 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)

Aggregations

IPersistenceProvider (org.whole.lang.codebase.IPersistenceProvider)22 IEntity (org.whole.lang.model.IEntity)15 Test (org.junit.Test)10 InputStream (java.io.InputStream)9 StreamSource (javax.xml.transform.stream.StreamSource)9 Schema (javax.xml.validation.Schema)9 Validator (javax.xml.validation.Validator)9 StreamPersistenceProvider (org.whole.lang.codebase.StreamPersistenceProvider)9 Category (org.junit.experimental.categories.Category)8 IPersistenceKit (org.whole.lang.codebase.IPersistenceKit)7 IFilePersistenceProvider (org.whole.lang.codebase.IFilePersistenceProvider)3 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 IFile (org.eclipse.core.resources.IFile)2 Shell (org.eclipse.swt.widgets.Shell)2 IBindingManager (org.whole.lang.bindings.IBindingManager)2 StringPersistenceProvider (org.whole.lang.codebase.StringPersistenceProvider)2 IWholeRuntimeException (org.whole.lang.exceptions.IWholeRuntimeException)2 WholeIllegalArgumentException (org.whole.lang.exceptions.WholeIllegalArgumentException)2 ParseException (org.whole.lang.parsers.ParseException)2