use of org.whole.lang.codebase.IPersistenceProvider in project whole by wholeplatform.
the class XsdMappingTest method testModelsToXmlSchemaXXX.
@Test
public void testModelsToXmlSchemaXXX() throws Exception {
IBindingManager bm = BindingManagerFactory.instance.createArguments();
PathExpression path = new ModelToXmlSchemaQuery().create();
Model model = (Model) ModelsTemplateManager.instance().create("Models model");
String uri = model.getUri().getValue();
ILanguageKit lk = ReflectionFactory.getLanguageKit(uri);
IEntity tuple = BehaviorUtils.evaluateFirstResult(path, model, bm);
Assert.assertNotNull(tuple);
InterpreterOperation.interpret(tuple.wGet(1));
ITemplateManager tm = lk.getTemplateManager();
IEntity entity = tm.create("Editors model");
IPersistenceProvider pp = new StringPersistenceProvider();
XsiPersistenceKit.instance().writeModel(entity, pp);
IEntity entity2 = XsiPersistenceKit.instance().readModel(pp);
boolean matches = Matcher.match(entity, entity2);
Assert.assertTrue(matches);
}
use of org.whole.lang.codebase.IPersistenceProvider in project whole by wholeplatform.
the class XsdMappingTest method testPain.
@Category(SlowTests.class)
@Test
public void testPain() throws Exception {
InputStream is = loader.getResourceAsStream("pain.xsd");
StreamSource ss = new StreamSource(is);
Schema schema = factory.newSchema(ss);
is = loader.getResourceAsStream("pain.xml");
Validator v = schema.newValidator();
v.validate(new StreamSource(is));
is = loader.getResourceAsStream("pain.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 PainInstance().create(), model));
}
use of org.whole.lang.codebase.IPersistenceProvider in project whole by wholeplatform.
the class XsdMappingTest method testDatatypes.
@Category(SlowTests.class)
@Test
public void testDatatypes() throws Exception {
InputStream is = loader.getResourceAsStream("datatypes.xsd");
StreamSource ss = new StreamSource(is);
Schema schema = factory.newSchema(ss);
is = loader.getResourceAsStream("datatypes.xml");
Validator v = schema.newValidator();
v.validate(new StreamSource(is));
is = loader.getResourceAsStream("datatypes.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 DatatypesInstance().create(), model));
}
use of org.whole.lang.codebase.IPersistenceProvider in project whole by wholeplatform.
the class AbstractE4Part method save.
@Persist
public void save() {
if (modelInput != null) {
workspace.removeResourceChangeListener(resourceListener);
IPersistenceProvider pp = modelInput.getPersistenceProvider();
try {
RootFragment rootFragment = (RootFragment) viewer.getContents().getModel();
modelInput.getPersistenceKit().writeModel(rootFragment.wGetRoot(), pp);
viewer.getCommandStack().markSaveLocation();
part.setDirty(false);
} catch (Exception e) {
} finally {
workspace.addResourceChangeListener(resourceListener);
}
}
}
use of org.whole.lang.codebase.IPersistenceProvider in project whole by wholeplatform.
the class AbstractReusablesSemanticsVisitor method readModel.
public static IEntity readModel(IEntity resource) {
Object[] pkpp = (Object[]) resource.wGetValue();
IPersistenceKit pk = (IPersistenceKit) pkpp[0];
IPersistenceProvider pp = (IPersistenceProvider) pkpp[1];
try {
return pk.readModel(pp);
} catch (FileNotFoundException e) {
throw new IllegalArgumentException("Resource not found with the " + pk.getId() + " persistence at " + e.getMessage(), e);
} catch (Exception e) {
throw new IllegalArgumentException("Failed to load the resource with the given persistence: " + pk.getId(), e);
}
}
Aggregations