Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: d7af16b11f88cf1125f3133c8cbdf218225c722b (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
/*****************************************************************************
 * Copyright (c) 2014 CEA LIST.
 *
 * 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:
 *  CEA LIST - Initial API and implementation
 *
 *****************************************************************************/
package org.eclipse.papyrus.uml.elementtypesconfigurations.stereotypeapplicationmatcherconfiguration;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.emf.ecore.EObject;
import org.eclipse.gmf.runtime.emf.type.core.IElementMatcher;
import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.Model;
import org.eclipse.uml2.uml.Profile;


/**
 * Matcher for UML elements that should be stereotyped
 */
public class StereotypeApplicationMatcher implements IElementMatcher {

	private List<String> stereotypesQualifiedNames;
	private String profileUri;

	public StereotypeApplicationMatcher(StereotypeApplicationMatcherConfiguration configuration) {
		this.profileUri = configuration.getProfileUri();
		this.stereotypesQualifiedNames = configuration.getStereotypesQualifiedNames();
	}


	public boolean matches(EObject eObject) {
		if (!(eObject instanceof Element)) {
			return false;
		}

		Element element = (Element) eObject;
		if (element.getAppliedStereotypes().isEmpty()) {
			return false;
		}

		for (String stereotypeQualifiedName : stereotypesQualifiedNames) {
			if (element.getAppliedStereotype(stereotypeQualifiedName) == null) {
				return false;
			}
		}
		
		if (profileUri != null){
			Model model = element.getModel();
			if (model == null){
				return false;
			}
			
			List<String> appliedProfileByUri = new ArrayList<String>();			
			for (Profile appliedProfile : model.getAllAppliedProfiles()) {
				appliedProfileByUri.add(appliedProfile.getURI());
			}
			
			if (!appliedProfileByUri.contains(profileUri)){
				return false;
			}
						
		}
		return true;
	}

	public List<String> getStereotypesQualifiedNames() {
		return stereotypesQualifiedNames;
	}


	public void setStereotypesQualifiedNames(List<String> stereotypeQualifiedName) {
		this.stereotypesQualifiedNames = stereotypeQualifiedName;
	}

}

Back to the top