KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > xalan > templates > AbsPathChecker


1 /*
2  * Copyright 2002-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 /*
17  * $Id: AbsPathChecker.java,v 1.4 2004/02/16 20:32:32 minchau Exp $
18  */

19 package org.apache.xalan.templates;
20
21 import org.apache.xpath.ExpressionOwner;
22 import org.apache.xpath.XPathVisitor;
23 import org.apache.xpath.axes.LocPathIterator;
24 import org.apache.xpath.functions.FuncCurrent;
25 import org.apache.xpath.functions.FuncExtFunction;
26 import org.apache.xpath.functions.Function;
27 import org.apache.xpath.operations.Variable;
28
29 /**
30  * This class runs over a path expression that is assumed to be absolute, and
31  * checks for variables and the like that may make it context dependent.
32  */

33 public class AbsPathChecker extends XPathVisitor
34 {
35     private boolean m_isAbs = true;
36     
37     /**
38      * Process the LocPathIterator to see if it contains variables
39      * or functions that may make it context dependent.
40      * @param path LocPathIterator that is assumed to be absolute, but needs checking.
41      * @return true if the path is confirmed to be absolute, false if it
42      * may contain context dependencies.
43      */

44     public boolean checkAbsolute(LocPathIterator path)
45     {
46         m_isAbs = true;
47         path.callVisitors(null, this);
48         return m_isAbs;
49     }
50     
51     /**
52      * Visit a function.
53      * @param owner The owner of the expression, to which the expression can
54      * be reset if rewriting takes place.
55      * @param func The function reference object.
56      * @return true if the sub expressions should be traversed.
57      */

58     public boolean visitFunction(ExpressionOwner owner, Function func)
59     {
60         if((func instanceof FuncCurrent) ||
61            (func instanceof FuncExtFunction))
62             m_isAbs = false;
63         return true;
64     }
65     
66     /**
67      * Visit a variable reference.
68      * @param owner The owner of the expression, to which the expression can
69      * be reset if rewriting takes place.
70      * @param var The variable reference object.
71      * @return true if the sub expressions should be traversed.
72      */

73     public boolean visitVariableRef(ExpressionOwner owner, Variable var)
74     {
75         m_isAbs = false;
76         return true;
77     }
78 }
79
80
Popular Tags