KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > icl > saxon > functions > UnparsedEntityURI


1 package com.icl.saxon.functions;
2 import com.icl.saxon.*;
3 import com.icl.saxon.om.DocumentInfo;
4 import com.icl.saxon.expr.*;
5 import com.icl.saxon.om.NodeInfo;
6 import java.util.*;
7
8
9
10
11 public class UnparsedEntityURI extends Function {
12
13     DocumentInfo boundDocument = null;
14
15     public String JavaDoc getName() {
16         return "unparsed-entity-uri";
17     };
18
19     /**
20     * Determine the data type of the expression
21     * @return Value.STRING
22     */

23
24     public int getDataType() {
25         return Value.STRING;
26     }
27
28     /**
29     * Validate and simplify
30     */

31
32     public Expression simplify() throws XPathException {
33         checkArgumentCount(1, 1);
34         return this;
35     }
36
37     /**
38     * Evaluate the expression in a string context
39     */

40
41     public String JavaDoc evaluateAsString(Context context) throws XPathException {
42         String JavaDoc arg0 = argument[0].evaluateAsString(context);
43         DocumentInfo doc = boundDocument;
44         if (doc==null) doc = (context.getContextNodeInfo()).getDocumentRoot();
45         return doc.getUnparsedEntity(arg0);
46     }
47
48     /**
49     * Evaluate in a general context
50     */

51
52     public Value evaluate(Context c) throws XPathException {
53         return new StringValue(evaluateAsString(c));
54     }
55
56     /**
57     * Determine which aspects of the context the expression depends on. The result is
58     * a bitwise-or'ed value composed from constants such as Context.VARIABLES and
59     * Context.CURRENT_NODE
60     */

61
62     public int getDependencies() {
63         int dep = argument[0].getDependencies();
64         if (boundDocument==null) {
65             dep |= Context.CONTEXT_NODE;
66         }
67         return dep;
68     }
69
70     /**
71     * Remove dependencies.
72     */

73
74     public Expression reduce(int dep, Context c) throws XPathException {
75         UnparsedEntityURI f = new UnparsedEntityURI();
76         f.addArgument(argument[0].reduce(dep, c));
77         f.setStaticContext(getStaticContext());
78         
79         if (boundDocument==null && ((dep & Context.CONTEXT_NODE)!=0)) {
80             f.boundDocument = (c.getContextNodeInfo()).getDocumentRoot();
81         } else {
82             f.boundDocument = this.boundDocument;
83         }
84         return f;
85     }
86
87
88 }
89
90
91
92
93 //
94
// The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
95
// you may not use this file except in compliance with the License. You may obtain a copy of the
96
// License at http://www.mozilla.org/MPL/
97
//
98
// Software distributed under the License is distributed on an "AS IS" basis,
99
// WITHOUT WARRANTY OF ANY KIND, either express or implied.
100
// See the License for the specific language governing rights and limitations under the License.
101
//
102
// The Original Code is: all this file.
103
//
104
// The Initial Developer of the Original Code is
105
// Michael Kay of International Computers Limited (mhkay@iclway.co.uk).
106
//
107
// Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
108
//
109
// Contributor(s): none.
110
//
111
Popular Tags