Ejemplo n.º 1
0
  /**
   * No resolution
   *
   * @param depName
   * @return
   */
  public Set<Component> getRawLinkDests(String depName) {
    if (depName == null || depName.isEmpty()) {
      return null;
    }

    if (CST.isFinalRelation(depName)) {
      return getFInalLinkDests(depName);
    }

    Set<Component> dests = new HashSet<Component>();
    for (Link link : getRawLinks()) {
      if (link.getName().equals(depName)) {
        dests.add(link.getDestination());
      }
    }
    return dests;
  }
Ejemplo n.º 2
0
  @Override
  public boolean createLink(
      Component to, RelToResolve dep, boolean hasConstraints, boolean promotion) {
    // Not a relation : a find
    if (!dep.isRelation()) {
      return true;
    }

    if (CST.isFinalRelation(dep.getName())) {
      logger.error("CreateLink: cannot create predefined relation " + dep.getName());
      return false;
    }

    if ((to == null) || (dep == null)) {
      logger.error("CreateLink: Source or target are null ");
      return false;
    }

    if (!promotion && !canSee(to)) {
      logger.error("CreateLink: Source  " + this + " does not see its target " + to);
      return false;
    }

    if (this.getKind() != dep.getSourceKind()) {
      logger.error(
          "CreateLink: Source kind "
              + getKind()
              + " is not compatible with relation sourceType "
              + dep.getSourceKind());
      return false;
    }

    if (to.getKind() != dep.getTargetKind()) {
      logger.error(
          "CreateLink: Target kind "
              + to.getKind()
              + " is not compatible with relation targetType "
              + dep.getTargetKind());
      return false;
    }

    if (hasConstraints && !dep.matchRelationConstraints(to)) {
      logger.error("CreateLink: Target does not satisfies the constraints");
      return false;
    }

    String depName = dep.getName();

    for (Link link : links) { // check if it already exists
      if ((link.getDestination() == to) && link.getName().equals(depName)) {
        // It exists, do nothing.
        return true;
      }
    }

    // creation
    if (!getApformComponent().checkLink(to, depName)) {
      logger.error(
          "CreateLink: INTERNAL ERROR: link from "
              + this
              + " to "
              + to
              + " could not be created in the real instance.");
      return false;
    }

    Link link = new LinkImpl(this, to, dep, hasConstraints, promotion);
    links.add(link);
    ((ComponentImpl) to).invlinks.add(link);
    getApformComponent().setLink(to, depName);

    // Notify Dynamic managers that a new link has been created
    for (DynamicManager manager : ApamManagers.getDynamicManagers()) {
      manager.addedLink(link);
    }

    return true;
  }