本文整理汇总了Java中org.w3c.dom.xpath.XPathException.TYPE_ERR属性的典型用法代码示例。如果您正苦于以下问题:Java XPathException.TYPE_ERR属性的具体用法?Java XPathException.TYPE_ERR怎么用?Java XPathException.TYPE_ERR使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.w3c.dom.xpath.XPathException
的用法示例。
在下文中一共展示了XPathException.TYPE_ERR属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: snapshotItem
/**
* Returns the <code>index</code>th item in the snapshot collection. If
* <code>index</code> is greater than or equal to the number of nodes in
* the list, this method returns <code>null</code>. Unlike the iterator
* result, the snapshot does not become invalid, but may not correspond
* to the current document if it is mutated.
* @param index Index into the snapshot collection.
* @return The node at the <code>index</code>th position in the
* <code>NodeList</code>, or <code>null</code> if that is not a valid
* index.
* @exception XPathException
* TYPE_ERR: raised if <code>resultType</code> is not
* <code>UNORDERED_NODE_SNAPSHOT_TYPE</code> or
* <code>ORDERED_NODE_SNAPSHOT_TYPE</code>.
*
* @see org.w3c.dom.xpath.XPathResult#snapshotItem(int)
*/
public Node snapshotItem(int index) throws XPathException {
if ((m_resultType != UNORDERED_NODE_SNAPSHOT_TYPE) &&
(m_resultType != ORDERED_NODE_SNAPSHOT_TYPE)) {
String fmsg = XPATHMessages.createXPATHMessage(XPATHErrorResources.ER_NON_SNAPSHOT_TYPE, new Object[] {m_xpath.getPatternString(), getTypeString(m_resultType)});
throw new XPathException(XPathException.TYPE_ERR, fmsg);
// "The method snapshotItem cannot be called on the XPathResult of XPath expression {0} because its XPathResultType is {1}.
// This method applies only to types UNORDERED_NODE_SNAPSHOT_TYPE and ORDERED_NODE_SNAPSHOT_TYPE."},
}
Node node = m_list.item(index);
// Wrap "namespace node" in an XPathNamespace
if (isNamespaceNode(node)) {
return new XPathNamespaceImpl(node);
} else {
return node;
}
}
示例2: getSingleNodeValue
public Node getSingleNodeValue()
{
switch (type)
{
case XPathResult.FIRST_ORDERED_NODE_TYPE:
case XPathResult.ORDERED_NODE_ITERATOR_TYPE:
case XPathResult.ORDERED_NODE_SNAPSHOT_TYPE:
case XPathResult.UNORDERED_NODE_ITERATOR_TYPE:
case XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE:
Collection ns = (Collection) value;
if (ns.isEmpty ())
{
return null;
}
else
{
return (Node) ns.iterator ().next ();
}
}
throw new XPathException (XPathException.TYPE_ERR, value.toString ());
}
示例3: iterateNext
public Node iterateNext()
{
if (iterator != null)
{
if (iterator.hasNext ())
{
return (Node) iterator.next ();
}
else
{
iterator = null;
return null;
}
}
throw new XPathException (XPathException.TYPE_ERR, value.toString ());
}
示例4: snapshotItem
public Node snapshotItem(int index)
{
switch (type)
{
case XPathResult.FIRST_ORDERED_NODE_TYPE:
case XPathResult.ORDERED_NODE_ITERATOR_TYPE:
case XPathResult.ORDERED_NODE_SNAPSHOT_TYPE:
case XPathResult.UNORDERED_NODE_ITERATOR_TYPE:
case XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE:
Collection ns = (Collection) value;
Node[] nodes = new Node[ns.size ()];
ns.toArray (nodes);
return nodes[index];
}
throw new XPathException (XPathException.TYPE_ERR, value.toString ());
}
示例5: getNumberValue
/**
* The value of this number result.
* @exception XPathException
* TYPE_ERR: raised if <code>resultType</code> is not
* <code>NUMBER_TYPE</code>.
* @see org.w3c.dom.xpath.XPathResult#getNumberValue()
*/
public double getNumberValue() throws XPathException {
if (getResultType() != NUMBER_TYPE) {
String fmsg = XPATHMessages.createXPATHMessage(XPATHErrorResources.ER_CANT_CONVERT_XPATHRESULTTYPE_TO_NUMBER, new Object[] {m_xpath.getPatternString(), getTypeString(m_resultType)});
throw new XPathException(XPathException.TYPE_ERR,fmsg);
// "The XPathResult of XPath expression {0} has an XPathResultType of {1} which cannot be converted to a number"
} else {
try {
return m_resultObj.num();
} catch (Exception e) {
// Type check above should prevent this exception from occurring.
throw new XPathException(XPathException.TYPE_ERR,e.getMessage());
}
}
}
示例6: getStringValue
/**
* The value of this string result.
* @exception XPathException
* TYPE_ERR: raised if <code>resultType</code> is not
* <code>STRING_TYPE</code>.
*
* @see org.w3c.dom.xpath.XPathResult#getStringValue()
*/
public String getStringValue() throws XPathException {
if (getResultType() != STRING_TYPE) {
String fmsg = XPATHMessages.createXPATHMessage(XPATHErrorResources.ER_CANT_CONVERT_TO_STRING, new Object[] {m_xpath.getPatternString(), m_resultObj.getTypeString()});
throw new XPathException(XPathException.TYPE_ERR,fmsg);
// "The XPathResult of XPath expression {0} has an XPathResultType of {1} which cannot be converted to a string."
} else {
try {
return m_resultObj.str();
} catch (Exception e) {
// Type check above should prevent this exception from occurring.
throw new XPathException(XPathException.TYPE_ERR,e.getMessage());
}
}
}
示例7: getBooleanValue
/**
* @see org.w3c.dom.xpath.XPathResult#getBooleanValue()
*/
public boolean getBooleanValue() throws XPathException {
if (getResultType() != BOOLEAN_TYPE) {
String fmsg = XPATHMessages.createXPATHMessage(XPATHErrorResources.ER_CANT_CONVERT_TO_BOOLEAN, new Object[] {m_xpath.getPatternString(), getTypeString(m_resultType)});
throw new XPathException(XPathException.TYPE_ERR,fmsg);
// "The XPathResult of XPath expression {0} has an XPathResultType of {1} which cannot be converted to a boolean."
} else {
try {
return m_resultObj.bool();
} catch (TransformerException e) {
// Type check above should prevent this exception from occurring.
throw new XPathException(XPathException.TYPE_ERR,e.getMessage());
}
}
}
示例8: getSingleNodeValue
/**
* The value of this single node result, which may be <code>null</code>.
* @exception XPathException
* TYPE_ERR: raised if <code>resultType</code> is not
* <code>ANY_UNORDERED_NODE_TYPE</code> or
* <code>FIRST_ORDERED_NODE_TYPE</code>.
*
* @see org.w3c.dom.xpath.XPathResult#getSingleNodeValue()
*/
public Node getSingleNodeValue() throws XPathException {
if ((m_resultType != ANY_UNORDERED_NODE_TYPE) &&
(m_resultType != FIRST_ORDERED_NODE_TYPE)) {
String fmsg = XPATHMessages.createXPATHMessage(XPATHErrorResources.ER_CANT_CONVERT_TO_SINGLENODE, new Object[] {m_xpath.getPatternString(), getTypeString(m_resultType)});
throw new XPathException(XPathException.TYPE_ERR,fmsg);
// "The XPathResult of XPath expression {0} has an XPathResultType of {1} which cannot be converted to a single node.
// This method applies only to types ANY_UNORDERED_NODE_TYPE and FIRST_ORDERED_NODE_TYPE."
}
NodeIterator result = null;
try {
result = m_resultObj.nodeset();
} catch (TransformerException te) {
throw new XPathException(XPathException.TYPE_ERR,te.getMessage());
}
if (null == result) return null;
Node node = result.nextNode();
// Wrap "namespace node" in an XPathNamespace
if (isNamespaceNode(node)) {
return new XPathNamespaceImpl(node);
} else {
return node;
}
}
示例9: getSnapshotLength
/**
* The number of nodes in the result snapshot. Valid values for
* snapshotItem indices are <code>0</code> to
* <code>snapshotLength-1</code> inclusive.
* @exception XPathException
* TYPE_ERR: raised if <code>resultType</code> is not
* <code>UNORDERED_NODE_SNAPSHOT_TYPE</code> or
* <code>ORDERED_NODE_SNAPSHOT_TYPE</code>.
*
* @see org.w3c.dom.xpath.XPathResult#getSnapshotLength()
*/
public int getSnapshotLength() throws XPathException {
if ((m_resultType != UNORDERED_NODE_SNAPSHOT_TYPE) &&
(m_resultType != ORDERED_NODE_SNAPSHOT_TYPE)) {
String fmsg = XPATHMessages.createXPATHMessage(XPATHErrorResources.ER_CANT_GET_SNAPSHOT_LENGTH, new Object[] {m_xpath.getPatternString(), getTypeString(m_resultType)});
throw new XPathException(XPathException.TYPE_ERR,fmsg);
// "The method getSnapshotLength cannot be called on the XPathResult of XPath expression {0} because its XPathResultType is {1}.
}
return m_list.getLength();
}
示例10: getBooleanValue
public boolean getBooleanValue()
{
if (type == XPathResult.BOOLEAN_TYPE)
{
return ((Boolean) value).booleanValue ();
}
throw new XPathException (XPathException.TYPE_ERR, value.toString ());
}
示例11: getNumberValue
public double getNumberValue()
{
if (type == XPathResult.NUMBER_TYPE)
{
return ((Double) value).doubleValue ();
}
throw new XPathException (XPathException.TYPE_ERR, value.toString ());
}
示例12: getSnapshotLength
public int getSnapshotLength()
{
switch (type)
{
case XPathResult.FIRST_ORDERED_NODE_TYPE:
case XPathResult.ORDERED_NODE_ITERATOR_TYPE:
case XPathResult.ORDERED_NODE_SNAPSHOT_TYPE:
case XPathResult.UNORDERED_NODE_ITERATOR_TYPE:
case XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE:
return ((Collection) value).size ();
}
throw new XPathException (XPathException.TYPE_ERR, value.toString ());
}
示例13: getStringValue
public String getStringValue()
{
if (type == XPathResult.STRING_TYPE)
{
return (String) value;
}
throw new XPathException (XPathException.TYPE_ERR, value.toString ());
}
示例14: evaluate
public Object evaluate(Node contextNode, short type, Object result)
throws XPathException, DOMException
{
try
{
QName typeName = null;
switch (type)
{
case XPathResult.BOOLEAN_TYPE:
typeName = XPathConstants.BOOLEAN;
break;
case XPathResult.NUMBER_TYPE:
typeName = XPathConstants.NUMBER;
break;
case XPathResult.STRING_TYPE:
typeName = XPathConstants.STRING;
break;
case XPathResult.ANY_UNORDERED_NODE_TYPE:
case XPathResult.FIRST_ORDERED_NODE_TYPE:
typeName = XPathConstants.NODE;
break;
case XPathResult.UNORDERED_NODE_ITERATOR_TYPE:
case XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE:
case XPathResult.ORDERED_NODE_ITERATOR_TYPE:
case XPathResult.ORDERED_NODE_SNAPSHOT_TYPE:
typeName = XPathConstants.NODESET;
break;
default:
throw new XPathException(XPathException.TYPE_ERR, null);
}
Object val = expression.evaluate(contextNode, typeName);
switch (type)
{
case XPathResult.ORDERED_NODE_ITERATOR_TYPE:
case XPathResult.ORDERED_NODE_SNAPSHOT_TYPE:
// Sort the nodes
List ns = new ArrayList((Collection) val);
Collections.sort(ns, new DocumentOrderComparator());
val = ns;
}
return new DomXPathResult(val, type);
}
catch (javax.xml.xpath.XPathException e)
{
throw new XPathException(XPathException.TYPE_ERR, e.getMessage());
}
}
示例15: evaluate
public Object evaluate(Node contextNode, short type, Object result)
throws XPathException, DOMException
{
try
{
QName typeName = null;
switch (type)
{
case XPathResult.BOOLEAN_TYPE:
typeName = XPathConstants.BOOLEAN;
break;
case XPathResult.NUMBER_TYPE:
typeName = XPathConstants.NUMBER;
break;
case XPathResult.STRING_TYPE:
typeName = XPathConstants.STRING;
break;
case XPathResult.ANY_UNORDERED_NODE_TYPE:
case XPathResult.FIRST_ORDERED_NODE_TYPE:
typeName = XPathConstants.NODE;
break;
case XPathResult.UNORDERED_NODE_ITERATOR_TYPE:
case XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE:
case XPathResult.ORDERED_NODE_ITERATOR_TYPE:
case XPathResult.ORDERED_NODE_SNAPSHOT_TYPE:
typeName = XPathConstants.NODESET;
break;
default:
throw new XPathException(XPathException.TYPE_ERR, null);
}
Object val = expression.evaluate(contextNode, typeName);
switch (type)
{
case XPathResult.ORDERED_NODE_ITERATOR_TYPE:
case XPathResult.ORDERED_NODE_SNAPSHOT_TYPE:
// Sort the nodes
List ns = new ArrayList((Collection) val);
Collections.sort(ns, new DocumentOrderComparator());
val = ns;
}
return new DomXPathResult(val, type);
}
catch (javax.xml.xpath.XPathException e)
{
throw new XPathException(XPathException.TYPE_ERR, e.getMessage());
}
}