public MultiplicityFacade createMultiplicityFacade(EObject multiplicityElement) {
   // To be overriden
   if (multiplicityElement instanceof MultiplicityElement) {
     MultiplicityElement m = (MultiplicityElement) multiplicityElement;
     return createMultiplicityFacade(m.getLower(), m.getUpper(), m.isUnique(), m.isOrdered());
   } else if (multiplicityElement instanceof LocalNameDeclarationStatement) {
     LocalNameDeclarationStatement statement = (LocalNameDeclarationStatement) multiplicityElement;
     int lower = statement.isMultiplicityIndicator() ? 0 : 1;
     int upper = statement.isMultiplicityIndicator() ? -1 : 1;
     boolean isUnique = statement.isMultiplicityIndicator() ? false : true;
     boolean isOrdered = statement.isMultiplicityIndicator() ? true : false;
     return createMultiplicityFacade(lower, upper, isUnique, isOrdered);
   } else if (multiplicityElement instanceof LoopVariableDefinition) {
     // Correctly handled by the following return statement
   }
   return createMultiplicityFacade();
 }
예제 #2
0
  private Property buildAssociationEnd(
      final Object assoc,
      final String name,
      final Object type,
      final Object multi,
      final Object stereo,
      final Boolean navigable,
      final Object order,
      final Object aggregation,
      final Object scope,
      final Object changeable,
      final Object visibility) {
    // The attribute 'targetScope' of an AssociationEnd in UML1.x is no
    // longer supported in UML2.x
    if (!(assoc instanceof Association)) {
      throw new IllegalArgumentException(
          "The assoc must be instance of Association."); //$NON-NLS-1$
    }
    if (!(type instanceof Type)) {
      throw new IllegalArgumentException(
          "The type of the property "
              + //$NON-NLS-1$
              "must be instance of Type."); //$NON-NLS-1$
    }
    if (aggregation != null && !(aggregation instanceof AggregationKind)) {
      throw new IllegalArgumentException(
          "The aggregation of the property "
              + //$NON-NLS-1$
              "must be instance of AggregationKind."); //$NON-NLS-1$
    }
    if (visibility != null && !(visibility instanceof VisibilityKind)) {
      throw new IllegalArgumentException(
          "The visibility of the property must"
              + //$NON-NLS-1$
              " be instance of VisibilityKind."); //$NON-NLS-1$
    }
    if (multi != null && !(multi instanceof MultiplicityElement)) {
      throw new IllegalArgumentException(
          "The multilicity of the property must"
              + //$NON-NLS-1$
              " be instance of MultiplicityElement."); //$NON-NLS-1$
    }
    MultiplicityElement m = (MultiplicityElement) multi;
    final int lower = m.getLower();
    final int upper = m.getUpper();
    if ((order != null && !(order instanceof Boolean))
        || (changeable != null && !(changeable instanceof Boolean))) {
      throw new IllegalArgumentException(
          "The isOrdered, isReadOnly attributes of "
              + //$NON-NLS-1$
              "the property must be instances of Boolean."); //$NON-NLS-1$
    }
    if (stereo != null && !(stereo instanceof Stereotype)) {
      throw new IllegalArgumentException("stereo must be instance of Stereotype."); // $NON-NLS-1$
    }
    RunnableClass run =
        new RunnableClass() {
          public void run() {
            Property property =
                buildAssociationEndInternal(
                    (Association) assoc,
                    name,
                    (Type) type,
                    new Integer[] {lower, upper},
                    (Stereotype) stereo,
                    navigable,
                    (Boolean) order,
                    (AggregationKind) aggregation,
                    (Boolean) scope,
                    (Boolean) changeable,
                    (VisibilityKind) visibility);
            getParams().add(property);
          }
        };
    modelImpl.getModelEventPump().getRootContainer().setHoldEvents(true);
    ChangeCommand cmd =
        new ChangeCommand(modelImpl, run, "Create the association end # of the association #");
    editingDomain.getCommandStack().execute(cmd);
    if (run.getParams().isEmpty()) {
      editingDomain.getCommandStack().undo();
      editingDomain.getCommandStack().flush();
      modelImpl.getModelEventPump().getRootContainer().clearHeldEvents();
      modelImpl.getModelEventPump().getRootContainer().setHoldEvents(false);
      throw new UnsupportedOperationException(
          "This stereotype cannot be applied "
              + //$NON-NLS-1$
              "to the association end."); //$NON-NLS-1$
    }
    cmd.setObjects(run.getParams().get(0), assoc);
    modelImpl.getModelEventPump().getRootContainer().setHoldEvents(false);

    return (Property) run.getParams().get(0);
  }