DocumentFragment domTemplate = null;
String src = bindingElm.getAttribute("src");
if (!src.equals("")) {
ServiceManager manager = assistant.getServiceManager();
SourceResolver sourceResolver = (SourceResolver)manager.lookup(SourceResolver.ROLE);
Source source = null;
try {
source = sourceResolver.resolveURI(src);
Document document = SourceUtil.toDOM(source);
Element element = document.getDocumentElement();
String xpath = bindingElm.getAttribute("xpath");
if (!xpath.equals("")) {
XPathProcessor xpathProcessor = (XPathProcessor)manager.lookup(XPathProcessor.ROLE);
try {
Node node = xpathProcessor.selectSingleNode(document, xpath);
if (node == null)
throw new BindingException("XPath expression \"" + xpath + "\" didn't return a result.");
if (!(node instanceof Element))
throw new BindingException("XPath expression \"" + xpath + "\" did not return an element node.");
element = (Element)node;
} finally {
manager.release(xpathProcessor);
}
}
domTemplate = document.createDocumentFragment();
domTemplate.appendChild(element);
} finally {
if (source != null) {
sourceResolver.release(source);
}
manager.release(sourceResolver);
}
} else {
domTemplate = bindingElm.getOwnerDocument().createDocumentFragment();