Java 类org.eclipse.emf.ecore.xmi.impl.XMLHelperImpl 实例源码

项目:Source    文件:EObjectConnector.java   
/**
 * Updates the given {@link IEObjectContainer} with the given {@link Resource}.
 * 
 * @param container
 *            the {@link ILocationContainer}
 * @param eObjectContainer
 *            the {@link IEObjectContainer}
 * @param newResource
 *            the {@link Resource}
 * @throws Exception
 *             if the XMI serialization failed
 */
public void updateEObjectContainer(ILocationContainer container, IEObjectContainer eObjectContainer,
        Resource newResource) throws Exception {
    if (eObjectContainer.getXMIContent() != null && !eObjectContainer.getXMIContent().isEmpty()) {
        final XMIResourceImpl oldResource = new XMIResourceImpl(URI.createURI(""));
        oldResource.load(new ByteArrayInputStream(eObjectContainer.getXMIContent().getBytes(UTF_8)),
                new HashMap<Object, Object>());
        final IComparisonScope scope = new DefaultComparisonScope(oldResource, newResource, null);
        final Comparison comparison = EMFCompare.builder().build().compare(scope);
        for (ILocation child : new ArrayList<ILocation>(eObjectContainer.getContents())) {
            if (child instanceof IEObjectLocation && !child.isMarkedAsDeleted()) {
                final IEObjectLocation location = (IEObjectLocation)child;
                updateEObjectLocation(oldResource, comparison, location, needSavedURIFragment(
                        newResource));
            }
        }
    }

    eObjectContainer.getSavedURIFragments().clear();
    if (needSavedURIFragment(newResource)) {
        updateSavedURIFragment(container, eObjectContainer, newResource);
    }

    final String newXMIContent = XMLHelperImpl.saveString(new HashMap<Object, Object>(), newResource
            .getContents(), UTF_8, null);
    eObjectContainer.setXMIContent(newXMIContent);
}