Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcletavernie2011-12-21 15:16:54 +0000
committercletavernie2011-12-21 15:16:54 +0000
commitd4cb3602d7e3ce74262f86d596503e3a8a568f50 (patch)
treee242d0fdf2a7f81be6f38d886aa4ef1c415e64dd /sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/infra/emf/newchild/policies/PolicyMatcher.java
parent220236e6675aa7a729026b39b7853dd2cea9241c (diff)
downloadorg.eclipse.papyrus-d4cb3602d7e3ce74262f86d596503e3a8a568f50.tar.gz
org.eclipse.papyrus-d4cb3602d7e3ce74262f86d596503e3a8a568f50.tar.xz
org.eclipse.papyrus-d4cb3602d7e3ce74262f86d596503e3a8a568f50.zip
Sandbox commit
Diffstat (limited to 'sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/infra/emf/newchild/policies/PolicyMatcher.java')
-rw-r--r--sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/infra/emf/newchild/policies/PolicyMatcher.java78
1 files changed, 78 insertions, 0 deletions
diff --git a/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/infra/emf/newchild/policies/PolicyMatcher.java b/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/infra/emf/newchild/policies/PolicyMatcher.java
new file mode 100644
index 00000000000..4e3c9d20116
--- /dev/null
+++ b/sandbox/org.eclipse.papyrus.newchild/src/org/eclipse/papyrus/infra/emf/newchild/policies/PolicyMatcher.java
@@ -0,0 +1,78 @@
+/*****************************************************************************
+ * Copyright (c) 2011 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:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.emf.newchild.policies;
+
+import java.util.Collection;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.papyrus.infra.emf.newchild.ncpolicy.NewChildPolicy;
+import org.eclipse.papyrus.infra.emf.newchild.ncpolicy.NewChildPolicySet;
+import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
+
+
+public class PolicyMatcher {
+
+ private List<NewChildFillPolicy> fillPolicies;
+
+ public void setPolicies(Collection<NewChildPolicySet> policySets) {
+ this.fillPolicies = new LinkedList<NewChildFillPolicy>();
+ for(NewChildPolicySet policySet : policySets) {
+ for(NewChildPolicy policy : policySet.getPolicies()) {
+ NewChildFillPolicy fillPolicy = NewChildFillPolicy.Factory.instance.getPolicy(policy);
+ fillPolicies.add(fillPolicy);
+ }
+ }
+ }
+
+ public List<NewChildFillPolicy> getMatchingPolicies(EClass eClass, EStructuralFeature role){
+ List<NewChildFillPolicy> matchedPolicies = new LinkedList<NewChildFillPolicy>();
+
+ for (NewChildFillPolicy policy : fillPolicies){
+ if(matches(policy, eClass, role)) {
+ matchedPolicies.add(policy);
+ }
+ }
+
+ return matchedPolicies;
+ }
+
+ private boolean matches(NewChildFillPolicy policy, EClass eClass, EStructuralFeature role) {
+ Collection<EClass> eClasses = policy.getEClasses();
+ Collection<String> roles = policy.getRoles();
+
+ if(eClasses.isEmpty() && roles.isEmpty()) {
+ return true;
+ }
+
+ if(roles.contains(role.getName()) && (eClasses.isEmpty() || isContained(eClass, eClasses))) {
+ return true;
+ }
+
+ if((roles.isEmpty() || roles.contains(role)) && isContained(eClass, eClasses)) {
+ return true;
+ }
+
+ return false;
+ }
+
+ private boolean isContained(EClass eClass, Collection<EClass> eClasses) {
+ for(EClass classToCheck : eClasses) {
+ if(EMFHelper.isSubclass(eClass, classToCheck)) {
+ return true;
+ }
+ }
+ return false;
+ }
+}

Back to the top