Search in sources :

Example 16 with IPersistenceProvider

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

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

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

the class ResourceRegistry method createResource.

@SuppressWarnings("unchecked")
public T createResource(String uri, boolean hidden) {
    T resource = (T) getResourceFactoryRegistry().createResource(uri);
    try {
        IPersistenceProvider pp = getURIResolverRegistry().resolve(null, uri);
        resource.setResourcePersistenceProvider(pp);
    } catch (IllegalArgumentException e) {
    }
    addResource(resource, hidden);
    return resource;
}
Also used : IPersistenceProvider(org.whole.lang.codebase.IPersistenceProvider)

Example 19 with IPersistenceProvider

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

the class WholeModelWizardPage1 method getInitialContents.

protected InputStream getInitialContents() {
    IEntity model = templateFactory.create(templates[templateCombo.getSelectionIndex()]);
    persistenceKit = getPersistenceKit(saveAsCombo);
    try {
        IPersistenceProvider pp = new StringPersistenceProvider();
        defineResourceBindings(pp.getBindings(), fileHandle);
        persistenceKit.writeModel(model, pp);
        return pp.openInputStream();
    } catch (Exception e) {
        throw new IllegalStateException("error writing file contents", e);
    }
}
Also used : StringPersistenceProvider(org.whole.lang.codebase.StringPersistenceProvider) IEntity(org.whole.lang.model.IEntity) IPersistenceProvider(org.whole.lang.codebase.IPersistenceProvider)

Example 20 with IPersistenceProvider

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

the class HandlersBehavior method importEntity.

public static void importEntity(IBindingManager bm) {
    IEntityPartViewer viewer = (IEntityPartViewer) bm.wGetValue("viewer");
    IEntity focusEntity = bm.wGet("focusEntity");
    RunnableWithResult<IImportAsModelDialog> runnable = RunnableWithResult.create(() -> {
        Shell shell = viewer.getControl().getShell();
        IEclipseContext eclipseContext = (IEclipseContext) bm.wGetValue("eclipse#eclipseContext");
        IImportAsModelDialog dialog = eclipseContext.get(IImportAsModelDialogFactory.class).createImportAsModelDialog(shell, "Import model", EntityUtils.isComposite(focusEntity));
        dialog.show();
        return dialog;
    });
    E4Utils.syncExec(bm, runnable);
    IImportAsModelDialog dialog = runnable.get();
    if (!dialog.isConfirmed())
        return;
    Object[] files = dialog.getSelection();
    IPersistenceKit persistenceKit = dialog.getPersistenceKit();
    EntityDescriptor<?> stage = dialog.getStage();
    boolean adding = dialog.isForceAdding() || files.length > 1;
    for (int i = files.length - 1; i >= 0; i--) {
        IPersistenceProvider pp = new IFilePersistenceProvider((IFile) files[i]);
        try {
            IEntity importedEntity = persistenceKit.readModel(pp);
            if (!adding) {
                if (!CommonsEntityDescriptorEnum.SameStageFragment.equals(stage) || !EntityUtils.isReplaceable(focusEntity, importedEntity))
                    importedEntity = CommonsEntityFactory.instance.create(stage, importedEntity);
                IEntity parent = focusEntity.wGetParent();
                parent.wSet(focusEntity, importedEntity);
                break;
            } else {
                if (!CommonsEntityDescriptorEnum.SameStageFragment.equals(stage) || !EntityUtils.isAddable(focusEntity, importedEntity))
                    importedEntity = CommonsEntityFactory.instance.create(stage, importedEntity);
                if (bm.wIsSet("hilightPosition"))
                    focusEntity.wAdd(bm.wIntValue("hilightPosition"), importedEntity);
                else
                    focusEntity.wAdd(importedEntity);
            }
        } catch (Exception e) {
        // fail silently
        }
    }
}
Also used : IEntity(org.whole.lang.model.IEntity) IImportAsModelDialogFactory(org.whole.lang.ui.dialogs.IImportAsModelDialogFactory) OperationCanceledException(org.whole.lang.operations.OperationCanceledException) Shell(org.eclipse.swt.widgets.Shell) IImportAsModelDialog(org.whole.lang.ui.dialogs.IImportAsModelDialog) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) IFilePersistenceProvider(org.whole.lang.codebase.IFilePersistenceProvider) IPersistenceProvider(org.whole.lang.codebase.IPersistenceProvider) IPersistenceKit(org.whole.lang.codebase.IPersistenceKit) IEntityPartViewer(org.whole.lang.ui.viewers.IEntityPartViewer)

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