Description
When I obtain an actor from an instance with instance.getActor()
, the .getIncomingPortMap()
and .getOutgoingPortMap()
methods both return empty maps. This is the case even for actors that are connected to predecessor and successor actors with connections, so the returned map container should contain entries.
For example, here is a simple XDF graphiti feature:
public class MyFeature extends AbstractTimeConsumingCustomFeature {
@Override
public void execute(ICustomContext context, IProgressMonitor parentMonitor) {
final Network currentNetwork = (Network)
getBusinessObjectForPictogramElement( getDiagram() );
for (Vertex ver : currentNetwork.getVertices()) {
if (ver instanceof Instance) {
Instance inst = (Instance) ver;
Actor actor = inst.getActor();
System.out.println(actor.getName() + ": " + actor.getIncomingPortMap().size());
}
}
}
}
It prints an empty entry set for actors in my network that have incoming connections.
I've tried to find the root cause of this issue. It may be something to do with EMF resources. Below is the code used to fill the dialog box with instances and networks, to update a refinement for a graphiti container shape (a box).
First, here's the code of interest, modified with a print statement to inspect the incomingPortMap()
for the actor consumed with emfResourceSet.getResource(uri, true);
if (DfPackage.eINSTANCE.getNetwork().equals(classz)
|| DfPackage.eINSTANCE.getActor().equals(classz)) {
if (DfPackage.eINSTANCE.getActor().equals(classz)) {
Actor actor = (Actor) eobject;
System.out.println("Adding: " + actor.getName() + ", " + actor.getIncomingPortMap());
}
objects.add(eobject);
}
This also prints an empty entry set for actors that do have incoming connections. Here's it in full:
public class EntitySelectionDialog extends FilteredItemsSelectionDialog {
/* other methods (omitted) */
private void fillEntitiesList(IFolder folder) throws CoreException {
final IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
URI.createPlatformResourceURI(resource.getFullPath().toString(),
true);
injector.getInstance(IGenerator.class);
for (IResource resource : folder.members()) {
if (resource.getType() == IResource.FOLDER) {
68BD
fillEntitiesList((IFolder) resource);
} else if (resource.getType() == IResource.FILE) {
final String suffix = resource.getFileExtension();
if (!OrccUtil.IR_SUFFIX.equals(suffix)
&& !OrccUtil.NETWORK_SUFFIX.equals(suffix)) {
continue;
}
final URI uri =
URI.createPlatformResourceURI(resource.getFullPath().toString(),
true);
if (!root.exists(resource.getFullPath())) {
continue;
}
EObject eobject = null;
try {
final Resource emfRes = emfResourceSet.getResource(uri, true);
if (emfRes == null || emfRes.getContents().size() == 0) {
continue;
}
eobject = emfRes.getContents().get(0);
if (eobject == null) {
continue;
}
} catch (NullPointerException e) {
continue;
} catch (Exception e) {
continue;
}
final EClass classz = eobject.eClass();
if (classz == null) {
continue;
}
if (DfPackage.eINSTANCE.getNetwork().equals(classz)
|| DfPackage.eINSTANCE.getActor().equals(classz)) {
if (DfPackage.eINSTANCE.getActor().equals(classz)) {
Actor actor = (Actor) eobject;
System.out.println("Adding: " + actor.getName() + ", " + actor.getIncomingPortMap());
}
objects.add(eobject);
}
}
}
}
}
I don't know how this works:
final Resource emfRes = emfResourceSet.getResource(uri, true);
It looks a bit magical to me, given that I'm not familiar with the EMF framework. Even so, it does appear that it doesn't seem to be getting the entire resource correctly, namely for actors it does not be getting information about incoming or outgoing port maps.
What's the resolution? Thanks!