KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > org > apache > xalan > internal > xsltc > compiler > LocationPathPattern


1 /*
2  * Copyright 2001-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: LocationPathPattern.java,v 1.6 2004/02/16 22:24:29 minchau Exp $
18  */

19
20 package com.sun.org.apache.xalan.internal.xsltc.compiler;
21
22 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator;
23 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator;
24 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type;
25 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.TypeCheckError;
26 import com.sun.org.apache.xalan.internal.xsltc.dom.Axis;
27
28 /**
29  * @author Jacek Ambroziak
30  * @author Santiago Pericas-Geertsen
31  * @author Morten Jorgensen
32  */

33 public abstract class LocationPathPattern extends Pattern {
34     private Template _template;
35     private int _importPrecedence;
36     private double _priority = Double.NaN;
37     private int _position = 0;
38
39     public Type typeCheck(SymbolTable stable) throws TypeCheckError {
40     return Type.Void; // TODO
41
}
42
43     public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
44     // TODO: What does it mean to translate a Pattern ?
45
}
46     
47     public void setTemplate(final Template template) {
48     _template = template;
49     _priority = template.getPriority();
50     _importPrecedence = template.getImportPrecedence();
51     _position = template.getPosition();
52     }
53         
54     public Template getTemplate() {
55     return _template;
56     }
57         
58     public final double getPriority() {
59     return Double.isNaN(_priority) ? getDefaultPriority() : _priority;
60     }
61         
62     public double getDefaultPriority() {
63     return 0.5;
64     }
65
66     /**
67      * This method is used by the Mode class to prioritise patterns and
68      * template. This method is called for templates that are in the same
69      * mode and that match on the same core pattern. The rules used are:
70      * o) first check precedence - highest precedence wins
71      * o) then check priority - highest priority wins
72      * o) then check the position - the template that occured last wins
73      */

74     public boolean noSmallerThan(LocationPathPattern other) {
75     if (_importPrecedence > other._importPrecedence) {
76         return true;
77     }
78     else if (_importPrecedence == other._importPrecedence) {
79         if (_priority > other._priority) {
80         return true;
81         }
82         else if (_priority == other._priority) {
83         if (_position > other._position) {
84             return true;
85         }
86         }
87     }
88     return false;
89     }
90     
91     public abstract StepPattern getKernelPattern();
92     
93     public abstract void reduceKernelPattern();
94         
95     public abstract boolean isWildcard();
96
97     public int getAxis() {
98     final StepPattern sp = getKernelPattern();
99     return (sp != null) ? sp.getAxis() : Axis.CHILD;
100     }
101
102     public String JavaDoc toString() {
103     return "root()";
104     }
105 }
106
Popular Tags