Standard Libraries

import default
import semmle.code.java.frameworks.spring.SpringAbstractRef

/** Represents a <ref> element in a Spring XML file*/
class SpringRef extends SpringAbstractRef {
  SpringRef() {
    this.getName() = "ref"
  }

  /** true if the ref has a parent attribute*/
  predicate hasBeanNameInParent() {
    this.hasAttribute("parent")
  }
  /** returns the value of the parent attribute*/
  string getBeanNameInParent() {
    result = this.getAttributeValue("parent")
  }

  //NOTE: Currently incomplete, as the Spring docs are unclear on parent references
  /** returns the bean referred to by the ref element*/
  SpringBean getBean() {
    if this.hasBeanLocalName()
    then result.getBeanId() = this.getBeanLocalName()
    else result.getBeanIdentifier() = this.getBeanName()
    //TODO: Check parent
	}
}