diff --git a/org.fortiss.tooling.kernel/src/org/fortiss/tooling/kernel/utils/.ratings b/org.fortiss.tooling.kernel/src/org/fortiss/tooling/kernel/utils/.ratings index db56108a5c5c5a052c804c19f3214e0ba9ed265f..1f61338d2b7255ed6e8f347bdba5c3a3910c70b0 100644 --- a/org.fortiss.tooling.kernel/src/org/fortiss/tooling/kernel/utils/.ratings +++ b/org.fortiss.tooling.kernel/src/org/fortiss/tooling/kernel/utils/.ratings @@ -1,6 +1,6 @@ CompositionUtils.java 34c0a191bd0fb4176c94b4d61abb5c88a679d5e8 GREEN EMFResourceUtils.java 68e6712a52349548bf85346900b17aa65b5f0ea9 GREEN -EcoreSerializerBase.java 0a0c2969d793d2e68094c55c8f7b0a662ef6e5d5 GREEN +EcoreSerializerBase.java f906e6578ca512e0c83a822ebf6ad17ca5bd3b76 YELLOW EcoreUtils.java a62460d445203b69ec6029479929da77e887866a GREEN ExtensionPointUtils.java 7ce63242b49eb9a7cd4eaadd223f5ebce1dfd75b GREEN HierarchicalNameComparator.java 6face1b673126701a0721af48ead2f9766c17d46 GREEN diff --git a/org.fortiss.tooling.kernel/src/org/fortiss/tooling/kernel/utils/EcoreSerializerBase.java b/org.fortiss.tooling.kernel/src/org/fortiss/tooling/kernel/utils/EcoreSerializerBase.java index 0a0c2969d793d2e68094c55c8f7b0a662ef6e5d5..f906e6578ca512e0c83a822ebf6ad17ca5bd3b76 100644 --- a/org.fortiss.tooling.kernel/src/org/fortiss/tooling/kernel/utils/EcoreSerializerBase.java +++ b/org.fortiss.tooling.kernel/src/org/fortiss/tooling/kernel/utils/EcoreSerializerBase.java @@ -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);