@Override public Parameter getParameterNamedWithParent(String name, String parent) { if (this.getName().equals(parent)) { for (Parameter p : parameters) { if (p.getName().equals(name)) { return p; } } } for (AbstractActor aa : vertices) { if (aa instanceof Actor && aa.getName().equals(parent)) { Refinement refinement = ((Actor) aa).getRefinement(); if (refinement != null) { AbstractActor subGraph = refinement.getAbstractActor(); if (subGraph != null && subGraph instanceof PiGraph) { Parameter p = ((PiGraph) subGraph).getParameterNamedWithParent(name, parent); if (p != null) return p; } } } else if (aa instanceof PiGraph) { Parameter p = ((PiGraph) aa).getParameterNamedWithParent(name, parent); if (p != null) return p; } } return null; }
@Override public Set<String> getVerticesNames() { Set<String> names = new HashSet<String>(getVertices().size()); for (AbstractActor vertex : this.getVertices()) { names.add(vertex.getName()); } return names; }
/** Returns an Actor indicated through a path where separators are "/" */ @Override public AbstractActor getHierarchicalActorFromPath(String path) { String[] splitPath = path.split("/"); int index = 0; // Get the first segment of the path, this is the name of the first // actor we will look for String currentName = splitPath[index]; index++; String currentPath = ""; // Handle the case where the first segment of path == name if (this.getName().equals(currentName)) { // If the first segment is the only one, then we are looking for // this if (splitPath.length == 1) return this; currentName = splitPath[index]; index++; } // Compute the path for the next search (path minus currentName) for (int i = index; i < splitPath.length; i++) { if (i > index) { currentPath += "/"; } currentPath += splitPath[i]; } // Look for an actor named currentName for (AbstractActor a : this.getVertices()) { if (a.getName().equals(currentName)) { // If currentPath is empty, then we are at the last hierarchy // level if (currentPath.equals("")) { // We found the actor return a; // Otherwise, we need to go deeper in the hierarchy, either // through a PiGraph object directly or through a Refinement } else if (a instanceof PiGraph) { return ((PiGraph) a).getHierarchicalActorFromPath(currentPath); } else if (a instanceof Actor) { Refinement refinement = ((Actor) a).getRefinement(); if (refinement != null) { AbstractActor subGraph = refinement.getAbstractActor(); if (subGraph != null && subGraph instanceof PiGraph) { return ((PiGraph) subGraph).getHierarchicalActorFromPath(currentPath); } } } } } // If we reach this point, no actor was found, return null return null; }
/** * Retrieve the {@link PictogramElement} of the {@link Diagram} corresponding to the given {@link * AbstractActor}. * * @param diagram the {@link Diagram} containing the {@link PictogramElement} * @param actor the {@link AbstractActor} whose {@link PictogramElement} is searched. * @return the {@link PictogramElement} of the {@link AbstractActor}. * @throws RuntimeException if no {@link PictogramElement} could be found in this {@link Diagram} * for this {@link AbstractActor}. */ public static PictogramElement getActorPE(Diagram diagram, AbstractActor actor) throws RuntimeException { // Get the PE List<PictogramElement> pes = Graphiti.getLinkService().getPictogramElements(diagram, actor); PictogramElement actorPE = null; for (PictogramElement pe : pes) { if (pe instanceof ContainerShape) { actorPE = pe; break; } } if (actorPE == null) { throw new RuntimeException("No PE was found for actor :" + actor.getName()); } return actorPE; }