/** | |
* Copyright (c)2020 CEA LIST, Committer Name, and others. | |
* | |
* All rights reserved. This program and the accompanying materials | |
* are made available under the terms of the Eclipse Public License 2.0 | |
* which accompanies this distribution, and is available at | |
* https://www.eclipse.org/legal/epl-2.0/ | |
* | |
* SPDX-License-Identifier: EPL-2.0 | |
* | |
* Contributors: | |
* CEA LIST - Initial API and implementation | |
* Gabriel Pedroza (CEA LIST) gabriel.pedroza@cea.fr | |
* | |
*/ | |
package org.eclipse.papyrus.pdp4eng.designer.controller.internal.processcreation; | |
import java.util.HashMap; | |
import java.util.Iterator; | |
import org.eclipse.emf.ecore.EClass; | |
import org.eclipse.papyrus.requirements.sysml14.common.I_SysMLStereotype; | |
import org.eclipse.uml2.uml.Abstraction; | |
import org.eclipse.uml2.uml.Element; | |
import org.eclipse.uml2.uml.NamedElement; | |
import org.eclipse.uml2.uml.Stereotype; | |
import org.eclipse.uml2.uml.UMLFactory; | |
import org.eclipse.uml2.uml.UMLPackage; | |
public class ProcessBuilder implements IProcessCreation { | |
private HashMap<EClass, IProcessCreation> processCreations= new HashMap<EClass, IProcessCreation>(); | |
private static ProcessBuilder builder=null; | |
public static ProcessBuilder getInstance() { | |
if( builder==null) { | |
builder= new ProcessBuilder(); | |
} | |
return builder; | |
} | |
private ProcessBuilder() { | |
processCreations.put(UMLPackage.eINSTANCE.getActivity(), new ActivityProcessCreation()); | |
processCreations.put(UMLPackage.eINSTANCE.getOpaqueAction(), new OpaqueActionProcessCreation()); | |
processCreations.put(UMLPackage.eINSTANCE.getInputPin(), new InputPinProcessCreation()); | |
processCreations.put(UMLPackage.eINSTANCE.getOutputPin(), new OutputPinProcessCreation()); | |
processCreations.put(UMLPackage.eINSTANCE.getDataStoreNode(), new DataStoreProcessCreation()); | |
processCreations.put(UMLPackage.eINSTANCE.getObjectFlow(), new ObjectFlowProcessCreation()); | |
processCreations.put(UMLPackage.eINSTANCE.getClass_(), new DataProcessCreation()); | |
} | |
public HashMap<EClass, IProcessCreation> getProcessTransfo(){ | |
return processCreations; | |
} | |
@Override | |
public Element createElement(Element source, Element owner) { | |
for (Iterator<EClass> keyIterator = processCreations.keySet().iterator(); keyIterator.hasNext();) { | |
EClass currentEclass = (EClass) keyIterator.next(); | |
if (currentEclass.isInstance(source)) { | |
return processCreations.get(currentEclass).createElement(source, owner); | |
} | |
} | |
return null; | |
} | |
public static void createSatisfy(NamedElement source, NamedElement target) { | |
Abstraction theAbstraction = UMLFactory.eINSTANCE.createAbstraction(); | |
source.getNearestPackage().getPackagedElements().add(theAbstraction); | |
theAbstraction.getSuppliers().add(target); | |
theAbstraction.getClients().add(source); | |
theAbstraction.setName("Satisfies_" + target.getName()); | |
Stereotype satisfyStereotype = theAbstraction.getApplicableStereotype(I_SysMLStereotype.SATISFY_STEREOTYPE); | |
if(satisfyStereotype!=null) { | |
theAbstraction.applyStereotype(satisfyStereotype); | |
} | |
} | |
} |