require 'java'
include_class 'javax.xml.XMLConstants'
include_class 'javax.xml.namespace.NamespaceContext'
include_class 'javax.xml.xpath.XPathFactory'

class NSCT1 < NamespaceContext

  def initialize foo
    # doesn't need to do anything
  end

  def getNamespaceURI prefix
    return 'ape:sex'
  end
end

class NSCT2 < NamespaceContext

  def getNamespaceURI prefix
    return 'ape:sex'
  end
end

x = XPathFactory.newInstance.newXPath
n1 = NSCT1.new('foo')
n2 = NSCT2.new

x.setNamespaceContext(n2)
puts "Worked fine with NSC2"
x.setNamespaceContext(n1)


