KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > icl > saxon > expr > ErrorExpression


1 package com.icl.saxon.expr;
2 import com.icl.saxon.*;
3 import java.util.*;
4
5
6 /**
7 * Error expression: this expression is generated when the supplied expression cannot be
8 * parsed, and the containing element enables forwards-compatible processing. It defers
9 * the generation of an error message until an attempt is made to evaluate the expression
10 */

11
12 public class ErrorExpression extends Expression {
13
14     private XPathException exception; // the error found when parsing this expression
15

16     /**
17     * Constructor
18     * @param exception the error found when parsing this expression
19     */

20
21     public ErrorExpression(XPathException exception) {
22         this.exception = exception;
23     };
24
25     /**
26     * Evaluate this expression. This always throws the exception registered when the expression
27     * was first parsed.
28     */

29
30     public Value evaluate(Context c) throws XPathException {
31         throw exception;
32     }
33
34     /**
35     * Determine the data type of the expression, if possible
36     * @return Value.ANY (meaning not known in advance)
37     */

38
39     public int getDataType() {
40         return Value.ANY;
41     }
42     
43     /**
44     * Determine which aspects of the context the expression depends on. The result is
45     * a bitwise-or'ed value composed from constants such as Context.VARIABLES and
46     * Context.CURRENT_NODE
47     */

48
49     public int getDependencies() {
50         return 0;
51     }
52
53     /**
54     * Perform a partial evaluation of the expression, by eliminating specified dependencies
55     * on the context.
56     * @param dependencies The dependencies to be removed
57     * @param context The context to be used for the partial evaluation
58     * @return a new expression that does not have any of the specified
59     * dependencies
60     */

61
62     public Expression reduce(int dependencies, Context context) throws XPathException {
63         return this;
64     }
65
66     /**
67     * Diagnostic print of expression structure
68     */

69     
70     public void display(int level) {
71         System.err.println(indent(level) + "**ERROR** (" + exception.getMessage() + ")");
72     }
73
74 }
75
76 //
77
// The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
78
// you may not use this file except in compliance with the License. You may obtain a copy of the
79
// License at http://www.mozilla.org/MPL/
80
//
81
// Software distributed under the License is distributed on an "AS IS" basis,
82
// WITHOUT WARRANTY OF ANY KIND, either express or implied.
83
// See the License for the specific language governing rights and limitations under the License.
84
//
85
// The Original Code is: all this file.
86
//
87
// The Initial Developer of the Original Code is
88
// Michael Kay of International Computers Limited (mhkay@iclway.co.uk).
89
//
90
// Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
91
//
92
// Contributor(s): none.
93
//
94
Popular Tags