Esempio n. 1
0
  /**
   * @param chain
   * @return The weakest type of relationship in a chain of relationships
   */
  public static EClass getWeakestType(List<IRelationship> chain) {
    int weakest = weaklist.size() - 1;

    for (IRelationship rel : chain) {
      int index = weaklist.indexOf(rel.eClass());
      if (index < weakest) {
        weakest = index;
      }
    }

    return weaklist.get(weakest);
  }
Esempio n. 2
0
  /**
   * Create a derived relation between two elements
   *
   * @param element1
   * @param element2
   * @return the derived relationship or null
   * @throws TooComplicatedException
   */
  public static IRelationship createDerivedRelationship(
      IArchimateElement element1, IArchimateElement element2) throws TooComplicatedException {
    if (element1 == null || element2 == null) {
      return null;
    }

    // System.out.println("-----------------------------------");
    // System.out.println("Starting hunt from " + element1.getName() + " --> " +
    // element2.getName());
    // System.out.println("-----------------------------------");

    // Traverse from element1 to element2
    List<List<IRelationship>> chains = findChains(element1, element2);

    if (chains.isEmpty()) {
      return null;
    }

    int weakest = weaklist.size() - 1;

    // You are the weakest link...goodbye.
    for (List<IRelationship> chain : chains) {
      for (IRelationship rel : chain) {
        // printChain(chain);
        int index = weaklist.indexOf(rel.eClass());
        if (index < weakest) {
          weakest = index;
        }
      }
    }

    EClass relationshipClass = weaklist.get(weakest);
    // System.out.println("Weakest is: " + relationshipClass);

    /*
     * Check the validity of the relationship.
     */
    boolean isValid =
        ArchimateModelUtils.isValidRelationship(element1, element2, relationshipClass);
    if (!isValid) {
      return null;
    }

    return (IRelationship) IArchimateFactory.eINSTANCE.create(relationshipClass);
  }