Search in sources :

Example 11 with IPersistenceProvider

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

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

Example 13 with IPersistenceProvider

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

the class XmlPrettyPrinterPerformanceTest method setUp.

@BeforeClass
public static void setUp() throws Exception {
    ReflectionFactory.deployWholePlatform();
    String packagePath = StringUtils.packagePath(XmlPrettyPrinterPerformanceTest.class.getPackage().getName());
    IPersistenceProvider pp = new ClasspathPersistenceProvider(packagePath + "/content.xml");
    xmlModel = XmlSourcePersistenceKit.instance().readModel(pp);
}
Also used : ClasspathPersistenceProvider(org.whole.lang.codebase.ClasspathPersistenceProvider) IPersistenceProvider(org.whole.lang.codebase.IPersistenceProvider) BeforeClass(org.junit.BeforeClass)

Example 14 with IPersistenceProvider

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

the class AbstractArtifactsGeneratorVisitor method writeContents.

protected void writeContents(IEntity model) {
    IPersistenceProvider pp = (IPersistenceProvider) env().wGetValue("persistenceProvider");
    boolean contentsWritten = false;
    if (env().wIsSet("persistenceKitId")) {
        IPersistenceKit pk = ReflectionFactory.getPersistenceKit(env().wStringValue("persistenceKitId"));
        if (pk.canApply(model))
            try {
                pk.writeModel(model, pp);
                contentsWritten = true;
            } catch (Exception inner) {
                throw new IllegalStateException(inner);
            }
    }
    try {
        if (!contentsWritten)
            PrettyPrintPersistenceKit.instance().writeModel(model, pp);
    } catch (RuntimeException runtime) {
        throw runtime;
    } catch (Exception outer) {
        throw new IllegalStateException(outer);
    }
}
Also used : IPersistenceProvider(org.whole.lang.codebase.IPersistenceProvider) IPersistenceKit(org.whole.lang.codebase.IPersistenceKit)

Example 15 with IPersistenceProvider

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

the class XsdMappingTest method testXmi20.

@Category(SlowTests.class)
@Test
public void testXmi20() throws Exception {
    InputStream is = loader.getResourceAsStream("xmi20.xsd");
    StreamSource ss = new StreamSource(is);
    Schema schema = factory.newSchema(ss);
    is = loader.getResourceAsStream("xmi20.xml");
    Validator v = schema.newValidator();
    v.validate(new StreamSource(is));
    is = loader.getResourceAsStream("xmi20.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 Xmi20Instance().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) Validator(javax.xml.validation.Validator) Xmi20Instance(org.whole.lang.xsd.mapping.samples.Xmi20Instance) 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