private boolean portIsRelated(EObject toFilter, Port portContext) {

    if (portContext == toFilter) {
      return false;
    }

    if (toFilter instanceof Port) {
      final List<ConnectorEnd> ends = portContext.getEnds();
      for (final ConnectorEnd portEnd : ends) {
        final EObject eContainer = portEnd.eContainer();
        if (eContainer instanceof Connector) {
          final Connector connector = (Connector) eContainer;
          final EList<ConnectorEnd> connectorEnds = connector.getEnds();
          for (final ConnectorEnd connectorEnd : connectorEnds) {
            if (connectorEnd.getRole() != null && connectorEnd.getRole().equals(toFilter)) {
              return true;
            }
          }
        }
      }
    } else if (toFilter instanceof EncapsulatedClassifier) {
      final List<Port> ownedPortsToFilter = ((EncapsulatedClassifier) toFilter).getOwnedPorts();
      for (final Port portToFilter : ownedPortsToFilter) {
        if (portIsRelated(portToFilter, portContext)) {
          return true;
        }
      }
    }

    return false;
  }
 /** @TODO: author to add some doc. Middleware specific? */
 public static String getConnectionOtherSide(Port p1) {
   if (p1.getEnds().size() > 0) {
     Connector conn = (Connector) p1.getEnds().get(0).getOwner();
     ConnectorEnd e1 = conn.getEnds().get(0);
     ConnectorEnd e2 = conn.getEnds().get(1);
     Port p2 = null;
     java.lang.System.out.println("p1=" + p1.getName());
     Property c2 = null;
     if (e1.getRole() == p1) {
       p2 = (Port) e2.getRole();
       c2 = e2.getPartWithPort();
       java.lang.System.out.println("1 - p2=" + p2.getName() + ", c2=" + c2.getName());
     } else if (e2.getRole() == p1) {
       p2 = (Port) e1.getRole();
       c2 = e1.getPartWithPort();
       java.lang.System.out.println("2 - p2=" + p2.getName() + ", c2=" + c2.getName());
     }
     if (c2.getName().equals(((NamedElement) conn.getOwner()).getName())) {
       return "@" + p2.getName();
     } else {
       return "@" + c2.getName() + "." + p2.getName();
     }
   } else {
     return "?????";
   }
 }
  public static Port getConnectedPort(Port port) {
    if (port.getEnds().size() == 0) {
      return null;
    }

    Connector conn = (Connector) port.getEnds().get(0).getOwner();
    ConnectorEnd e1 = conn.getEnds().get(0);
    ConnectorEnd e2 = conn.getEnds().get(1);
    return (e1.getRole() == port) ? (Port) e2.getRole() : (Port) e1.getRole();
  }
 /**
  * @TODO: this seems to be middleware specific. To be moved to corresponding middleware generator
  * project.
  */
 public static String getConnectionDefinition(Connector connector) {
   ConnectorEnd e1 = connector.getEnds().get(0);
   ConnectorEnd e2 = connector.getEnds().get(1);
   return e1.getPartWithPort().getName()
       + "."
       + e1.getRole().getName()
       + ".connectTo("
       + e2.getPartWithPort().getName()
       + "."
       + e2.getRole().getName()
       + ")";
 }
  /**
   * Can be displayed.
   *
   * @param connector a connector
   * @param selectedView a view used as source or target for the connector to display
   * @param domain2NotationMap the map to complete if we found source and target View on the diagram
   *     to diplsay the connector
   * @return <code>true</code> if the view can be used as source/target for the connector according
   *     to the nested path AND if we found a second view for the 2nd connector end according to the
   *     nested path
   */
  protected boolean canBeDisplayed(
      final Connector connector,
      final View selectedView,
      final Domain2Notation domain2NotationMap) {
    // we need to verify the selected view
    final EObject semanticElement = selectedView.getElement();
    ConnectorEnd endForView = null;

    // 1. look for the connector end represented by the selected view
    for (final ConnectorEnd current : connector.getEnds()) {
      if (current.getRole() == semanticElement) {
        endForView = current;
        break;
      }
    }
    Assert.isNotNull(endForView);
    // 2. verify the view of the selected connector end
    if (!isCorrectGraphicalView(endForView, selectedView)) {
      return false;
    }

    // 3. try to find a view for the second connector end
    View secondView = null;
    for (final ConnectorEnd end : connector.getEnds()) {
      final ConnectableElement role = end.getRole();
      if (role == null) {
        return false;
      }
      if (end == endForView) {
        continue;
      }

      final Set<View> views =
          CrossReferencerUtil.getCrossReferencingViewsInDiagram(role, getCurrentDiagram());
      final Iterator<View> iterOnView = views.iterator();
      while (secondView == null && iterOnView.hasNext()) {
        final View currentView = iterOnView.next();
        if (isCorrectGraphicalView(end, currentView)) {
          domain2NotationMap.putView(endForView, selectedView);
          domain2NotationMap.putView(end, currentView);
          secondView = currentView;
        }
      }
    }
    return secondView != null;
  }
 /** @TODO: author to add some doc */
 public static Boolean isConnectionValid(Connector connector) {
   if (connector.getEnds().size() != 2) {
     return false;
   }
   for (ConnectorEnd cend : connector.getEnds()) {
     if ((cend.getRole() == null) || (cend.getPartWithPort() == null)) {
       return false;
     }
   }
   return true;
 }