Skip to content
Snippets Groups Projects
Commit db20038c authored by Simon Barner's avatar Simon Barner
Browse files

Merge branch '4223' into 'master'

4223: Expose createResource(), add saveResource()

See merge request !184
parents 8fec72e0 30fa464d
No related branches found
No related tags found
1 merge request!1844223: Expose createResource(), add saveResource()
CompositionUtils.java 34c0a191bd0fb4176c94b4d61abb5c88a679d5e8 GREEN
EMFResourceUtils.java 68e6712a52349548bf85346900b17aa65b5f0ea9 GREEN
EcoreSerializerBase.java 0a0c2969d793d2e68094c55c8f7b0a662ef6e5d5 GREEN
EcoreSerializerBase.java f906e6578ca512e0c83a822ebf6ad17ca5bd3b76 GREEN
EcoreUtils.java a62460d445203b69ec6029479929da77e887866a GREEN
ExtensionPointUtils.java 7ce63242b49eb9a7cd4eaadd223f5ebce1dfd75b GREEN
HierarchicalNameComparator.java 6face1b673126701a0721af48ead2f9766c17d46 GREEN
......
......@@ -19,6 +19,7 @@ import static org.eclipse.emf.ecore.util.EcoreUtil.getIdentification;
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.charset.Charset;
import java.util.HashMap;
import java.util.Map;
......@@ -288,10 +289,23 @@ public abstract class EcoreSerializerBase<R extends EObject> {
validate(rootElement);
saveResource(resource, null);
}
/**
* Saves the given {@link Resource} with the options provided by {@link #getOptions()}. In case
* the provided {@link OutputStream} is not {@code null}, the resource is saved to it.
* Otherwise, it is saved to the URI as configured during the creation of the {@link Resource}.
*/
protected void saveResource(Resource resource, OutputStream ostream) throws IOException {
if(resource instanceof XMLResource) {
((XMLResource)resource).setEncoding(charset.name());
}
resource.save(getOptions());
if(ostream == null) {
resource.save(getOptions());
} else {
resource.save(ostream, getOptions());
}
}
/**
......@@ -424,7 +438,7 @@ public abstract class EcoreSerializerBase<R extends EObject> {
*
* @throws IOException
*/
private final ResourceSet createResourceSet() throws IOException {
protected final ResourceSet createResourceSet() throws IOException {
ResourceSet resourceSet = new ResourceSetImpl();
resourceSet.getPackageRegistry().put(eNsURI, ePackage);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment