Standard Libraries

import default
import semmle.code.java.frameworks.spring.SpringBeanFile
import semmle.code.java.frameworks.spring.SpringBean

/** The superclass of all Spring XML elements*/
class SpringXMLElement extends XMLElement {
  SpringXMLElement() {
    this.getFile() instanceof SpringBeanFile
  }

  /** Returns a child of the Spring XML element*/
  SpringXMLElement getASpringChild() {
    result = (SpringXMLElement) (this.getAChild())
  }

  /** Returns the bean file of this xml element*/
  SpringBeanFile getSpringBeanFile() {
    result = (SpringBeanFile)(this.getFile())
  }

  //helper method
  /** Returns the value of the attribute with name attributeName, or "default" if the
    * attribute is not present*/
  string getAttributeValueWithDefault(string attributeName) {
    this.hasAttribute(attributeName) and
    if exists(XMLAttribute a | a = this.getAttribute(attributeName)) 
    then result = this.getAttributeValue(attributeName)
    else result = "default"
  }

  /** Returns the closest enclosing <bean> element*/
  SpringBean getEnclosingBean() {
    if this instanceof SpringBean 
    then result = this
    else result = ((SpringXMLElement)this.getParent()).getEnclosingBean()
  }

  /** "abstract" method of isSimilar, which returns false on any parameter. Is overriden
    * by subclasses and is used to match value, property and ref elements for similarity*/
  predicate isSimilar(SpringXMLElement other) {
    not any()
  }

  string getContentString() {
    result = this.allCharactersString()
	}
}