本文整理汇总了Java中com.sun.org.apache.xpath.internal.objects.XObject.CLASS_NODESET属性的典型用法代码示例。如果您正苦于以下问题:Java XObject.CLASS_NODESET属性的具体用法?Java XObject.CLASS_NODESET怎么用?Java XObject.CLASS_NODESET使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类com.sun.org.apache.xpath.internal.objects.XObject
的用法示例。
在下文中一共展示了XObject.CLASS_NODESET属性的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getTypeFromXObject
/**
* Given an XObject, determine the corresponding DOM XPath type
*
* @return type string
*/
private short getTypeFromXObject(XObject object) {
switch (object.getType()) {
case XObject.CLASS_BOOLEAN: return BOOLEAN_TYPE;
case XObject.CLASS_NODESET: return UNORDERED_NODE_ITERATOR_TYPE;
case XObject.CLASS_NUMBER: return NUMBER_TYPE;
case XObject.CLASS_STRING: return STRING_TYPE;
// XPath 2.0 types
// case XObject.CLASS_DATE:
// case XObject.CLASS_DATETIME:
// case XObject.CLASS_DTDURATION:
// case XObject.CLASS_GDAY:
// case XObject.CLASS_GMONTH:
// case XObject.CLASS_GMONTHDAY:
// case XObject.CLASS_GYEAR:
// case XObject.CLASS_GYEARMONTH:
// case XObject.CLASS_TIME:
// case XObject.CLASS_YMDURATION: return STRING_TYPE; // treat all date types as strings?
case XObject.CLASS_RTREEFRAG: return UNORDERED_NODE_ITERATOR_TYPE;
case XObject.CLASS_NULL: return ANY_TYPE; // throw exception ?
default: return ANY_TYPE; // throw exception ?
}
}
示例2: getXPathResult
/**
* Construct an XPathExpressionResult object based on the result of the
* evaluation and cast to the specified class type.
* @param <T> The class type
* @param resultObject the result of an evaluation
* @param type The class type expected to be returned by the XPath expression.
* @return an instance of the specified type or null if the XObject returned
* an UNKNOWN object type.
* @throws TransformerException if there is an error converting the result
* to the specified type. It's unlikely to happen. This is mostly needed
* by the internal XPath engine.
*/
<T> T getXPathResult(XObject resultObject, Class<T> type)
throws TransformerException {
int resultType = resultObject.getType();
switch (resultType) {
case XObject.CLASS_BOOLEAN :
return type.cast(new XPathResultImpl<>(resultObject, Boolean.class));
case XObject.CLASS_NUMBER :
return type.cast(new XPathResultImpl<>(resultObject, Double.class));
case XObject.CLASS_STRING :
return type.cast(new XPathResultImpl<>(resultObject, String.class));
case XObject.CLASS_NODESET :
return type.cast(new XPathResultImpl<>(resultObject, XPathNodes.class));
case XObject.CLASS_RTREEFRAG : //NODE
return type.cast(new XPathResultImpl<>(resultObject, Node.class));
}
return null;
}
示例3: getResult
/**
* Read the XObject and set values in accordance with the result type
* @param resultObject internal XPath result object
* @throws TransformerException if there is an error reading the XPath
* result.
*/
private void getResult(XObject resultObject) throws TransformerException {
switch (resultType) {
case XObject.CLASS_BOOLEAN:
boolValue = resultObject.bool();
mapToType = XPathResultType.BOOLEAN;
break;
case XObject.CLASS_NUMBER:
numValue = resultObject.num();
mapToType = XPathResultType.NUMBER;
break;
case XObject.CLASS_STRING:
strValue = resultObject.str();
mapToType = XPathResultType.STRING;
break;
case XObject.CLASS_NODESET:
mapToType = XPathResultType.NODESET;
nodeList = resultObject.nodelist();
break;
case XObject.CLASS_RTREEFRAG: //NODE
mapToType = XPathResultType.NODE;
NodeIterator ni = resultObject.nodeset();
//Return the first node, or null
node = ni.nextNode();
break;
}
}
示例4: getValue
/**
* Read the internal result object and return the value in accordance with
* the type specified.
*
* @param <T> The expected class type.
* @param resultObject internal XPath result object
* @param type the class type
* @return The value of the result, null in case of unexpected type.
* @throws TransformerException if there is an error reading the XPath
* result.
*/
static <T> T getValue(XObject resultObject, Class<T> type) throws TransformerException {
Objects.requireNonNull(type);
if (type.isAssignableFrom(XPathEvaluationResult.class)) {
return type.cast(new XPathResultImpl<T>(resultObject, type));
}
int resultType = classToInternalType(type);
switch (resultType) {
case XObject.CLASS_BOOLEAN:
return type.cast(resultObject.bool());
case XObject.CLASS_NUMBER:
if (Double.class.isAssignableFrom(type)) {
return type.cast(resultObject.num());
} else if (Integer.class.isAssignableFrom(type)) {
return type.cast((int)resultObject.num());
} else if (Long.class.isAssignableFrom(type)) {
return type.cast((long)resultObject.num());
}
/*
This is to suppress warnings. By the current specification,
among numeric types, only Double, Integer and Long are supported.
*/
break;
case XObject.CLASS_STRING:
return type.cast(resultObject.str());
case XObject.CLASS_NODESET:
XPathNodes nodeSet = new XPathNodesImpl(resultObject.nodelist(),
Node.class);
return type.cast(nodeSet);
case XObject.CLASS_RTREEFRAG: //NODE
NodeIterator ni = resultObject.nodeset();
//Return the first node, or null
return type.cast(ni.nextNode());
}
return null;
}
示例5: classToInternalType
/**
* Map the specified class type to the internal result type
*
* @param <T> The expected class type.
* @param type the class type
* @return the internal XObject type.
*/
static <T> int classToInternalType(Class<T> type) {
if (type.isAssignableFrom(Boolean.class)) {
return XObject.CLASS_BOOLEAN;
} else if (Number.class.isAssignableFrom(type)) {
return XObject.CLASS_NUMBER;
} else if (type.isAssignableFrom(String.class)) {
return XObject.CLASS_STRING;
} else if (type.isAssignableFrom(XPathNodes.class)) {
return XObject.CLASS_NODESET;
} else if (type.isAssignableFrom(Node.class)) {
return XObject.CLASS_RTREEFRAG;
}
return XObject.CLASS_NULL;
}