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));
}
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));
}
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;
}
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);
}
}
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
}
}
}
Aggregations