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;
  }
  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: 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;
 }
 /** @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 "?????";
   }
 }
  /**
   * Checks if is correct graphical view.
   *
   * @param connectorEnd a connector end
   * @param view a view
   * @return <code>true</code> if the view represents the role of the connector AND if the view is
   *     encapsulated as required by the nested path of the connector end
   */
  protected boolean isCorrectGraphicalView(final ConnectorEnd connectorEnd, final View view) {
    final NestedConnectorEnd nestedConnectorEnd =
        org.eclipse.uml2.uml.util.UMLUtil.getStereotypeApplication(
            connectorEnd, NestedConnectorEnd.class);
    final Property partWithPort = connectorEnd.getPartWithPort();
    // final ConnectableElement role = end.getRole();
    // 1. we get the top view of this view with the same semantic element
    View localView = getTopViewWithSameSemanticElement(view);

    // 2. we verify the part with port
    if (partWithPort != null) {
      View parent = getTopViewWithSameSemanticElement(ViewUtil.getViewContainer(localView));
      if (parent.getElement() != partWithPort) {
        return false;
      }
    }

    // 3. we verify the nested path
    if (nestedConnectorEnd != null && nestedConnectorEnd.getPropertyPath().size() > 0) {
      View parent = view;
      final List<Property> paths = nestedConnectorEnd.getPropertyPath();
      for (int i = paths.size() - 1; i >= 0; i--) {
        final Property currentProperty = paths.get(i);
        parent = getTopViewWithSameSemanticElement(ViewUtil.getViewContainer(parent));
        if (parent.getElement() != currentProperty) {
          return false;
        }
      }
    }
    return true;
  }
  /**
   * Get external connectors to a port
   *
   * @param port
   * @return a list of connectors which are connected to the port.
   */
  public static List<org.eclipse.uml2.uml.Connector> getConnectionsFromPort(Port port) {
    LinkedList<org.eclipse.uml2.uml.Connector> connectors =
        new LinkedList<org.eclipse.uml2.uml.Connector>();

    for (ConnectorEnd connEnd : port.getEnds()) {
      Connector conn = (Connector) connEnd.getOwner();

      if (conn.getEnds().size() >= 2
          && conn.getEnds().get(0).getPartWithPort() != null
          && conn.getEnds().get(1).getPartWithPort() != null) {
        connectors.add(conn);
      }
    }

    return connectors;
  }
  /**
   * 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: 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()
       + ")";
 }
 /**
  *
  * <!-- begin-user-doc -->
  * <!-- end-user-doc -->
  *
  * @generated
  */
 public ConnectorEnd getBase_ConnectorEnd() {
   if (base_ConnectorEnd != null && base_ConnectorEnd.eIsProxy()) {
     InternalEObject oldBase_ConnectorEnd = (InternalEObject) base_ConnectorEnd;
     base_ConnectorEnd = (ConnectorEnd) eResolveProxy(oldBase_ConnectorEnd);
     if (base_ConnectorEnd != oldBase_ConnectorEnd) {
       if (eNotificationRequired()) {
         eNotify(
             new ENotificationImpl(
                 this,
                 Notification.RESOLVE,
                 BlocksPackage.NESTED_CONNECTOR_END__BASE_CONNECTOR_END,
                 oldBase_ConnectorEnd,
                 base_ConnectorEnd));
       }
     }
   }
   return base_ConnectorEnd;
 }
Example #10
0
  /**
   *
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * <!-- begin-model-doc -->
   * Derivation for ConnectorEnd::/definingEnd : Property result = (if connector.type = null then
   * null else let index : Integer = connector.end->indexOf(self) in
   * connector.type.memberEnd->at(index) endif)
   *
   * <p>From package UML::StructuredClassifiers.
   *
   * @param connectorEnd The receiving '<em><b>Connector End</b></em>' model object.
   *     <!-- end-model-doc -->
   * @generated NOT
   */
  public static Property getDefiningEnd(ConnectorEnd connectorEnd) {
    Element owner = connectorEnd.getOwner();

    if (owner instanceof Connector) {
      Connector connector = (Connector) owner;
      Association type = connector.getType();

      if (type != null) {
        List<ConnectorEnd> ends = ((InternalEList<ConnectorEnd>) connector.getEnds()).basicList();
        List<Property> memberEnds = ((InternalEList<Property>) type.getMemberEnds()).basicList();

        if (ends.size() == memberEnds.size()) {
          return memberEnds.get(ends.indexOf(connectorEnd));
        }
      }
    }

    return null;
  }
 /**
  * Checks whether or not a port is a "destination port" from the point of view of a given
  * connector. A destination port can be an input port for a connector stepping out of a component
  * or it can be an output port for a connector linking a component model output port to a
  * component output port inside the component model (e.g. from a component inside the model to the
  * model boundaries).
  */
 private static boolean isDestPort(ConnectorEnd end, Port p) {
   return ((isAnOutputPort(p) && end.getPartWithPort() == null)
       || (isAnInputPort(p) && end.getPartWithPort() != null));
 }