Skip to content

Commit

Permalink
Merge pull request #446 from ZeligsoftDev/papyrus_issue445
Browse files Browse the repository at this point in the history
Papyrus Issue #445
  • Loading branch information
eposse authored May 19, 2023
2 parents 00ba364 + a4dcdb3 commit 1aa0483
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 3 deletions.
5 changes: 5 additions & 0 deletions bundles/com.zeligsoft.cx.codegen/src/codegen/debug.ext
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,8 @@ private Void JavaInspect( int condition, Object obj ) :
private Object JavaDebugObj( Object obj, String msg ) :
JAVA com.zeligsoft.cx.codegen.internal.OawDebug.debug( java.lang.Object, java.lang.String )
;

String getNameOrId( Object obj ) :
JAVA com.zeligsoft.cx.codegen.internal.OawDebug.getNameOrId( java.lang.Object )
;

Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,15 @@
package com.zeligsoft.cx.codegen.internal;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.List;

import org.eclipse.emf.ecore.EAttribute;
import org.eclipse.emf.ecore.ENamedElement;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.uml2.uml.NamedElement;

public class OawDebug {

public static boolean isDebugEnabled() {
Expand Down Expand Up @@ -161,4 +167,75 @@ public static Object debugList(Object l) {
}
return l;
}

public static String getNameOrId(Object obj) {
String nameOrId = "_unknown_";
// System.out.println("getNameOrId 1: " + obj.toString());
assert obj != null;
boolean found = false;
if (obj instanceof EObject) {
// System.out.println("getNameOrId 2: " + obj.toString());
EObject eObj = (EObject) obj;
for (EAttribute attribute : eObj.eClass().getEAllAttributes()) {
if ("name".equals(attribute.getName())) {
nameOrId = (String) eObj.eGet(attribute);
found = true;
break;
}
}
if (!found && eObj instanceof NamedElement) {
// System.out.println("getNameOrId 3: " + obj.toString());
NamedElement namedElement = (NamedElement) eObj;
nameOrId = namedElement.getName();
found = true;
}
if (!found && eObj instanceof ENamedElement) {
// System.out.println("getNameOrId 4: " + obj.toString());
ENamedElement eNamedElement = (ENamedElement) eObj;
nameOrId = eNamedElement.getName();
found = true;
}
}
if (!found) {
// System.out.println("getNameOrId 5: " + obj.toString());

for (Class<?> klass = obj.getClass(); !found && klass != null; klass = klass.getSuperclass()) {
// System.out.println("getNameOrId 6: " + klass.getName());
Method methods[] = klass.getDeclaredMethods();
for (Method method : methods) {
// System.out.println("getNameOrId 7: " + method.getName());
if ("getName".equals(method.getName())) {
try {
nameOrId = (String) method.invoke(obj);
found = true;
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
break;
}
}
}
if (!found) {
// System.out.println("getNameOrId 8: " + obj.toString());
Class<?> klass = obj.getClass();
Field fields[] = klass.getFields();
for (Field field : fields) {
// System.out.println("getNameOrId 9: " + field.getName());
if ("name".equals(field.getName())) {
try {
nameOrId = (String) field.get(obj);
found = true;
} catch (IllegalArgumentException | IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
break;
}
}
}
}
// System.out.println("getNameOrId 10: " + nameOrId);
return nameOrId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public boolean select(Viewer viewer, Object parentElement, Object element) {
}

// filter out CX Domain models
if (eObject.eResource() != null && domain.isReadOnly(eObject.eResource()) && ZDLUtil.isZDLConcept(eObject, ZDLNames.DOMAIN_MODEL)) {
if (eObject != null && eObject.eResource() != null && domain != null && domain.isReadOnly(eObject.eResource()) && ZDLUtil.isZDLConcept(eObject, ZDLNames.DOMAIN_MODEL)) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1005,7 +1005,7 @@ public static Property getDataSpaceFromPerPort(Port port, Property deploymentPar
ConnectorEnd otherEnd = IDL3PlusUtil.getOtherEnd(port, ccmPart);
// While the other end is a border port, and not a dataspace, go up until we
// find one
while (otherEnd == null || isBorderPort(otherEnd)) {
while (otherEnd != null && isBorderPort(otherEnd)) {
// Here port is a delegated port
// Get the parent deployment part of the current part
deploymentPart = ZDeploymentUtil.getParentPart(deploymentPart);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ DeploymentPlan mainTransformAxcioma(CCM::CCM_Deployment::DeploymentPlan deployme
let homeInstances = deployment.allocation.deployed.select( e | e.modelElement.metaType.toString() == "CCM::CCM_Implementation::HomeInstance") :
let connectors = deployment.part.modelElement.typeSelect(DataSpace) :
let parts = deployment.part.modelElement.typeSelect(CCMPart):
deployment.Debug("[DEBUG] DeploymentPlan cdp::mainTransformAxcioma(CCM::CCM_Deployment::DeploymentPlan deployment)") ->
deployment.Debug("[DEBUG] DeploymentPlan cdp::mainTransformAxcioma(CCM::CCM_Deployment::DeploymentPlan deployment = " + deployment.name + ")") ->
enableTrace("RegisterNaming") ->
storeGlobalVar("modelType",modelType) ->
plan.createLocalityManagerElements() ->
Expand Down Expand Up @@ -358,17 +358,21 @@ MonolithicImplementation getComponentPartImplementationForHomeInstance(Deploymen
componentPart.getSelectedImplementation();

Void createInstances(DataSpace dataSpace, DeploymentPlan plan, CCM::CCM_Deployment::DeploymentPlan deployment) :
dataSpace.Debug("Void createInstances(DataSpace dataSpace = " + dataSpace.name + ", DeploymentPlan plan = " + getNameOrId(plan) + ", CCM::CCM_Deployment::DeploymentPlan deployment = " + deployment.name + "); ") ->
visit(dataSpace, plan, deployment, dataSpace.zdlAsProperty().eContainer);

Void visit(DataSpace dataSpace, DeploymentPlan plan, CCM::CCM_Deployment::DeploymentPlan deployment, AssemblyImplementation assembly ) :
dataSpace.Debug("Void visit(DataSpace dataSpace = " + dataSpace.name + ", DeploymentPlan plan = " + getNameOrId(plan) + ", CCM::CCM_Deployment::DeploymentPlan deployment = " + deployment.name + ", AssemblyImplementation assembly = " + assembly.name + "); ") ->
assembly.connector.select( c | c.end.zdlAsConnectorEnd().role.contains(dataSpace)).visit(dataSpace, plan, deployment, dataSpace);

Void visit(CCMConnector connector, DataSpace dataSpace, DeploymentPlan plan, CCM::CCM_Deployment::DeploymentPlan deployment, Object expansionObject) :
connector.Debug("Void visit(CCMConnector connector = " + getNameOrId(connector) + ", DataSpace dataSpace = " + dataSpace.name + ", DeploymentPlan plan = " + getNameOrId(plan) + ", CCM::CCM_Deployment::DeploymentPlan deployment" + deployment.name + ", Object expansionObject" + expansionObject.toString() + "); ") ->
visit(connector, dataSpace, plan, deployment, expansionObject, connector);

Void visit(CCMConnector connector, DataSpace dataSpace, DeploymentPlan plan, CCM::CCM_Deployment::DeploymentPlan deployment, Object expansionObject, CCMConnector origConn) :
let compPart = connector.end.reject(e | e.partWithPort == null).partWithPort.first() :
let deploymentTarget = deployment.allocation.select(e | e.deployed.modelElement.contains(compPart)) :
deploymentTarget.Debug("Void visit(CCMConnector connector = " + getNameOrId(connector) + ", DataSpace dataSpace = " + dataSpace.name + ", DeploymentPlan plan = " + getNameOrId(plan) + ", CCM::CCM_Deployment::DeploymentPlan deployment = " + deployment.name + ", Object expansionObject = " + expansionObject.toString() + ", CCMConnector origConn = " + getNameOrId(origConn) + "); ") ->
if( deploymentTarget.size == 0) then {
// Assembly. Iterate into the assembly and generate the instances for every connected leaf component.
let assembly_impl = getAssembly(compPart.definition) :
Expand All @@ -379,6 +383,7 @@ Void visit(CCMConnector connector, DataSpace dataSpace, DeploymentPlan plan, CCM
// Leaf. Generate DDS4CCM fragments for every deployed instance of this part.
let compPort = connector.end.reject(e | e.partWithPort == null).port.first() :
let origConnPart = origConn.end.reject(e | e.partWithPort == null).partWithPort.first() : // original CCMPart in the top-level connection
deploymentTarget.Debug("compPort = " + compPort.name + " origConnPart = " + origConnPart.name) ->
deploymentTarget.select( dt | dt.deployed.select(dep | dep.modelElement == compPart).select( part | part.hasAncestor(origConnPart)).createDDS4CCMConnectorFragmentHelper(dt.deployedOn, plan, deployment, dataSpace, compPort, origConn))
};

Expand All @@ -401,6 +406,8 @@ Void createDDS4CCMConnectorFragmentHelper(DeploymentPart source, DeploymentPart
let fragmentInstance = createDDS4CCMConnectorFragmentHelper(source, target, plan, deployment, dataSpace ) :
let sourceSN = source.getScopedName() :
let compInstance = plan.instance.selectFirst( i | i.name.first().matches(sourceSN)) :

source.Debug("Void createDDS4CCMConnectorFragmentHelper(DeploymentPart source = " + source.name + ", DeploymentPart target = " + target.name + ", DeploymentPlan plan = " + getNameOrId(plan) + ", CCM::CCM_Deployment::DeploymentPlan deployment = " + deployment.name + ", DataSpace dataSpace = " + dataSpace.name + ", InterfacePort sourcePort = " + sourcePort.name + ", CCMConnector origConn = " + getNameOrId(origConn) + " )") ->

// For the DDS Connector that connects them, for each provides and requires, create a connection where one endpoint is
// the facet/recept on the component, and the other is the connector fragment we just created.
Expand All @@ -414,6 +421,7 @@ create InstanceDeploymentDescription createDDS4CCMConnectorFragmentHelper(Deploy
let dataSpaceSN = dataSpace.connectorType.getCorbaScopedName() :
let id = visit(dataSpace.connectorType, plan).id :
let dataSpaceDP = deployment.part.select( part | part.modelElement == dataSpace).selectFirst( part | part.sameLocalAssembly(source)) :
idd.Debug("create InstanceDeploymentDescription createDDS4CCMConnectorFragmentHelper(DeploymentPart source = " + source.name + ", DeploymentPart target = " + target.name + ", DeploymentPlan plan = " + getNameOrId(plan) + ", CCM::CCM_Deployment::DeploymentPlan deployment = " + deployment.name + ", DataSpace dataSpace = " + dataSpace.name + " )") ->
idd.JavaSetAttribute("id", dataSpace.getConnId(source,getPerPortDP(source, dataSpace),target,node)) ->
idd.name.add(dataSpace.getScopedName() + "_to_" + source.name + "@" + node.name + "." + target.name) ->
idd.node.add(node.name) ->
Expand Down

0 comments on commit 1aa0483

Please sign in to comment.