예제 #1
0
  private Type internalNavigateParameterized(
      final String name, final Type[] params, boolean fCheckIsQuery) throws OclTypeException {

    if (classifier == null) {
      throw new OclTypeException("attempting to access features of Void");
    }

    Type type = Basic.navigateAnyParameterized(name, params);
    if (type != null) {
      return type;
    }

    Object foundOp = null; // MOperation
    java.util.Collection operations = Model.getFacade().getOperations(classifier);
    Iterator iter = operations.iterator();
    while (iter.hasNext() && foundOp == null) {
      Object op = iter.next();
      if (operationMatchesCall(op, name, params)) {
        foundOp = op;
      }
    }

    if (foundOp == null) {
      throw new OclTypeException("operation " + name + " not found in classifier " + toString());
    }

    if (fCheckIsQuery) {
      /* Query checking added 05/21/01, sz9 */
      if (!Model.getFacade().isQuery(foundOp)) {
        throw new OclTypeException(
            "Non-query operations cannot " + "be used in OCL expressions. (" + name + ")");
      }
    }

    Collection returnParams = Model.getCoreHelper().getReturnParameters(foundOp);
    Object rp;
    if (returnParams.size() == 0) {
      rp = null;
    } else {
      rp = returnParams.iterator().next();
    }
    if (returnParams.size() > 1) {
      LOG.log(
          Level.WARNING,
          "OCL compiler only handles one return parameter"
              + " - Found "
              + returnParams.size()
              + " for "
              + Model.getFacade().getName(foundOp));
    }

    if (rp == null || Model.getFacade().getType(rp) == null) {
      LOG.log(Level.WARNING, "WARNING: supposing return type void!");
      return new ArgoAny(null);
    }
    Object returnType = Model.getFacade().getType(rp);

    return getOclRepresentation(returnType);
  }
예제 #2
0
  /*
   * @see tudresden.ocl.check.types.Type#navigateQualified(
   *         java.lang.String, tudresden.ocl.check.types.Type[])
   */
  public Type navigateQualified(String name, Type[] qualifiers) throws OclTypeException {

    if (classifier == null) {
      throw new OclTypeException("attempting to access features of Void");
    }

    if (qualifiers != null) {
      throw new OclTypeException("qualified associations " + "not supported yet!");
    }

    Type type = Basic.navigateAnyQualified(name, this, qualifiers);
    if (type != null) {
      return type;
    }

    Object foundAssocType = null, foundAttribType = null; // MClassifiers
    boolean isSet = false, isSequence = false; // cannot be Bag

    // first search for appropriate attributes
    Collection attributes = Model.getCoreHelper().getAttributesInh(classifier);
    Iterator iter = attributes.iterator();
    while (iter.hasNext() && foundAttribType == null) {
      Object attr = iter.next();
      if (Model.getFacade().getName(attr).equals(name)) {
        foundAttribType = Model.getFacade().getType(attr);
      }
    }

    // look for associations
    Collection associationEnds = Model.getCoreHelper().getAssociateEndsInh(classifier);
    Iterator asciter = associationEnds.iterator();
    while (asciter.hasNext() && foundAssocType == null) {
      Object ae = asciter.next(); // MAssociationEnd
      if (Model.getFacade().getName(ae) != null && name.equals(Model.getFacade().getName(ae))) {

        foundAssocType = Model.getFacade().getType(ae);
      } else if (Model.getFacade().getName(ae) == null
          || Model.getFacade().getName(ae).equals("")) {

        String oppositeName = Model.getFacade().getName(Model.getFacade().getType(ae));
        if (oppositeName != null) {

          String lowerOppositeName = oppositeName.substring(0, 1).toLowerCase();
          lowerOppositeName += oppositeName.substring(1);
          if (lowerOppositeName.equals(name)) {
            foundAssocType = Model.getFacade().getType(ae);
          }
        }
      }
      if (foundAssocType != null) {
        Object multiplicity = Model.getFacade().getMultiplicity(ae);
        if (multiplicity != null
            && (Model.getFacade().getUpper(multiplicity) > 1
                || Model.getFacade().getUpper(multiplicity) == -1)) {
          if (Model.getExtensionMechanismsHelper().hasStereotype(ae, "ordered")) {
            isSequence = true;
          } else {
            isSet = true;
          }
        }
      }
    }

    if (foundAssocType != null && foundAttribType != null) {
      throw new OclTypeException(
          "cannot access feature "
              + name
              + " of classifier "
              + toString()
              + " because both an attribute and "
              + "an association end of this name "
              + "where found");
    }

    Object foundType;
    if (foundAssocType == null) {
      foundType = foundAttribType;
    } else {
      foundType = foundAssocType;
    }

    if (foundType == null) {
      throw new OclTypeException("attribute " + name + " not found in classifier " + toString());
    }

    Type result = getOclRepresentation(foundType);

    if (isSet) {
      result =
          new tudresden.ocl.check.types.Collection(
              tudresden.ocl.check.types.Collection.SET, result);
    }
    if (isSequence) {
      result =
          new tudresden.ocl.check.types.Collection(
              tudresden.ocl.check.types.Collection.SEQUENCE, result);
    }

    return result;
  }