示例#1
0
 /**
  * Returns operation modifiers as string, separated with comma.
  *
  * @return a string containing the modifiers
  */
 private static String getModifiersAsString(Operation operation) {
   StringBuffer buffer = new StringBuffer();
   boolean needsComma = false;
   // Return parameter modifiers
   Parameter returnParameter = OperationUtil.getReturnParameter(operation);
   if (returnParameter != null) {
     // non unique parameter
     if (!returnParameter.isUnique()) {
       buffer.append("nonunique");
       needsComma = true;
     }
     // return parameter has ordered values
     if (returnParameter.isOrdered()) {
       if (needsComma) {
         buffer.append(", ");
       }
       buffer.append("ordered");
       needsComma = true;
     }
   }
   // is the operation a query ?
   if (operation.isQuery()) {
     if (needsComma) {
       buffer.append(", ");
     }
     buffer.append("query");
     needsComma = true;
   }
   // is the operation redefining another operation ?
   Iterator<Operation> it = operation.getRedefinedOperations().iterator();
   while (it.hasNext()) {
     Operation currentOperation = it.next();
     if (needsComma) {
       buffer.append(", ");
     }
     buffer.append("redefines ");
     buffer.append(currentOperation.getName());
     needsComma = true;
   }
   // has the operation a constraint ?
   Iterator<Constraint> it2 = operation.getOwnedRules().iterator();
   while (it2.hasNext()) {
     Constraint constraint = it2.next();
     if (needsComma) {
       buffer.append(", ");
     }
     if (constraint.getSpecification() != null) {
       buffer.append(constraint.getSpecification().stringValue());
     }
     needsComma = true;
   }
   return buffer.toString();
 }
  /**
   * Returns the string representing the import block for a given classifier.
   *
   * @param aClassifier The classifier
   * @return The string representing the import block for a given classifier.
   */
  public String reqImport(Classifier aClassifier) {
    Set<String> importedTypes = new LinkedHashSet<String>();

    List<Property> attributes = aClassifier.getAttributes();
    for (Property property : attributes) {
      String qualifiedName = this.qualifiedName(property.getType());
      if (qualifiedName != null) {
        importedTypes.add(qualifiedName);
      }
      if (property.getUpper() != 1) {
        String collectionQualifiedName =
            this.collectionQualifiedName(aClassifier, property.isOrdered(), property.isUnique());
        if (collectionQualifiedName != null) {
          importedTypes.add(collectionQualifiedName);
        }
      }
    }

    List<Operation> operations = aClassifier.getOperations();
    for (Operation operation : operations) {
      String qualifiedName = this.qualifiedName(operation.getType());
      if (qualifiedName != null) {
        importedTypes.add(qualifiedName);
      }
      if (operation.getUpper() != 1) {
        String collectionQualifiedName =
            this.collectionQualifiedName(aClassifier, operation.isOrdered(), operation.isUnique());
        if (collectionQualifiedName != null) {
          importedTypes.add(collectionQualifiedName);
        }
      }

      List<Parameter> ownedParameters = operation.getOwnedParameters();
      for (Parameter parameter : ownedParameters) {
        qualifiedName = this.qualifiedName(parameter.getType());
        if (qualifiedName != null) {
          importedTypes.add(qualifiedName);
        }
        if (parameter.getUpper() != 1) {
          String collectionQualifiedName =
              this.collectionQualifiedName(
                  aClassifier, parameter.isOrdered(), parameter.isUnique());
          if (collectionQualifiedName != null) {
            importedTypes.add(collectionQualifiedName);
          }
        }
      }

      List<Type> raisedExceptions = operation.getRaisedExceptions();
      for (Type type : raisedExceptions) {
        String exceptionQualifiedName = this.qualifiedName(type);
        if (exceptionQualifiedName != null) {
          importedTypes.add(exceptionQualifiedName);
        }
      }
    }

    List<String> sortedImportedTypes = new ArrayList<String>(importedTypes);
    Collections.sort(sortedImportedTypes);

    StringBuilder stringBuilder = new StringBuilder();
    for (String importedType : sortedImportedTypes) {
      stringBuilder.append(IMPORT + importedType + END_IMPORT);
    }

    return stringBuilder.toString();
  }