001 /* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the "License"); 007 * you may not use this file except in compliance with the License. 008 * You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018 /* 019 * $Id: LocationPathPattern.java 468650 2006-10-28 07:03:30Z minchau $ 020 */ 021 022 package org.apache.xalan.xsltc.compiler; 023 024 import org.apache.xalan.xsltc.compiler.util.ClassGenerator; 025 import org.apache.xalan.xsltc.compiler.util.MethodGenerator; 026 import org.apache.xalan.xsltc.compiler.util.Type; 027 import org.apache.xalan.xsltc.compiler.util.TypeCheckError; 028 import org.apache.xml.dtm.Axis; 029 030 /** 031 * @author Jacek Ambroziak 032 * @author Santiago Pericas-Geertsen 033 * @author Morten Jorgensen 034 */ 035 public abstract class LocationPathPattern extends Pattern { 036 private Template _template; 037 private int _importPrecedence; 038 private double _priority = Double.NaN; 039 private int _position = 0; 040 041 public Type typeCheck(SymbolTable stable) throws TypeCheckError { 042 return Type.Void; // TODO 043 } 044 045 public void translate(ClassGenerator classGen, MethodGenerator methodGen) { 046 // TODO: What does it mean to translate a Pattern ? 047 } 048 049 public void setTemplate(final Template template) { 050 _template = template; 051 _priority = template.getPriority(); 052 _importPrecedence = template.getImportPrecedence(); 053 _position = template.getPosition(); 054 } 055 056 public Template getTemplate() { 057 return _template; 058 } 059 060 public final double getPriority() { 061 return Double.isNaN(_priority) ? getDefaultPriority() : _priority; 062 } 063 064 public double getDefaultPriority() { 065 return 0.5; 066 } 067 068 /** 069 * This method is used by the Mode class to prioritise patterns and 070 * template. This method is called for templates that are in the same 071 * mode and that match on the same core pattern. The rules used are: 072 * o) first check precedence - highest precedence wins 073 * o) then check priority - highest priority wins 074 * o) then check the position - the template that occured last wins 075 */ 076 public boolean noSmallerThan(LocationPathPattern other) { 077 if (_importPrecedence > other._importPrecedence) { 078 return true; 079 } 080 else if (_importPrecedence == other._importPrecedence) { 081 if (_priority > other._priority) { 082 return true; 083 } 084 else if (_priority == other._priority) { 085 if (_position > other._position) { 086 return true; 087 } 088 } 089 } 090 return false; 091 } 092 093 public abstract StepPattern getKernelPattern(); 094 095 public abstract void reduceKernelPattern(); 096 097 public abstract boolean isWildcard(); 098 099 public int getAxis() { 100 final StepPattern sp = getKernelPattern(); 101 return (sp != null) ? sp.getAxis() : Axis.CHILD; 102 } 103 104 public String toString() { 105 return "root()"; 106 } 107 }