Esempio n. 1
0
  /**
   * Performs contextual operation call on the operation referred by this call object.
   *
   * @param self a <code>non-null</code> context type instance on which the invocation is performed
   * @param arguments actual parameter values passed to the invocation or <code>null</code> in no
   *     parameters are defined
   * @return the value returned by this call invocation
   * @exception IllegalArgumentException if the <code>self</code> does not conform to the operation
   *     context type or the <code>arguments</code> do not conform to corresponding parameter types
   *     or the underlying operation is non-contextual
   * @exception InvocationTargetException if the underling operation throws an exception
   * @see #invoke(Object[])
   */
  private Object doInvoke(Object self, Object[] arguments)
      throws IllegalArgumentException, InvocationTargetException {
    if (self == null) {
      throw new IllegalArgumentException("Null context instance"); // $NON-NLS-1$
    }

    Object[] actualArguments = (arguments == null) ? NO_ARGS : arguments;
    checkArgumentType(self, actualArguments);

    QvtOperationalEvaluationVisitorImpl evaluator = fContext.getEvaluator();
    Object result = null;
    try {
      result = evaluator.executeHelperOperation(fOperation, self, Arrays.asList(actualArguments));
      if (result
          == evaluator
              .getOperationalEvaluationEnv()
              .getAdapter(InternalEvaluationEnv.class)
              .getInvalid()) {
        // OclInvalid is not valid for non-QVT external callers
        result = null;
      }
    } catch (RuntimeException e) {
      throw new InvocationTargetException(e);
    }

    return result;
  }
Esempio n. 2
0
  private void checkArgumentType(Object self, Object[] arguments) {
    if (arguments.length != fArgumentTypes.size()) {
      throw new IllegalArgumentException("Parameter count mismatch"); // $NON-NLS-1$
    }

    EvaluationEnvironment<EClassifier, EOperation, EStructuralFeature, EClass, EObject> evalEnv =
        fContext.getEvaluator().getEvaluationEnvironment();
    if (self != null) {
      EClassifier callContextType = fContextType;
      if (callContextType == null) {
        callContextType = fOwningModule;
      }
      if (!evalEnv.isKindOf(self, callContextType)) {
        throw new IllegalArgumentException("Invalid context instance type"); // $NON-NLS-1$
      }
    }

    int argIndex = 0;
    for (EClassifier nextArgType : fArgumentTypes) {
      Object nextArg = arguments[argIndex++];
      if (nextArg != null) {
        if (!evalEnv.isKindOf(nextArg, nextArgType)) {
          throw new IllegalArgumentException(
              "Invalid type of argument, pos = " + argIndex); // $NON-NLS-1$				
        }
      }
    }
  }
Esempio n. 3
0
  /**
   * Invokes as a library module owned (non-contextual) operation.
   *
   * @param arguments actual parameter values passed to the invocation or <code>null</code> in no
   *     parameters are defined
   * @return the value returned by this call invocation
   * @exception IllegalArgumentException if the <code>arguments</code> do not conform to
   *     corresponding parameter types or the underlying operation is contextual
   * @exception InvocationTargetException if the underling operation throws an exception
   * @see #invoke(Object, Object[])
   */
  public Object invoke(Object[] arguments)
      throws IllegalArgumentException, InvocationTargetException {
    if (isContextual()) {
      throw new IllegalArgumentException("Contextual operation called without self"); // $NON-NLS-1$
    }

    QvtOperationalEvaluationVisitorImpl evaluator = fContext.getEvaluator();
    Object thisObject = evaluator.getOperationalEvaluationEnv().getThisOfType(this.fOwningModule);
    assert thisObject != null;
    return doInvoke(thisObject, arguments);
  }