コード例 #1
0
 @Override
 public Boolean isLiteralType() {
   Boolean isLiteralValue = null;
   for (IfcValue value : values) {
     Boolean b = value.isLiteralType();
     if (b != isLiteralValue && b != null) {
       assert isLiteralValue == null
           : "Mixed literal and link type: "
               + StringUtils.collectionToString(values, null, null, null, ",");
       isLiteralValue = b;
     }
   }
   return isLiteralValue;
 }
コード例 #2
0
  /**
   * Set entity attribute values
   *
   * @param entity
   * @param attributeInfos
   * @param attributeValues
   * @throws IfcParserException
   */
  private void setEntityAttributeValues(
      IfcEntity entity, List<IfcAttributeInfo> attributeInfos, List<IfcValue> attributeValues)
      throws IfcParserException {
    try {

      if (attributeValues.size() == attributeInfos.size()) {
        boolean isLiteralValueContainer = true;
        for (int attributeIndex = 0; attributeIndex < attributeValues.size(); ++attributeIndex) {

          IfcAttributeInfo attributeInfo = attributeInfos.get(attributeIndex);
          IfcValue attributeValue = attributeValues.get(attributeIndex);

          Boolean isLiteralValue = attributeValue.isLiteralType();

          if (isLiteralValue != null) {
            isLiteralValueContainer = isLiteralValueContainer && isLiteralValue == Boolean.TRUE;
            if (isLiteralValue) {

              if (attributeValue instanceof IfcTemporaryCollectionValueWrapper) {

                if (attributeInfo.isCollection()) {

                  IfcLiteralValueCollection values = new IfcLiteralValueCollection();
                  for (IfcValue value :
                      ((IfcTemporaryCollectionValueWrapper) attributeValue).getValues()) {
                    values.add((IfcLiteralValue) value);
                  }

                  entity.addLiteralAttribute(
                      new IfcLiteralAttribute(attributeInfo, attributeIndex, values));

                } else {

                  for (IfcValue value :
                      ((IfcTemporaryCollectionValueWrapper) attributeValue).getValues()) {
                    entity.addLiteralAttribute(
                        new IfcLiteralAttribute(attributeInfo, attributeIndex, value));
                  }
                }

              } else {

                assert (attributeValue instanceof IfcLiteralValue)
                    : String.format(
                        "Object is not a literal value, line number: %d, attributeInfo: %s, attribute value: %s, value type: %s",
                        entity.getLineNumber(),
                        attributeInfo.getName(),
                        attributeValue,
                        attributeInfo.getAttributeTypeInfo().getValueTypes());
                entity.addLiteralAttribute(
                    new IfcLiteralAttribute(attributeInfo, attributeIndex, attributeValue));
              }

            } else { // attributeInfo instanceof IfcLinkInfo

              if (attributeValue instanceof IfcTemporaryCollectionValueWrapper) {

                if (attributeInfo.isCollection()) {

                  IfcEntityCollection destinations = new IfcEntityCollection();
                  for (IfcValue destination :
                      ((IfcTemporaryCollectionValueWrapper) attributeValue).getValues()) {
                    destinations.add((IfcEntity) destination);
                  }

                  entity.addOutgoingLink(
                      new IfcLink(
                          (IfcLinkInfo) attributeInfo, attributeIndex, entity, destinations));

                } else {

                  for (IfcValue destination :
                      ((IfcTemporaryCollectionValueWrapper) attributeValue).getValues()) {
                    IfcLink link =
                        new IfcLink(
                            (IfcLinkInfo) attributeInfo,
                            attributeIndex,
                            entity,
                            (IfcEntityBase) destination);
                    entity.addOutgoingLink(link);
                  }
                }

              } else {

                assert (attributeValue instanceof IfcEntityBase)
                    : String.format(
                        "Object is not an entity, line number: %d, attributeInfo: %s, attribute value: %s, value type: %s",
                        entity.getLineNumber(),
                        attributeInfo.getName(),
                        attributeValue,
                        attributeInfo.getAttributeTypeInfo().getValueTypes());
                IfcLink link =
                    new IfcLink(
                        (IfcLinkInfo) attributeInfo,
                        attributeIndex,
                        entity,
                        (IfcEntityBase) attributeValue);
                entity.addOutgoingLink(link);
              }
            }
          }
        }
        entity.setLiteralValueContainer(isLiteralValueContainer);

      } else {
        throw new IfcParserException(
            String.format(
                "Type %s: Expected %d attributes, but %d were found: %s, %s",
                entity.getTypeInfo().getName(),
                attributeInfos.size(),
                attributeValues.size(),
                attributeInfos,
                attributeValues));
      }

    } catch (Exception e) {
      throw new IfcParserException(
          String.format(
              "Error parsing entity %s (line %d): %s",
              entity.toString(), entity.getLineNumber(), e.getMessage()),
          e);
    }
  }