KickJava   Java API By Example, From Geeks To Geeks.

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


1 package net.sf.saxon.functions;
2 import net.sf.saxon.expr.XPathContext;
3 import net.sf.saxon.om.Item;
4 import net.sf.saxon.om.Name;
5 import net.sf.saxon.om.QNameException;
6 import net.sf.saxon.trans.XPathException;
7 import net.sf.saxon.value.AtomicValue;
8 import net.sf.saxon.value.QNameValue;
9
10
11 /**
12 * This class supports the fn:QName() function (previously named fn:expanded-QName())
13 */

14
15 public class QNameFn extends SystemFunction {
16
17     /**
18     * Evaluate the expression
19     */

20
21     public Item evaluateItem(XPathContext context) throws XPathException {
22         AtomicValue arg0 = (AtomicValue)argument[0].evaluateItem(context);
23
24         String JavaDoc uri;
25         if (arg0 == null) {
26             uri = null;
27         } else {
28             uri = arg0.getStringValue();
29         }
30
31         try {
32             String JavaDoc lex = argument[1].evaluateItem(context).getStringValue();
33             String JavaDoc[] parts = Name.getQNameParts(lex);
34             return new QNameValue(parts[0], uri, parts[1]);
35         } catch (QNameException e) {
36             dynamicError(e.getMessage(), "FOCA0002", context);
37             return null;
38         }
39     }
40
41 }
42
43
44
45
46
47 //
48
// The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
49
// you may not use this file except in compliance with the License. You may obtain a copy of the
50
// License at http://www.mozilla.org/MPL/
51
//
52
// Software distributed under the License is distributed on an "AS IS" basis,
53
// WITHOUT WARRANTY OF ANY KIND, either express or implied.
54
// See the License for the specific language governing rights and limitations under the License.
55
//
56
// The Original Code is: all this file.
57
//
58
// The Initial Developer of the Original Code is Michael H. Kay
59
//
60
// Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
61
//
62
// Contributor(s): none.
63
//
64
Popular Tags