use of org.whole.lang.codebase.FilePersistenceProvider in project whole by wholeplatform.
the class ReusablesDynamicCompilerVisitor method visit.
@Override
public void visit(FileSystem entity) {
entity.getPersistence().accept(this);
IEntityIterator<?> persistenceIterator = getResultIterator();
entity.getContent().accept(this);
IEntityIterator<?> contentIterator = getResultIterator();
setResultIterator(IteratorFactory.composeIterator(IteratorFactory.singleValuedRunnableIterator(new ResourcePersistenceRunnable() {
protected IPersistenceProvider getPersistenceProvider(String path, IBindingManager bm) {
return new FilePersistenceProvider(new File(path), bm);
}
}, new int[] { 0 }, persistenceIterator).withSourceEntity(entity), contentIterator));
}
use of org.whole.lang.codebase.FilePersistenceProvider in project whole by wholeplatform.
the class ResourceArtifactsGeneratorVisitor method visit.
public void visit(FileArtifact entity) {
env().wEnterScope();
entity.getName().accept(this);
if (!env().wIsSet("name"))
throw new VisitException("No File name");
String fileNameWithExtension = env().wStringValue("name");
env().wDefValue("fileNameWithExtension", fileNameWithExtension);
env().wDefValue("fileName", StringUtils.stripFileExtension(fileNameWithExtension));
env().wDefValue("fileExtension", StringUtils.getFileExtension(fileNameWithExtension));
if (fileNameWithExtension.indexOf(File.separatorChar) != -1 || fileNameWithExtension.indexOf('/') != -1)
throw new VisitException("Invalid File name");
entity.getMetadata().accept(this);
File parentFolder = getParentFolder();
File file = new File(parentFolder.getAbsolutePath() + File.separatorChar + fileNameWithExtension);
try {
if (!file.exists())
file.createNewFile();
env().wDefValue("persistenceProvider", new FilePersistenceProvider(file, env()));
IEntity result = InterpreterOperation.interpret(entity.getContent(), env()).getResult();
if (result != null)
writeContents(result);
} catch (IOException e) {
throw new VisitException(e);
}
if (env().wIsSet("derived"))
// not implemented yet
;
if (env().wIsSet("readonly") && file.canWrite())
file.setReadOnly();
env().wExitScope();
}
use of org.whole.lang.codebase.FilePersistenceProvider in project whole by wholeplatform.
the class ModelInputFunction method compute.
@Override
public Object compute(IEclipseContext context) {
final IBindingManager bm = BindingManagerFactory.instance.createBindingManager();
bm.wDefValue("eclipse#eclipseContext", context);
final IEditorPart editorPart = context.get(IEditorPart.class);
final IEditorInput input = context.get(IEditorInput.class);
if (input instanceof IFileEditorInput) {
IFile file = ((IFileEditorInput) input).getFile();
IFilePersistenceProvider pp = new IFilePersistenceProvider(file, bm);
ModelInput modelInput = new ModelInput(context, pp, calculateBasePersistenceKitId(file));
if (editorPart != null) {
String editorId = editorPart.getSite().getId();
String overridePersistenceKitId = ReflectionFactory.getPersistenceKitFromEditorId(editorId).getId();
modelInput.setOverridePersistenceKitId(overridePersistenceKitId);
}
return modelInput;
} else if (input instanceof IURIEditorInput) {
File file = new File(((IURIEditorInput) input).getURI());
FilePersistenceProvider pp = new FilePersistenceProvider(file, bm);
ModelInput modelInput = new ModelInput(context, pp, ReflectionFactory.getDefaultPersistenceKit().getId());
if (editorPart != null) {
String editorId = editorPart.getSite().getId();
String overridePersistenceKitId = ReflectionFactory.getPersistenceKitFromEditorId(editorId).getId();
modelInput.setOverridePersistenceKitId(overridePersistenceKitId);
}
return modelInput;
} else
return null;
}
use of org.whole.lang.codebase.FilePersistenceProvider in project whole by wholeplatform.
the class WorkflowsInterpreterVisitorTest method testInvokeOperation.
@Test
public void testInvokeOperation() throws Exception {
IEntity invokeOperationTest = WorkflowsTestTemplateManager.instance().create("invokeOperationTest");
IBindingManager args = BindingManagerFactory.instance.createArguments();
TestDecorationManager dm = new TestDecorationManager();
args.wDefValue("decorationManager", dm);
StringWriter writer = new StringWriter();
args.wDefValue("printWriter", new PrintWriter(writer));
InterpreterOperation.interpret(invokeOperationTest, args);
Assert.assertTrue(args.wIsSet("model"));
Assert.assertTrue(args.wIsSet("modelCopy"));
// validate assertions
Assert.assertNotNull(dm.messages);
Assert.assertFalse(dm.messages.isEmpty());
Assert.assertEquals(1, dm.messages.size());
Assert.assertTrue(dm.messages.contains("Reference to the undeclared type: IType"));
// normalize assertions
IEntity modelCopy = args.wGet("modelCopy");
Assert.assertFalse(Matcher.match(args.wGet("model"), modelCopy));
Assert.assertTrue(Matcher.match(args.wGet("model"), NormalizerOperation.normalize(EntityUtils.clone(modelCopy))));
// pretty print assertions
String ls = System.getProperty("line.separator");
String TEXT_MODEL = "model SampleM" + ls + ls + ls + "entity Type types IType" + ls + " feature DataStr data" + ls + ls + "entity DataStr" + ls + " value <String>" + ls + ls + "abstract entity IType" + ls;
Assert.assertEquals(TEXT_MODEL, writer.toString());
// pretty print assertions
ILanguageKit languageKit = ReflectionFactory.getLanguageKit("http://lang.whole.org/SampleM");
Assert.assertNotNull(languageKit);
EntityDescriptor<? extends IEntity> ed = languageKit.getEntityDescriptorEnum().valueOf("Type");
Assert.assertNotNull(ed);
Assert.assertEquals(1, ed.featureSize());
// generate assertions
File file = new File("./data/SampleM.xwl");
Assert.assertTrue(file.exists());
IEntity entity = XmlBuilderPersistenceKit.instance().readModel(new FilePersistenceProvider(file));
Assert.assertTrue(Matcher.match(args.wGet("model"), entity));
Assert.assertFalse(args.wIsSet("fileArtifact"));
}
use of org.whole.lang.codebase.FilePersistenceProvider in project whole by wholeplatform.
the class ModelInput method createPersistenceProvider.
public static IPersistenceProvider createPersistenceProvider(IEclipseContext context, String location) {
final IBindingManager bm = BindingManagerFactory.instance.createBindingManager();
bm.wDefValue("eclipse#eclipseContext", context);
try {
File file = new File(new URI(location));
return new FilePersistenceProvider(file, bm);
} catch (Exception e) {
IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(Path.fromPortableString(location));
return new IFilePersistenceProvider(file, bm);
}
}
Aggregations