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. package com.sun.org.apache.xalan.internal.xsltc.compiler;
  20. import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator;
  21. import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator;
  22. import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type;
  23. import com.sun.org.apache.xalan.internal.xsltc.compiler.util.TypeCheckError;
  24. import com.sun.org.apache.xalan.internal.xsltc.dom.Axis;
  25. /**
  26. * @author Jacek Ambroziak
  27. * @author Santiago Pericas-Geertsen
  28. * @author Morten Jorgensen
  29. */
  30. public abstract class LocationPathPattern extends Pattern {
  31. private Template _template;
  32. private int _importPrecedence;
  33. private double _priority = Double.NaN;
  34. private int _position = 0;
  35. public Type typeCheck(SymbolTable stable) throws TypeCheckError {
  36. return Type.Void; // TODO
  37. }
  38. public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
  39. // TODO: What does it mean to translate a Pattern ?
  40. }
  41. public void setTemplate(final Template template) {
  42. _template = template;
  43. _priority = template.getPriority();
  44. _importPrecedence = template.getImportPrecedence();
  45. _position = template.getPosition();
  46. }
  47. public Template getTemplate() {
  48. return _template;
  49. }
  50. public final double getPriority() {
  51. return Double.isNaN(_priority) ? getDefaultPriority() : _priority;
  52. }
  53. public double getDefaultPriority() {
  54. return 0.5;
  55. }
  56. /**
  57. * This method is used by the Mode class to prioritise patterns and
  58. * template. This method is called for templates that are in the same
  59. * mode and that match on the same core pattern. The rules used are:
  60. * o) first check precedence - highest precedence wins
  61. * o) then check priority - highest priority wins
  62. * o) then check the position - the template that occured last wins
  63. */
  64. public boolean noSmallerThan(LocationPathPattern other) {
  65. if (_importPrecedence > other._importPrecedence) {
  66. return true;
  67. }
  68. else if (_importPrecedence == other._importPrecedence) {
  69. if (_priority > other._priority) {
  70. return true;
  71. }
  72. else if (_priority == other._priority) {
  73. if (_position > other._position) {
  74. return true;
  75. }
  76. }
  77. }
  78. return false;
  79. }
  80. public abstract StepPattern getKernelPattern();
  81. public abstract void reduceKernelPattern();
  82. public abstract boolean isWildcard();
  83. public int getAxis() {
  84. final StepPattern sp = getKernelPattern();
  85. return (sp != null) ? sp.getAxis() : Axis.CHILD;
  86. }
  87. public String toString() {
  88. return "root()";
  89. }
  90. }