/** Inherits and resolve */
  @Override
  public Set<Link> getLinks(String relName) {
    Set<Link> dests = getExistingLinks(relName);
    if (!dests.isEmpty()) {
      return dests;
    }

    // None are present. Try to resolve
    RelationDefinition rel = getRelation(relName);
    if (rel == null) {
      logger.error("relation " + relName + " undefined for " + this);
      return null;
    }

    // if (!rel.isLazy())
    // return dests ;

    Component source = rel.getRelSource(this);
    CST.apamResolver.resolveLink(source, rel);
    return getExistingLinks(relName);
  }
  @Override
  public Link getLink(String relName) {
    Component group = this;
    while (group != null) {
      for (Link link : ((ComponentImpl) group).getLocalLinks()) {
        if (link.getName().equals(relName)) {
          return link;
        }
      }
      group = group.getGroup();
    }

    // None are present. Try to resolve
    RelationDefinition rel = getRelation(relName);
    if (rel == null) {
      logger.error("relation " + relName + " undefined for " + this);
      return null;
    }
    Component source = rel.getRelSource(this);
    CST.apamResolver.resolveLink(source, rel);
    return getExistingLink(relName);
  }
  @Override
  public Set<RelationDefinition> getRelations() {
    Set<RelationDefinition> relDefs = new HashSet<RelationDefinition>();
    Set<String> processed = new HashSet<String>();

    Component group = this;
    while (group != null) {

      for (RelationDefinition relDef : group.getLocalRelations()) {
        if (!processed.contains(relDef.getName())) {
          relDefs.add(relDef);
          processed.add(relDef.getName());
        }
      }

      group = group.getGroup();
    }

    // Looking for composite definitions.
    if (this instanceof Instance) {
      CompositeType comptype = ((Instance) this).getComposite().getCompType();

      for (RelationDefinition relDef : comptype.getCtxtRelations(this)) {
        if (!processed.contains(relDef.getName())) {
          relDefs.add(relDef);
          processed.add(relDef.getName());
        }
      }
    }
    if (this instanceof Implementation) {
      for (CompositeType comptype : ((Implementation) this).getInCompositeType()) {
        for (RelationDefinition relDef : comptype.getCtxtRelations(this)) {
          if (!processed.contains(relDef.getName())) {
            relDefs.add(relDef);
            processed.add(relDef.getName());
          }
        }
      }
    }

    return relDefs;
  }