Search in sources :

Example 1 with IPersistenceProvider

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

the class WorkflowsInterpreterVisitor method visit.

@Override
public void visit(SaveModel entity) {
    try {
        IPersistenceKit persistenceKit = getPersistenceKit(entity.getPersistence());
        IPersistenceProvider provider = getPersistenceProvider(entity);
        entity.getModel().accept(this);
        IEntity model = getResult();
        try {
            persistenceKit.writeModel(model, provider);
            afterWriteModel(entity, provider);
        } catch (Exception e) {
            throw new IllegalArgumentException("Failed to save 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 2 with IPersistenceProvider

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

the class XsdMappingTest method testMaven.

@Category(SlowTests.class)
@Test
public void testMaven() throws Exception {
    InputStream is = loader.getResourceAsStream("maven-v4_0_0.xsd");
    StreamSource ss = new StreamSource(is);
    Schema schema = factory.newSchema(ss);
    is = loader.getResourceAsStream("maven-v4_0_0.xml");
    Validator v = schema.newValidator();
    v.validate(new StreamSource(is));
    is = loader.getResourceAsStream("maven-v4_0_0.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 Maven400Instance().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) IPersistenceProvider(org.whole.lang.codebase.IPersistenceProvider) StreamPersistenceProvider(org.whole.lang.codebase.StreamPersistenceProvider) Maven400Instance(org.whole.lang.xsd.mapping.samples.Maven400Instance) Validator(javax.xml.validation.Validator) Category(org.junit.experimental.categories.Category) Test(org.junit.Test)

Example 3 with IPersistenceProvider

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

the class XsdMappingTest method testSimpleContent.

// Requires an Internet connection
// FIXME remove KnownFailingTests
@Category({ SlowTests.class, KnownFailingTests.class })
@Test
public void testSimpleContent() throws Exception {
    InputStream is = loader.getResourceAsStream("simpleContent.xsd");
    StreamSource ss = new StreamSource(is);
    Schema schema = factory.newSchema(ss);
    is = loader.getResourceAsStream("simpleContent.xml");
    Validator v = schema.newValidator();
    v.validate(new StreamSource(is));
    is = loader.getResourceAsStream("simpleContent.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 SimpleContentInstance().create(), model));
}
Also used : SimpleContentInstance(org.whole.lang.xsd.mapping.samples.SimpleContentInstance) 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 4 with IPersistenceProvider

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

the class XsdMappingTest method testChoiceSample.

@Test
public void testChoiceSample() throws Exception {
    InputStream is = loader.getResourceAsStream("ChoiceSample.xsd");
    StreamSource ss = new StreamSource(is);
    Schema schema = factory.newSchema(ss);
    is = loader.getResourceAsStream("ChoiceSample.xml");
    Validator v = schema.newValidator();
    v.validate(new StreamSource(is));
    is = loader.getResourceAsStream("ChoiceSample.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 ChoiceSampleInstance().create(), model));
}
Also used : IEntity(org.whole.lang.model.IEntity) ChoiceSampleInstance(org.whole.lang.xsd.mapping.samples.ChoiceSampleInstance) 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) Test(org.junit.Test)

Example 5 with IPersistenceProvider

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

the class XsdMappingTest method testFreemind.

@Category(SlowTests.class)
@Test
public void testFreemind() throws Exception {
    InputStream is = loader.getResourceAsStream("freemind.xsd");
    StreamSource ss = new StreamSource(is);
    Schema schema = factory.newSchema(ss);
    is = loader.getResourceAsStream("freemindExample.xml");
    Validator v = schema.newValidator();
    v.validate(new StreamSource(is));
    is = loader.getResourceAsStream("freemindExample.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 FreemindInstance(model.wGetLanguageKit()).create(), model));
}
Also used : IEntity(org.whole.lang.model.IEntity) InputStream(java.io.InputStream) FreemindInstance(org.whole.lang.xsd.mapping.samples.FreemindInstance) 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)

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