Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
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