Search in sources :

Example 1 with StreamPersistenceProvider

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

the class GrammarsUtilsTest method testParseXmlDocument.

@Category(KnownFailingTests.class)
@Test
public void testParseXmlDocument() throws Exception {
    InputStream is = getClass().getResourceAsStream("smallSample.xwl");
    IEntity xmlDocument = XmlSourcePersistenceKit.instance().readModel(new StreamPersistenceProvider(is));
    is.close();
    is = getClass().getResourceAsStream("smallSample.xwl");
    String source = StringUtils.readAsString(is, Charset.defaultCharset().name());
    is.close();
    IEntity xmlDocumentUsingGrammar = GrammarsUtils.parse(source, xmlGrammarURI);
    Assert.assertTrue(Matcher.match(xmlDocument, xmlDocumentUsingGrammar));
}
Also used : IEntity(org.whole.lang.model.IEntity) InputStream(java.io.InputStream) StreamPersistenceProvider(org.whole.lang.codebase.StreamPersistenceProvider) Category(org.junit.experimental.categories.Category) Test(org.junit.Test)

Example 2 with StreamPersistenceProvider

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

the class ModelMergeViewer method readSideModel.

protected void readSideModel(MergeSide side, Object input, String label) {
    IEntity sideModel = null;
    if (input != null)
        try {
            IStreamContentAccessor accessor = (IStreamContentAccessor) input;
            // TODO
            IPersistenceKit persistenceKit = ReflectionFactory.getDefaultPersistenceKit();
            sideModel = persistenceKit.readModel(new StreamPersistenceProvider(accessor.getContents()));
        } catch (Exception e) {
            E4Utils.reportError(getContext(), "Model Merge Viewer", "Unable to read the model", e);
        // TODO ? sideModel = Status model instance with failure info
        }
    setSideModel(side, sideModel != null ? sideModel : CommonsEntityFactory.instance.createResolver(), label);
}
Also used : IEntity(org.whole.lang.model.IEntity) IStreamContentAccessor(org.eclipse.compare.IStreamContentAccessor) StreamPersistenceProvider(org.whole.lang.codebase.StreamPersistenceProvider) IPersistenceKit(org.whole.lang.codebase.IPersistenceKit)

Example 3 with StreamPersistenceProvider

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

the class ModelMergeViewer method getSideModelBytes.

protected byte[] getSideModelBytes(MergeSide side) {
    try {
        // TODO
        IPersistenceKit persistenceKit = ReflectionFactory.getDefaultPersistenceKit();
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        persistenceKit.writeModel(getSideModel(side), new StreamPersistenceProvider(baos));
        return baos.toByteArray();
    } catch (Exception e) {
        throw new IllegalStateException("cannot gather contents of " + side.name().toLowerCase() + " pane", e);
    }
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) StreamPersistenceProvider(org.whole.lang.codebase.StreamPersistenceProvider) IPersistenceKit(org.whole.lang.codebase.IPersistenceKit)

Example 4 with StreamPersistenceProvider

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

the class LoadContentsVisitor method visit.

@Override
public void visit(FileArtifact file) {
    env().wEnterScope();
    file.getName().accept(this);
    file.getMetadata().accept(this);
    String fileName = env().wStringValue("name");
    IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
    IPath filePath = ArtifactsWorkspaceUtils.getParentPath(bindings).append(fileName);
    InputStream in;
    try {
        in = workspaceRoot.getFile(filePath).getContents(true);
    } catch (CoreException e) {
        throw new OperationCanceledException(e);
    }
    env().wDefValue("className", StringUtils.stripFileExtension(fileName));
    // TODO use IFile
    env().wDefValue("persistenceProvider", new StreamPersistenceProvider(in, null, env()));
    file.setContent(CommonsEntityAdapterFactory.createStageUpFragment(ArtifactsEntityDescriptorEnum.Content, readContents()));
    env().wExitScope();
}
Also used : IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) IPath(org.eclipse.core.runtime.IPath) CoreException(org.eclipse.core.runtime.CoreException) InputStream(java.io.InputStream) OperationCanceledException(org.whole.lang.operations.OperationCanceledException) StreamPersistenceProvider(org.whole.lang.codebase.StreamPersistenceProvider)

Example 5 with StreamPersistenceProvider

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

the class JSONPersistencesTest method setUp.

@Before
public void setUp() throws Exception {
    IEntity sampleText = TextSourcePersistenceKit.instance().readModel(new StreamPersistenceProvider(getClass().getResourceAsStream("sample.json")));
    sampleString = PrettyPrinterOperation.toPrettyPrintString(sampleText);
}
Also used : IEntity(org.whole.lang.model.IEntity) StreamPersistenceProvider(org.whole.lang.codebase.StreamPersistenceProvider) Before(org.junit.Before)

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