1 /* 2 * reserved comment block 3 * DO NOT REMOVE OR ALTER! 4 */ 5 /* 6 * Copyright 2001-2004 The Apache Software Foundation. 7 * 8 * Licensed under the Apache License, Version 2.0 (the "License"); 9 * you may not use this file except in compliance with the License. 10 * You may obtain a copy of the License at 11 * 12 * http://www.apache.org/licenses/LICENSE-2.0 13 * 14 * Unless required by applicable law or agreed to in writing, software 15 * distributed under the License is distributed on an "AS IS" BASIS, 16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 * See the License for the specific language governing permissions and 18 * limitations under the License. 19 */ 20 /* 21 * $Id: LocationPathPattern.java,v 1.2.4.1 2005/09/12 10:42:42 pvedula Exp $ 22 */ 23 24 package com.sun.org.apache.xalan.internal.xsltc.compiler; 25 26 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator; 27 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator; 28 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type; 29 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.TypeCheckError; 30 import com.sun.org.apache.xml.internal.dtm.Axis; 31 32 /** 33 * @author Jacek Ambroziak 34 * @author Santiago Pericas-Geertsen 35 * @author Morten Jorgensen 36 */ 37 public abstract class LocationPathPattern extends Pattern { 38 private Template _template; 39 private int _importPrecedence; 40 private double _priority = Double.NaN; 41 private int _position = 0; 42 43 public Type typeCheck(SymbolTable stable) throws TypeCheckError { 44 return Type.Void; // TODO 45 } 46 47 public void translate(ClassGenerator classGen, MethodGenerator methodGen) { 48 // TODO: What does it mean to translate a Pattern ? 49 } 50 51 public void setTemplate(final Template template) { 52 _template = template; 53 _priority = template.getPriority(); 54 _importPrecedence = template.getImportPrecedence(); 55 _position = template.getPosition(); 56 } 57 58 public Template getTemplate() { 59 return _template; 60 } 61 62 public final double getPriority() { 63 return Double.isNaN(_priority) ? getDefaultPriority() : _priority; 64 } 65 66 public double getDefaultPriority() { 67 return 0.5; 68 } 69 70 /** 71 * This method is used by the Mode class to prioritise patterns and 72 * template. This method is called for templates that are in the same 73 * mode and that match on the same core pattern. The rules used are: 74 * o) first check precedence - highest precedence wins 75 * o) then check priority - highest priority wins 76 * o) then check the position - the template that occured last wins 77 */ 78 public boolean noSmallerThan(LocationPathPattern other) { 79 if (_importPrecedence > other._importPrecedence) { 80 return true; 81 } 82 else if (_importPrecedence == other._importPrecedence) { 83 if (_priority > other._priority) { 84 return true; 85 } 86 else if (_priority == other._priority) { 87 if (_position > other._position) { 88 return true; 89 } 90 } 91 } 92 return false; 93 } 94 95 public abstract StepPattern getKernelPattern(); 96 97 public abstract void reduceKernelPattern(); 98 99 public abstract boolean isWildcard(); 100 101 public int getAxis() { 102 final StepPattern sp = getKernelPattern(); 103 return (sp != null) ? sp.getAxis() : Axis.CHILD; 104 } 105 106 public String toString() { 107 return "root()"; 108 } 109 }