Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Noyrit2013-07-16 15:50:45 +0000
committerFlorian Noyrit2013-07-16 15:50:45 +0000
commit69f6175633a55f6737e8e5734ec060d84726fafb (patch)
treee63de510c90e95ab89e1fbcd743ff723e77639b8 /plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/validator/ParticipantValidator.java
parent75b5410d69a1df0e8e16a5aeacfea3cd5c1afdb2 (diff)
downloadorg.eclipse.papyrus-69f6175633a55f6737e8e5734ec060d84726fafb.tar.gz
org.eclipse.papyrus-69f6175633a55f6737e8e5734ec060d84726fafb.tar.xz
org.eclipse.papyrus-69f6175633a55f6737e8e5734ec060d84726fafb.zip
OCL-based search and type-based search
Diffstat (limited to 'plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/validator/ParticipantValidator.java')
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/validator/ParticipantValidator.java101
1 files changed, 101 insertions, 0 deletions
diff --git a/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/validator/ParticipantValidator.java b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/validator/ParticipantValidator.java
new file mode 100644
index 00000000000..177ff26c248
--- /dev/null
+++ b/plugins/uml/org.eclipse.papyrus.uml.search.ui/src/org/eclipse/papyrus/uml/search/ui/validator/ParticipantValidator.java
@@ -0,0 +1,101 @@
+/*****************************************************************************
+ * Copyright (c) 2013 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.search.ui.validator;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+
+import org.eclipse.emf.common.util.TreeIterator;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.Stereotype;
+
+/**
+ *
+ * A generic implementation of participant validator that works on EMF basis
+ *
+ */
+public class ParticipantValidator implements IParticipantValidator {
+
+ private static ParticipantValidator instance = null;
+
+ private ParticipantValidator() {
+ super();
+ }
+
+ public final static ParticipantValidator getInstance() {
+
+ if(ParticipantValidator.instance == null) {
+ synchronized(ParticipantValidator.class) {
+ if(ParticipantValidator.instance == null) {
+ ParticipantValidator.instance = new ParticipantValidator();
+ }
+ }
+ }
+ return ParticipantValidator.instance;
+ }
+
+ public Collection<EObject> getParticipants(EObject root, Object[] participantsTypes) {
+
+ List<Object> participantsTypesList = Arrays.asList(participantsTypes);
+ List<EObject> results = new ArrayList<EObject>();
+
+
+
+ // ... and all its content
+ TreeIterator<EObject> it = root.eAllContents();
+ while(it.hasNext()) {
+ EObject modelElement = (EObject)it.next();
+ //Check that metaclass of this element is a supported metaclass
+
+ if(participantsTypesList.contains(modelElement.eClass())) {
+ results.add(modelElement);
+ }
+ }
+
+ return results;
+ }
+
+
+ public Collection<EObject> getParticipantsStereotype(EObject root, Object[] participantsTypes) {
+
+ List<Object> participantsTypesList = Arrays.asList(participantsTypes);
+ List<EObject> results = new ArrayList<EObject>();
+
+ // Evaluate root...
+ if(participantsTypesList.contains(root.eClass())) {
+ results.add(root);
+ }
+
+ // ... and all its content
+ TreeIterator<EObject> it = root.eAllContents();
+ while(it.hasNext()) {
+ EObject modelElement = (EObject)it.next();
+ if(modelElement instanceof Element) {
+ for(Stereotype element : ((Element)modelElement).getAppliedStereotypes()) {
+ //Check that metaclass of this element is a supported metaclass
+ for(Object stereotypeToGet : participantsTypesList) {
+ if(element.getName().equals(((Stereotype)stereotypeToGet).getName())) {
+ results.add(modelElement);
+ }
+ }
+ }
+ }
+ }
+
+ return results;
+ }
+}

Back to the top