Esempio n. 1
0
  /**
   * get a property association from the properties section of the containing classifier if the
   * context. This method has been designed to work with end points of connections, i.e., consisting
   * of a target and a context. The context must be a NamedElement in its containing classifier,
   * i.e., a feature, feature group, subcomponent. The property holder is assumed to be contained in
   * the context object, e.g., a feature in afeature group or a data subcomponent in a port, or
   * feature in a subcomponent. The association must match the property definition. if the context
   * is null then the containing classifier of the target is used and the path must be one or no
   * path. The applies to clause of the property association must be of size 2 if the context is set
   * and point to the context and then the property holder. The property value of the property
   * association is assumed not to be modal.
   *
   * @param context NamedElement whose containing classifier's properties section is searched for
   *     the desired property
   * @param target NamedElement the model element to which the property is applied to via the
   *     applies to clause
   * @param pd Property the property definition
   * @return
   */
  public static PropertyExpression getContainedSimplePropertyValue(
      final NamedElement context, final NamedElement target, final Property pd) {
    if (context == null) return target.getNonModalPropertyValue(pd);
    Classifier cl = AadlUtil.getContainingClassifier(context);
    EList<PropertyAssociation> props = cl.getAllPropertyAssociations();
    for (PropertyAssociation propertyAssociation : props) {
      if (propertyAssociation.getProperty().equals(pd)) {
        // we found a property with the corect type
        // now we need to check whether the applies to points to the holder
        EList<ContainedNamedElement> appliestos = propertyAssociation.getAppliesTos();
        for (ContainedNamedElement containedNamedElement : appliestos) {
          EList<ContainmentPathElement> cpes = containedNamedElement.getContainmentPathElements();
          if (cpes.size() == 2) {
            NamedElement pathcxt = cpes.get(0).getNamedElement();
            NamedElement pathelement = cpes.get(1).getNamedElement();
            if (context.equals(pathcxt) && target.equals(pathelement)) {
              EList<ModalPropertyValue> vallist = propertyAssociation.getOwnedValues();
              if (!vallist.isEmpty()) {
                ModalPropertyValue elem = vallist.get(0);
                PropertyExpression res = elem.getOwnedValue();
                if (res instanceof NamedValue) {
                  AbstractNamedValue nv = ((NamedValue) res).getNamedValue();
                  if (nv instanceof Property) {
                    res = target.getNonModalPropertyValue((Property) nv);
                  } else if (nv instanceof PropertyConstant) {
                    res = ((PropertyConstant) nv).getConstantValue();
                  }
                }

                return res;
              }
            }
          }
        }
      }
    }
    return null;
  }
  public void checkPortConsistency(
      FeatureInstance srcFI, FeatureInstance dstFI, ConnectionInstance conni) {
    double srcDataSize = GetProperties.getSourceDataSizeInBytes(srcFI);
    double dstDataSize = GetProperties.getSourceDataSizeInBytes(dstFI);

    RecordValue srcRate = GetProperties.getOutPutRate(srcFI);
    RecordValue dstRate = GetProperties.getInPutRate(dstFI);
    EnumerationLiteral srcRU = null;
    EnumerationLiteral dstRU = null;
    double srcMaxRateValue = 0;
    double dstMaxRateValue = 0;
    double srcMinRateValue = 0;
    double dstMinRateValue = 0;
    if (srcRate != null && dstRate != null) {
      srcRU = GetProperties.getRateUnit(srcRate);
      dstRU = GetProperties.getRateUnit(dstRate);
      srcMaxRateValue = GetProperties.getMaxDataRate(srcRate);
      dstMaxRateValue = GetProperties.getMaxDataRate(dstRate);
      srcMinRateValue = GetProperties.getMinDataRate(srcRate);
      dstMinRateValue = GetProperties.getMinDataRate(dstRate);
    }
    // now try it as SEI::Data_Rate
    double srcRateValue = GetProperties.getMessageRatePerSecond(srcFI);
    double dstRateValue = GetProperties.getMessageRatePerSecond(dstFI);

    Classifier srcC = GetProperties.getSingleBaseType(srcFI);
    Classifier dstC = GetProperties.getSingleBaseType(dstFI);

    String srcS = GetProperties.getMeasurementUnit(srcFI);
    String dstS = GetProperties.getMeasurementUnit(dstFI);

    // error logging

    if (srcDataSize > 0 && dstDataSize > 0) {
      if (srcDataSize != dstDataSize) {
        error(
            conni,
            "Source data size "
                + srcDataSize
                + " Bytes and destination data size "
                + dstDataSize
                + " Bytes differ");
      }
    } else {
      if (srcDataSize == 0 && dstDataSize > 0) error(conni, "Source data size is missing or zero");
      if (dstDataSize == 0 && srcDataSize > 0)
        error(conni, "Destination data size is missing or zero");
    }

    if (srcRU != null && dstRU != null && srcRU != dstRU) {
      error(
          conni,
          "Source rate unit "
              + srcRU.getName()
              + " and destination rate unit "
              + dstRU.getName()
              + " differ");
    }

    if (srcMaxRateValue > 0 && dstMaxRateValue > 0) {
      if (srcMaxRateValue > dstMaxRateValue) {
        error(
            conni,
            "Maximum source data rate "
                + srcMaxRateValue
                + " is greater than maximum destination data rate "
                + dstMaxRateValue);
      }
      if (srcMinRateValue < dstMinRateValue) {
        error(
            conni,
            "Minimum source data rate "
                + srcMinRateValue
                + " is less than minimum destination data rate "
                + dstMinRateValue);
      }
    } else {
      if (srcRate != null || dstRate != null) {
        error(conni, "Missing input rate or output rate");
      }
    }

    if (srcRateValue > 0 && dstRateValue > 0) {
      if (srcRateValue != dstRateValue) {
        error(
            conni,
            "Source data rate "
                + srcRateValue
                + " and destination data rate "
                + dstRateValue
                + " differ");
      }
    } else {
      if (srcRateValue == 0 && dstRateValue > 0)
        error(conni, "Source data rate is missing or zero");
      if (dstRateValue == 0 && srcRateValue > 0)
        error(conni, "Destination data rate is missing or zero");
    }

    if (srcC != null && dstC != null) {
      if (srcC != dstC) {
        error(
            conni,
            "Source base type "
                + srcC.getName()
                + " and destination base type "
                + dstC.getName()
                + " differ");
      }
    } else {
      if (srcC == null && dstC != null) error(conni, "Source base type is missing");
      if (dstC == null && srcC != null) error(conni, "Destination base type is missing");
    }

    if (srcS.length() > 0 && dstS.length() > 0) {
      if (!srcS.equalsIgnoreCase(dstS)) {
        error(
            conni,
            "Source measurement unit "
                + srcS
                + " and destination measurement unit "
                + dstS
                + " differ");
      }
    } else {
      if (srcS.length() == 0 && dstS.length() > 0)
        error(conni, "Source measurement unit is missing");
      if (dstS.length() == 0 && srcS.length() > 0)
        error(conni, "Destination measurement unit is missing");
    }
  }