Search in sources :

Example 21 with StreamPersistenceProvider

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

the class ArtifactsLoadFileContentsVisitor method visit.

@Override
public void visit(FileArtifact entity) {
    if (force || EntityUtils.isResolver(entity.getContent())) {
        InputStream is = getArtifactsOperations().getContents(getResource());
        IPersistenceKit persistenceKit = persistenceKitStack.peek();
        try {
            IEntity model = persistenceKit.readModel(new StreamPersistenceProvider(is));
            entity.setContent(CommonsEntityAdapterFactory.createStageUpFragment(ArtifactsEntityDescriptorEnum.Content, model));
        } catch (Exception e) {
        // TODO parameterize 	throw new IllegalStateException(e);
        }
    }
}
Also used : IEntity(org.whole.lang.model.IEntity) InputStream(java.io.InputStream) StreamPersistenceProvider(org.whole.lang.codebase.StreamPersistenceProvider) IPersistenceKit(org.whole.lang.codebase.IPersistenceKit)

Example 22 with StreamPersistenceProvider

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

Example 23 with StreamPersistenceProvider

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

the class XsdMappingTest method testSCTScf.

@Category(SlowTests.class)
@Test
public void testSCTScf() throws Exception {
    InputStream is = loader.getResourceAsStream("SepaSct.xsd");
    StreamSource ss = new StreamSource(is);
    Schema schema = factory.newSchema(ss);
    is = loader.getResourceAsStream("SepaSct.xml");
    Validator v = schema.newValidator();
    v.validate(new StreamSource(is));
    is = loader.getResourceAsStream("SepaSct.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 SepaSctInstance().create(), model));
}
Also used : SepaSctInstance(org.whole.lang.xsd.mapping.samples.SepaSctInstance) 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 24 with StreamPersistenceProvider

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

the class XsdMappingTest method testAppEngine.

@Category(SlowTests.class)
@Test
public void testAppEngine() throws Exception {
    InputStream is = loader.getResourceAsStream("appengine-web.xsd");
    StreamSource ss = new StreamSource(is);
    Schema schema = factory.newSchema(ss);
    is = loader.getResourceAsStream("appengine-web.xml");
    Validator v = schema.newValidator();
    v.validate(new StreamSource(is));
    is = loader.getResourceAsStream("appengine-web.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 AppEngineWebInstance().create(), model));
    is = loader.getResourceAsStream("cron.xsd");
    ss = new StreamSource(is);
    schema = factory.newSchema(ss);
    is = loader.getResourceAsStream("cron.xml");
    v = schema.newValidator();
    v.validate(new StreamSource(is));
    is = loader.getResourceAsStream("cron.xml");
    pp = new StreamPersistenceProvider(is);
    pp.getBindings().wDefValue("packageName", "org.whole.lang.xsd.mapping.samples");
    model = XsiPersistenceKit.instance().readModel(pp);
    Assert.assertTrue(Matcher.match(new CronInstance(model.wGetLanguageKit()).create(), model));
    is = loader.getResourceAsStream("queue.xsd");
    ss = new StreamSource(is);
    schema = factory.newSchema(ss);
    is = loader.getResourceAsStream("queue.xml");
    v = schema.newValidator();
    v.validate(new StreamSource(is));
    is = loader.getResourceAsStream("queue.xml");
    pp = new StreamPersistenceProvider(is);
    pp.getBindings().wDefValue("packageName", "org.whole.lang.xsd.mapping.samples");
    model = XsiPersistenceKit.instance().readModel(pp);
    Assert.assertTrue(Matcher.match(new QueueInstance(model.wGetLanguageKit()).create(), model));
    is = loader.getResourceAsStream("datastore-indexes.xsd");
    ss = new StreamSource(is);
    schema = factory.newSchema(ss);
    is = loader.getResourceAsStream("datastore-indexes.xml");
    v = schema.newValidator();
    v.validate(new StreamSource(is));
    is = loader.getResourceAsStream("datastore-indexes.xml");
    pp = new StreamPersistenceProvider(is);
    pp.getBindings().wDefValue("packageName", "org.whole.lang.xsd.mapping.samples");
    model = XsiPersistenceKit.instance().readModel(pp);
    Assert.assertTrue(Matcher.match(new DatastoreIndexesInstance(model.wGetLanguageKit()).create(), model));
    is = loader.getResourceAsStream("dos.xsd");
    ss = new StreamSource(is);
    schema = factory.newSchema(ss);
    is = loader.getResourceAsStream("dos.xml");
    v = schema.newValidator();
    v.validate(new StreamSource(is));
    is = loader.getResourceAsStream("dos.xml");
    pp = new StreamPersistenceProvider(is);
    pp.getBindings().wDefValue("packageName", "org.whole.lang.xsd.mapping.samples");
    model = XsiPersistenceKit.instance().readModel(pp);
    Assert.assertTrue(Matcher.match(new DosInstance(model.wGetLanguageKit()).create(), model));
    is = loader.getResourceAsStream("jdoconfig_2_3.xsd");
    ss = new StreamSource(is);
    schema = factory.newSchema(ss);
    is = loader.getResourceAsStream("jdoconfig.xml");
    v = schema.newValidator();
    v.validate(new StreamSource(is));
    is = loader.getResourceAsStream("jdoconfig.xml");
    pp = new StreamPersistenceProvider(is);
    pp.getBindings().wDefValue("packageName", "org.whole.lang.xsd.mapping.samples");
    model = XsiPersistenceKit.instance().readModel(pp);
    Assert.assertTrue(Matcher.match(new JDOConfigInstance().create(), model));
}
Also used : IEntity(org.whole.lang.model.IEntity) AppEngineWebInstance(org.whole.lang.xsd.mapping.samples.AppEngineWebInstance) CronInstance(org.whole.lang.xsd.mapping.samples.CronInstance) DatastoreIndexesInstance(org.whole.lang.xsd.mapping.samples.DatastoreIndexesInstance) InputStream(java.io.InputStream) StreamSource(javax.xml.transform.stream.StreamSource) Schema(javax.xml.validation.Schema) QueueInstance(org.whole.lang.xsd.mapping.samples.QueueInstance) IPersistenceProvider(org.whole.lang.codebase.IPersistenceProvider) StreamPersistenceProvider(org.whole.lang.codebase.StreamPersistenceProvider) DosInstance(org.whole.lang.xsd.mapping.samples.DosInstance) JDOConfigInstance(org.whole.lang.xsd.mapping.samples.JDOConfigInstance) Validator(javax.xml.validation.Validator) Category(org.junit.experimental.categories.Category) Test(org.junit.Test)

Example 25 with StreamPersistenceProvider

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

the class JSONPersistencesTest method testParseAndGenerateWithBuilderOperation.

@Test
public void testParseAndGenerateWithBuilderOperation() throws Exception {
    IEntity sampleModel = JSONSourcePersistenceKit.instance().readModel(new StreamPersistenceProvider(getClass().getResourceAsStream("sample.json")));
    StringPersistenceProvider pp = new StringPersistenceProvider();
    JsonGenerator generator = new JsonFactory().createGenerator(pp.getOutputStream());
    generator.useDefaultPrettyPrinter();
    JSONGeneratorBuilderOperation op = new JSONGeneratorBuilderOperation(generator);
    new ModelTemplate(sampleModel).apply(op);
    generator.close();
    assertEquals(sampleString, pp.getStore());
}
Also used : ModelTemplate(org.whole.lang.templates.ModelTemplate) StringPersistenceProvider(org.whole.lang.codebase.StringPersistenceProvider) IEntity(org.whole.lang.model.IEntity) JsonFactory(com.fasterxml.jackson.core.JsonFactory) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) StreamPersistenceProvider(org.whole.lang.codebase.StreamPersistenceProvider) JSONGeneratorBuilderOperation(org.whole.lang.json.util.JSONGeneratorBuilderOperation) Test(org.junit.Test)

Aggregations

StreamPersistenceProvider (org.whole.lang.codebase.StreamPersistenceProvider)28 IEntity (org.whole.lang.model.IEntity)24 Test (org.junit.Test)20 Category (org.junit.experimental.categories.Category)13 InputStream (java.io.InputStream)12 StreamSource (javax.xml.transform.stream.StreamSource)9 Schema (javax.xml.validation.Schema)9 Validator (javax.xml.validation.Validator)9 IPersistenceProvider (org.whole.lang.codebase.IPersistenceProvider)9 IBindingManager (org.whole.lang.bindings.IBindingManager)4 ModelBuilderOperation (org.whole.lang.builders.ModelBuilderOperation)4 ModelTemplate (org.whole.lang.templates.ModelTemplate)4 File (java.io.File)3 IPersistenceKit (org.whole.lang.codebase.IPersistenceKit)3 XmlNormalizerBuilderOperation (org.whole.lang.xml.codebase.XmlNormalizerBuilderOperation)3 JsonFactory (com.fasterxml.jackson.core.JsonFactory)2 PrintWriter (java.io.PrintWriter)2 StringPersistenceProvider (org.whole.lang.codebase.StringPersistenceProvider)2 XmlPrettyPrinterBuilderOperation (org.whole.lang.xml.codebase.XmlPrettyPrinterBuilderOperation)2 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)1