Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: d16ca2f0a814f0cd62f892a7231cbd7e968222a9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*****************************************************************************
 * Copyright (c) 2005, 2013 IBM Corporation, CEA, and others.
 * All rights reserved.   This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *   IBM - Initial API and implementation
 *   Christian W. Damus (CEA) - Target EObject must be the diagnostic's first data element
 *   Ed Willink, Klaas Gadeyne, A. Radermacher - Bug 408215 
 *
 *****************************************************************************/


package org.eclipse.papyrus.uml.service.validation;

import java.util.Map;

import org.eclipse.emf.common.util.BasicDiagnostic;
import org.eclipse.emf.common.util.Diagnostic;
import org.eclipse.emf.common.util.DiagnosticChain;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EValidator;
import org.eclipse.emf.ecore.plugin.EcorePlugin;
import org.eclipse.emf.ecore.util.EObjectValidator;
import org.eclipse.emf.validation.model.IConstraintStatus;
import org.eclipse.ocl.pivot.internal.delegate.OCLDelegateValidator;
import org.eclipse.ocl.pivot.uml.internal.validation.UMLOCLEValidator;
import org.eclipse.papyrus.infra.services.validation.EValidatorAdapter;
import org.eclipse.uml2.uml.InstanceSpecification;
import org.eclipse.uml2.uml.OpaqueAction;
import org.eclipse.uml2.uml.OpaqueBehavior;
import org.eclipse.uml2.uml.OpaqueExpression;


/**
 * An adapter that plugs the EMF Model Validation Service API into the {@link org.eclipse.emf.ecore.EValidator} API.
 * <p>
 * <strong>NOTE</strong> that this class was copied from the EMF Validation "Validation Adapter" example project as created by the EMF Validation SDK, and modified only to ensure that the {@link Diagnostic} created from an {@link IConstraintStatus} has the
 * original validation target element as the first element of the {@linkplain Diagnostic#getData() data list} because the {@linkplain IConstraintStatus#getResultLocus() result locus} of a constraint status is an unordered set.
 * </p>
 *
 * bug 405160 - avoid "false" errors by using the UMLValidator instead of EObjectValidator as base class
 */
public class OCLEValidatorAdapter
		extends EValidatorAdapter {

	/**
	 * Constructor.
	 *
	 */
	public OCLEValidatorAdapter(EValidator registeredValidator) {
		super(registeredValidator);
	}
	
	// Overridden to invoke OCLDelegateValidator
	@Override
	public boolean validate(EClass eClass, EObject eObject, DiagnosticChain diagnostics, Map<Object, Object> context) {
		if (eObject.eIsProxy()) {
			if (context != null && context.get(EObjectValidator.ROOT_OBJECT) != null) {
				if (diagnostics != null) {
					diagnostics.add(new BasicDiagnostic(Diagnostic.ERROR, EObjectValidator.DIAGNOSTIC_SOURCE,
							EObjectValidator.EOBJECT__EVERY_PROXY_RESOLVES,
							// create message
							EcorePlugin.INSTANCE.getString("_UI_UnresolvedProxy_diagnostic", //$NON-NLS-1$
								new Object[] {
										EObjectValidator.getFeatureLabel(eObject.eContainmentFeature(), context),
										EObjectValidator.getObjectLabel(eObject.eContainer(), context),
										EObjectValidator.getObjectLabel(eObject, context) }
							),
							new Object[] {
									eObject.eContainer(),
									eObject.eContainmentFeature(),
									eObject }
							));
				}
			}
		}
		else if (EValidator.Registry.INSTANCE.get(eClass.eContainer()) == registeredValidator) {
			if (eObject instanceof InstanceSpecification) {
				UMLOCLEValidator.INSTANCE.validateInstanceSpecification((InstanceSpecification) eObject, diagnostics, context);
			}
			else if (eObject instanceof OpaqueAction) {
				UMLOCLEValidator.INSTANCE.validateOpaqueAction((OpaqueAction) eObject, diagnostics, context);
			}
			else if (eObject instanceof OpaqueBehavior) {
				return UMLOCLEValidator.INSTANCE.validateOpaqueBehavior((OpaqueBehavior) eObject, diagnostics, context);
			}
			else if (eObject instanceof OpaqueExpression) {
				return UMLOCLEValidator.INSTANCE.validateOpaqueExpression((OpaqueExpression) eObject, diagnostics, context);
			}
			registeredValidator.validate(eClass, eObject, diagnostics, context);
		}
		else {
			new OCLDelegateValidator(EObjectValidator.INSTANCE) {
				// Ensure that the class loader for this class will be used downstream.
			}.validate(eClass, eObject, diagnostics, context);
		}
		
		return batchValidate(eObject, diagnostics, context);
	}
}

Back to the top