KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > saxon > functions > ResolveQName


1 package net.sf.saxon.functions;
2 import net.sf.saxon.expr.XPathContext;
3 import net.sf.saxon.om.*;
4 import net.sf.saxon.trans.XPathException;
5 import net.sf.saxon.value.AtomicValue;
6 import net.sf.saxon.value.QNameValue;
7
8
9 /**
10 * This class supports the resolve-QName function in XPath 2.0
11 */

12
13 public class ResolveQName extends SystemFunction {
14
15     /**
16     * Evaluate the expression
17     */

18
19     public Item evaluateItem(XPathContext context) throws XPathException {
20         AtomicValue arg0 = (AtomicValue)argument[0].evaluateItem(context);
21         if (arg0 == null) {
22             return null;
23         }
24
25         CharSequence JavaDoc qname = arg0.getStringValueCS();
26         String JavaDoc[] parts;
27         try {
28             parts = Name.getQNameParts(qname);
29         } catch (QNameException err) {
30             dynamicError(err.getMessage(), "FOCA0002", context);
31             return null;
32         }
33
34         NodeInfo element = (NodeInfo)argument[1].evaluateItem(context);
35         SequenceIterator nsNodes = element.iterateAxis(Axis.NAMESPACE);
36
37         while (true) {
38             NodeInfo namespace = (NodeInfo)nsNodes.next();
39             if (namespace==null) {
40                 break;
41             }
42             String JavaDoc prefix = namespace.getLocalPart();
43             if (prefix.equals(parts[0])) {
44                 return new QNameValue(prefix, namespace.getStringValue(), parts[1]);
45             }
46         }
47
48         if (parts[0].equals("")) {
49             return new QNameValue("", null, parts[1]);
50         }
51
52         dynamicError(
53             "Namespace prefix '" + parts[0] + "' is not in scope for the selected element", "FONS0004", context);
54         return null;
55     }
56
57 }
58
59
60
61
62
63 //
64
// The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
65
// you may not use this file except in compliance with the License. You may obtain a copy of the
66
// License at http://www.mozilla.org/MPL/
67
//
68
// Software distributed under the License is distributed on an "AS IS" basis,
69
// WITHOUT WARRANTY OF ANY KIND, either express or implied.
70
// See the License for the specific language governing rights and limitations under the License.
71
//
72
// The Original Code is: all this file.
73
//
74
// The Initial Developer of the Original Code is Michael H. Kay
75
//
76
// Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
77
//
78
// Contributor(s): none.
79
//
80
Popular Tags