1 /*******************************************************************************
2 * Copyright (c) 2012, 2015 Obeo.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
9 * Obeo - initial API and implementation
10 *******************************************************************************/
11 package org
.eclipse
.emf
.compare
.ide
.internal
.utils
;
13 import java
.util
.Iterator
;
16 import org
.eclipse
.emf
.ecore
.resource
.Resource
;
17 import org
.eclipse
.emf
.ecore
.xmi
.UnresolvedReferenceException
;
18 import org
.eclipse
.emf
.ecore
.xmi
.XMLDefaultHandler
;
19 import org
.eclipse
.emf
.ecore
.xmi
.XMLHelper
;
20 import org
.eclipse
.emf
.ecore
.xmi
.XMLLoad
;
21 import org
.eclipse
.emf
.ecore
.xmi
.XMLResource
;
22 import org
.eclipse
.emf
.ecore
.xmi
.impl
.XMLHandler
;
25 * This implementation of an {@link org.eclipse.emf.ecore.xmi.XMLParserPool} aims at disabling all
26 * notifications when the {@link XMLResource#OPTION_DISABLE_NOTIFY option} is set, including the notifications
27 * at the very end of parsing.
29 * This is one of the steps that allows EMF Compare to bypass UML's CacheAdapter when loading UML models from
33 * @author <a href="mailto:laurent.goubet@obeo.fr">Laurent Goubet</a>
35 public class NoNotificationParserPool
extends NotifyingParserPool
{
37 * Default constructor.
39 * @param containmentOnly
40 * only set containment reference values. The model will be mostly empty except for its
43 public NoNotificationParserPool(boolean containmentOnly
) {
44 super(containmentOnly
);
48 protected XMLDefaultHandler
createDefaultHandler(XMLResource resource
, XMLLoad xmlLoad
, XMLHelper helper
,
50 final XMLDefaultHandler handler
= super.createDefaultHandler(resource
, xmlLoad
, helper
, options
);
51 if (handler
instanceof XMLHandler
) {
52 return new NoNotificationXMLHandler((XMLHandler
)handler
, resource
, helper
, options
);
58 * The only purpose of this xml handler is to disable the notifications that are sent from the default
59 * implementation of {@link #endDocument()} .
61 * @author <a href="mailto:laurent.goubet@obeo.fr">Laurent Goubet</a>
63 private class NoNotificationXMLHandler
extends ForwardingXMLHandler
{
65 * Creates this forwarding handler given its delegate. All other parameters are only used to call the
66 * mandatory super-constructor... but none should be of any use here.
69 * Our delegate XMLHandler.
71 * The resource we'll be loading. Mandatory for the super-constructor, but we'll forward
72 * all calls to {@code delegate} anyway.
74 * The xml helper to use. Mandatory for the super-constructor, but we'll forward all calls
75 * to {@code delegate} anyway.
77 * The load options that were specified. Mandatory for the super-constructor, but we'll
78 * forward all calls to {@code delegate} anyway.
80 public NoNotificationXMLHandler(XMLHandler delegate
, XMLResource xmlResource
, XMLHelper helper
,
82 super(delegate
, xmlResource
, helper
, options
);
88 * @see org.eclipse.emf.ecore.xmi.impl.XMLHandler#endDocument()
91 public void endDocument() {
92 // prevent the sending of notifications at the end of loading
93 // "disableNotify" at true would still send some from here
94 setField("disableNotify", delegate(), Boolean
.FALSE
); //$NON-NLS-1$
96 setField("disableNotify", delegate(), Boolean
.TRUE
); //$NON-NLS-1$
98 if (containmentOnly
) {
99 // Same document references are all left as proxies since we haven't set them.
100 // The xml handler would diagnose that has an error.
101 final Iterator
<Resource
.Diagnostic
> errors
= xmlResource
.getErrors().iterator();
102 while (errors
.hasNext()) {
103 final Resource
.Diagnostic diagnostic
= errors
.next();
104 if (diagnostic
instanceof UnresolvedReferenceException
) {