*/
XPathResultImpl(short type, XObject result, Node contextNode) {
// Check that the type is valid
if (!isValidType(type)) {
String fmsg = XSLMessages.createXPATHMessage(XPATHErrorResources.ER_INVALID_XPATH_TYPE, new Object[] {new Integer(type)});
throw new XPathException(XPathException.TYPE_ERR,fmsg); // Invalid XPath type argument: {0}
}
// Result object should never be null!
if (null == result) {
String fmsg = XSLMessages.createXPATHMessage(XPATHErrorResources.ER_EMPTY_XPATH_RESULT, null);
throw new XPathException(XPathException.INVALID_EXPRESSION_ERR,fmsg); // Empty XPath result object
}
this.m_resultObj = result;
this.m_contextNode = contextNode;
// If specified result was ANY_TYPE, determine XObject type
if (type == ANY_TYPE) {
this.m_resultType = getTypeFromXObject(result);
} else {
this.m_resultType = type;
}
// If the context node supports DOM Events and the type is one of the iterator
// types register this result as an event listener
if (((m_resultType == XPathResult.ORDERED_NODE_ITERATOR_TYPE) ||
(m_resultType == XPathResult.UNORDERED_NODE_ITERATOR_TYPE))&&
(contextNode instanceof EventTarget)) {
((EventTarget)contextNode).addEventListener("MutationEvents",this,true);
}// else can we handle iterator types if contextNode doesn't support EventTarget??
// If this is an iterator type get the iterator
if ((m_resultType == ORDERED_NODE_ITERATOR_TYPE) ||
(m_resultType == UNORDERED_NODE_ITERATOR_TYPE) ||
(m_resultType == ANY_UNORDERED_NODE_TYPE) ||
(m_resultType == FIRST_ORDERED_NODE_TYPE)) {
try {
m_iterator = m_resultObj.nodeset();
} catch (TransformerException te) {
// probably not a node type
String fmsg = XSLMessages.createXPATHMessage(XPATHErrorResources.ER_INCOMPATIBLE_TYPES, new Object[] {getTypeString(getTypeFromXObject(m_resultObj)),getTypeString(m_resultType)});
throw new XPathException(XPathException.TYPE_ERR, fmsg); // The returned type: {0} can not be coerced into the specified type: {1}
}
// If user requested ordered nodeset and result is unordered
// need to sort...TODO
// if ((m_resultType == ORDERED_NODE_ITERATOR_TYPE) &&
// (!(((DTMNodeIterator)m_iterator).getDTMIterator().isDocOrdered()))) {
//
// }
// If it's a snapshot type, get the nodelist
} else if ((m_resultType == UNORDERED_NODE_SNAPSHOT_TYPE) ||
(m_resultType == ORDERED_NODE_SNAPSHOT_TYPE)) {
try {
m_list = m_resultObj.nodelist();
} catch (TransformerException te) {
// probably not a node type
String fmsg = XSLMessages.createXPATHMessage(XPATHErrorResources.ER_INCOMPATIBLE_TYPES, new Object[] {getTypeString(getTypeFromXObject(m_resultObj)),getTypeString(m_resultType)});
throw new XPathException(XPathException.TYPE_ERR, fmsg); // The returned type: {0} can not be coerced into the specified type: {1}
}
}
}