Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/developer/org.eclipse.papyrus.mwe2.utils/src/org/eclipse')
-rw-r--r--plugins/developer/org.eclipse.papyrus.mwe2.utils/src/org/eclipse/papyrus/mwe2/utils/Activator.java40
-rw-r--r--plugins/developer/org.eclipse.papyrus.mwe2.utils/src/org/eclipse/papyrus/mwe2/utils/components/QvtoTransformationWorkflowComponent.java146
-rw-r--r--plugins/developer/org.eclipse.papyrus.mwe2.utils/src/org/eclipse/papyrus/mwe2/utils/components/RegisterUmlProfileComponent.java73
-rw-r--r--plugins/developer/org.eclipse.papyrus.mwe2.utils/src/org/eclipse/papyrus/mwe2/utils/messages/Messages.java27
-rw-r--r--plugins/developer/org.eclipse.papyrus.mwe2.utils/src/org/eclipse/papyrus/mwe2/utils/messages/messages.properties6
5 files changed, 292 insertions, 0 deletions
diff --git a/plugins/developer/org.eclipse.papyrus.mwe2.utils/src/org/eclipse/papyrus/mwe2/utils/Activator.java b/plugins/developer/org.eclipse.papyrus.mwe2.utils/src/org/eclipse/papyrus/mwe2/utils/Activator.java
new file mode 100644
index 00000000000..e4a37634fd7
--- /dev/null
+++ b/plugins/developer/org.eclipse.papyrus.mwe2.utils/src/org/eclipse/papyrus/mwe2/utils/Activator.java
@@ -0,0 +1,40 @@
+/*******************************************************************************
+ * 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:
+ * Juan Cadavid <juan.cadavid@cea.fr> implementation
+ ******************************************************************************/
+package org.eclipse.papyrus.mwe2.utils;
+
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+
+public class Activator implements BundleActivator {
+
+ private static BundleContext context;
+
+ static BundleContext getContext() {
+ return context;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
+ */
+ public void start(BundleContext bundleContext) throws Exception {
+ Activator.context = bundleContext;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
+ */
+ public void stop(BundleContext bundleContext) throws Exception {
+ Activator.context = null;
+ }
+
+}
diff --git a/plugins/developer/org.eclipse.papyrus.mwe2.utils/src/org/eclipse/papyrus/mwe2/utils/components/QvtoTransformationWorkflowComponent.java b/plugins/developer/org.eclipse.papyrus.mwe2.utils/src/org/eclipse/papyrus/mwe2/utils/components/QvtoTransformationWorkflowComponent.java
new file mode 100644
index 00000000000..a88492f94cc
--- /dev/null
+++ b/plugins/developer/org.eclipse.papyrus.mwe2.utils/src/org/eclipse/papyrus/mwe2/utils/components/QvtoTransformationWorkflowComponent.java
@@ -0,0 +1,146 @@
+/*******************************************************************************
+ * 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:
+ * Juan Cadavid <juan.cadavid@cea.fr> implementation
+ ******************************************************************************/
+package org.eclipse.papyrus.mwe2.utils.components;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.eclipse.emf.common.util.Diagnostic;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.mwe.core.WorkflowContext;
+import org.eclipse.emf.mwe.core.issues.Issues;
+import org.eclipse.emf.mwe.core.lib.AbstractWorkflowComponent;
+import org.eclipse.emf.mwe.core.monitor.ProgressMonitor;
+import org.eclipse.m2m.qvt.oml.BasicModelExtent;
+import org.eclipse.m2m.qvt.oml.ExecutionContextImpl;
+import org.eclipse.m2m.qvt.oml.ExecutionDiagnostic;
+import org.eclipse.m2m.qvt.oml.ModelExtent;
+import org.eclipse.m2m.qvt.oml.TransformationExecutor;
+import org.eclipse.papyrus.mwe2.utils.messages.Messages;
+
+/**
+ * MWE Component to execute QVTO transformations. An example of use is:
+ * <blockquote>
+ * component = org.eclipse.papyrus.mwe.utils.components.QvtoTransformationWorkflowComponent {
+ inputSlots = 'inputGmfgen'
+ inputSlots = 'gmfgenUmlMetamodel'
+ transformationURI = 'platform:/resource/org.eclipse.papyrus.tests.framework/qvto/gmfgen2uml.qvto'
+ outputSlot = 'inputGmfgenUml'
+ }
+ </blockquote>
+ * where the multi-valued input slots are the input parameters for the transformation;
+ * there should be as many as there are declared in the qvto file;
+ * transformationURI is the location of the .qvto file and outputSlot the slot where
+ * the list of resulting eObjects of the transformation will be placed.
+ *
+ */
+public class QvtoTransformationWorkflowComponent extends
+ AbstractWorkflowComponent {
+
+ private String transformationURI;
+ private String outputSlot;
+ private ArrayList<String> inputSlots = new ArrayList<String>();
+ private Log log = LogFactory.getLog(getClass());
+
+ public String getTransformationURI() {
+ return transformationURI;
+ }
+
+ public void setTransformationURI(String transformationURI) {
+ this.transformationURI = transformationURI;
+ }
+
+ public String getOutputSlot() {
+ return outputSlot;
+ }
+
+ public void setOutputSlot(String outputSlot) {
+ this.outputSlot = outputSlot;
+ }
+
+ public boolean addInputSlots(String c) {
+ return inputSlots.add(c);
+ }
+
+ public ExecutionDiagnostic generate(List<? extends EObject> inObjects,
+ URI transformationURI, WorkflowContext ctx, Issues issues)
+ throws IOException {
+ //resolveProxies(inObjects);
+ TransformationExecutor executor = new TransformationExecutor(
+ transformationURI);
+ Diagnostic loadTransformationDiagnostic = executor.loadTransformation();
+ if (!loadTransformationDiagnostic.getMessage().equals("OK")) { //$NON-NLS-1$
+ log.error(Messages.QvtoTransformationWorkflowComponent_1
+ + loadTransformationDiagnostic);
+ return null;
+ }
+ ExecutionContextImpl context = new ExecutionContextImpl();
+ ArrayList<ModelExtent> input = new ArrayList<ModelExtent>();
+ for (EObject eObject : inObjects) {
+ BasicModelExtent basicModelExtent = new BasicModelExtent();
+ basicModelExtent.add(eObject);
+ input.add(basicModelExtent);
+ }
+ issues.addInfo(new File("..").getAbsolutePath()); //$NON-NLS-1$
+ ModelExtent output = new BasicModelExtent();
+ input.add(output);
+ ModelExtent[] modelParameters = input.toArray(new ModelExtent[] {});
+ context = new ExecutionContextImpl();
+ context.setConfigProperty("keepModeling", true); //$NON-NLS-1$
+ ExecutionDiagnostic result = executor.execute(context, modelParameters);
+ if (result.getSeverity() == Diagnostic.OK) {
+ List<EObject> outObjects = output.getContents();
+ ctx.set(getOutputSlot(), outObjects);
+ log.info(Messages.QvtoTransformationWorkflowComponent_4 + getTransformationURI());
+ } else {
+ issues.addError(result.toString());
+ }
+ return result;
+ }
+
+ @Override
+ protected void invokeInternal(WorkflowContext ctx, ProgressMonitor monitor,
+ Issues issues) {
+ List<EObject> inObjects = new ArrayList<EObject>();
+ for (String inputSlot : inputSlots) {
+
+ Object inputObject = ctx.get(inputSlot);
+ if(inputObject instanceof EObject){
+ inObjects.add((EObject) inputObject);
+ }else if(inputObject instanceof List<?>){
+ List<EObject> list = (List<EObject>) inputObject;
+ inObjects.add((EObject) list.get(0));
+ }
+ }
+ try {
+ generate(inObjects, URI.createURI(transformationURI),
+ ctx, issues);
+ } catch (IOException e) {
+ log.error(e.getLocalizedMessage());
+ }
+
+ }
+
+ @Override
+ public void checkConfiguration(Issues issues) {
+ if (inputSlots.isEmpty()) {
+ issues.addError(Messages.QvtoTransformationWorkflowComponent_5);
+ }
+ }
+
+
+
+}
diff --git a/plugins/developer/org.eclipse.papyrus.mwe2.utils/src/org/eclipse/papyrus/mwe2/utils/components/RegisterUmlProfileComponent.java b/plugins/developer/org.eclipse.papyrus.mwe2.utils/src/org/eclipse/papyrus/mwe2/utils/components/RegisterUmlProfileComponent.java
new file mode 100644
index 00000000000..26c2f305ee8
--- /dev/null
+++ b/plugins/developer/org.eclipse.papyrus.mwe2.utils/src/org/eclipse/papyrus/mwe2/utils/components/RegisterUmlProfileComponent.java
@@ -0,0 +1,73 @@
+/*******************************************************************************
+ * 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:
+ * Juan Cadavid <juan.cadavid@cea.fr> implementation
+ ******************************************************************************/
+package org.eclipse.papyrus.mwe2.utils.components;
+
+
+import org.apache.commons.logging.LogFactory;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.emf.mwe.core.WorkflowContext;
+import org.eclipse.emf.mwe.core.issues.Issues;
+import org.eclipse.emf.mwe.core.lib.AbstractWorkflowComponent;
+import org.eclipse.emf.mwe.core.monitor.ProgressMonitor;
+import org.eclipse.papyrus.mwe2.utils.messages.Messages;
+import org.eclipse.uml2.uml.Profile;
+
+/**
+ * This MWE component registers the EPackage definition of a UML profile in the global EPackage registry.
+ * An example of its usage is:
+ * <blockquote>
+ * component = org.eclipse.papyrus.mwe.utils.components.RegisterUmlProfile {
+ profileSlot = 'ecoreprofile'
+ }
+ </blockquote>
+ * where profileSlot is a slot that contains the uml Profile object to register.
+ */
+public class RegisterUmlProfileComponent extends AbstractWorkflowComponent {
+ private org.apache.commons.logging.Log log = LogFactory.getLog(getClass());
+
+
+ private String profileSlot;
+
+ public String getProfileSlot() {
+ return profileSlot;
+ }
+
+ public void setProfileSlot(String profileSlot) {
+ this.profileSlot = profileSlot;
+ }
+
+ public void checkConfiguration(Issues issues) {
+ if(profileSlot == null || profileSlot.equals("")){ //$NON-NLS-1$
+ issues.addError(Messages.RegisterUmlProfile_1);
+ }
+ }
+
+ @Override
+ protected void invokeInternal(WorkflowContext ctx, ProgressMonitor monitor,
+ Issues issues) {
+ EObject eObject = (EObject) ctx.get(profileSlot);
+ if(!(eObject instanceof Profile)){
+ log.error(Messages.RegisterUmlProfile_2);
+ return;
+ }
+ Profile profile = (Profile) eObject;
+ EPackage definition = profile.getDefinition();
+ if(definition == null){
+ log.error(Messages.RegisterUmlProfile_3);
+ return;
+ }
+ EPackage.Registry.INSTANCE.put(definition.getNsURI(), definition);
+ }
+
+
+
+}
diff --git a/plugins/developer/org.eclipse.papyrus.mwe2.utils/src/org/eclipse/papyrus/mwe2/utils/messages/Messages.java b/plugins/developer/org.eclipse.papyrus.mwe2.utils/src/org/eclipse/papyrus/mwe2/utils/messages/Messages.java
new file mode 100644
index 00000000000..99713cd0275
--- /dev/null
+++ b/plugins/developer/org.eclipse.papyrus.mwe2.utils/src/org/eclipse/papyrus/mwe2/utils/messages/Messages.java
@@ -0,0 +1,27 @@
+package org.eclipse.papyrus.mwe2.utils.messages;
+
+import org.eclipse.osgi.util.NLS;
+
+public class Messages extends NLS {
+
+ private static final String BUNDLE_NAME = "org.eclipse.papyrus.mwe.utils.messages.messages"; //$NON-NLS-1$
+
+ public static String QvtoTransformationWorkflowComponent_1;
+
+ public static String QvtoTransformationWorkflowComponent_4;
+
+ public static String QvtoTransformationWorkflowComponent_5;
+
+ public static String RegisterUmlProfile_1;
+
+ public static String RegisterUmlProfile_2;
+
+ public static String RegisterUmlProfile_3;
+ static {
+ // initialize resource bundle
+ NLS.initializeMessages(BUNDLE_NAME, Messages.class);
+ }
+
+ private Messages() {
+ }
+}
diff --git a/plugins/developer/org.eclipse.papyrus.mwe2.utils/src/org/eclipse/papyrus/mwe2/utils/messages/messages.properties b/plugins/developer/org.eclipse.papyrus.mwe2.utils/src/org/eclipse/papyrus/mwe2/utils/messages/messages.properties
new file mode 100644
index 00000000000..4b99391e951
--- /dev/null
+++ b/plugins/developer/org.eclipse.papyrus.mwe2.utils/src/org/eclipse/papyrus/mwe2/utils/messages/messages.properties
@@ -0,0 +1,6 @@
+QvtoTransformationWorkflowComponent_1=Error loading the model transformation:
+QvtoTransformationWorkflowComponent_4=Successful QVTO transformation
+QvtoTransformationWorkflowComponent_5=No input slots given for the QVTO transformation
+RegisterUmlProfile_1=Profile URI not provided
+RegisterUmlProfile_2=The profile URI does not contain a Profile object
+RegisterUmlProfile_3=The profile has not been defined

Back to the top