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: ClassGenerator.java,v 1.7 2004/02/16 22:26:44 minchau Exp $
  18. */
  19. package com.sun.org.apache.xalan.internal.xsltc.compiler.util;
  20. import com.sun.org.apache.bcel.internal.generic.ALOAD;
  21. import com.sun.org.apache.bcel.internal.generic.ClassGen;
  22. import com.sun.org.apache.bcel.internal.generic.Instruction;
  23. import com.sun.org.apache.xalan.internal.xsltc.compiler.Constants;
  24. import com.sun.org.apache.xalan.internal.xsltc.compiler.Parser;
  25. import com.sun.org.apache.xalan.internal.xsltc.compiler.Stylesheet;
  26. /**
  27. * The class that implements any class that inherits from
  28. * <tt>AbstractTranslet</tt>, i.e. any translet. Methods in this
  29. * class may be of the following kinds:
  30. *
  31. * 1. Main method: applyTemplates, implemented by intances of
  32. * <tt>MethodGenerator</tt>.
  33. *
  34. * 2. Named methods: for named templates, implemented by instances
  35. * of <tt>NamedMethodGenerator</tt>.
  36. *
  37. * 3. Rt methods: for result tree fragments, implemented by
  38. * instances of <tt>RtMethodGenerator</tt>.
  39. * @author Jacek Ambroziak
  40. * @author Santiago Pericas-Geertsen
  41. */
  42. public class ClassGenerator extends ClassGen {
  43. protected static int TRANSLET_INDEX = 0;
  44. protected static int INVALID_INDEX = -1;
  45. private Stylesheet _stylesheet;
  46. private final Parser _parser; // --> can be moved to XSLT
  47. // a single instance cached here
  48. private final Instruction _aloadTranslet;
  49. private final String _domClass;
  50. private final String _domClassSig;
  51. private final String _applyTemplatesSig;
  52. public ClassGenerator(String class_name, String super_class_name,
  53. String file_name,
  54. int access_flags, String[] interfaces,
  55. Stylesheet stylesheet) {
  56. super(class_name, super_class_name, file_name,
  57. access_flags, interfaces);
  58. _stylesheet = stylesheet;
  59. _parser = stylesheet.getParser();
  60. _aloadTranslet = new ALOAD(TRANSLET_INDEX);
  61. if (stylesheet.isMultiDocument()) {
  62. _domClass = "com.sun.org.apache.xalan.internal.xsltc.dom.MultiDOM";
  63. _domClassSig = "Lcom/sun/org/apache/xalan/internal/xsltc/dom/MultiDOM;";
  64. }
  65. else {
  66. _domClass = "com.sun.org.apache.xalan.internal.xsltc.dom.DOMAdapter";
  67. _domClassSig = "Lcom/sun/org/apache/xalan/internal/xsltc/dom/DOMAdapter;";
  68. }
  69. _applyTemplatesSig = "("
  70. + Constants.DOM_INTF_SIG
  71. + Constants.NODE_ITERATOR_SIG
  72. + Constants.TRANSLET_OUTPUT_SIG
  73. + ")V";
  74. }
  75. public final Parser getParser() {
  76. return _parser;
  77. }
  78. public final Stylesheet getStylesheet() {
  79. return _stylesheet;
  80. }
  81. /**
  82. * Pretend this is the stylesheet class. Useful when compiling
  83. * references to global variables inside a predicate.
  84. */
  85. public final String getClassName() {
  86. return _stylesheet.getClassName();
  87. }
  88. public Instruction loadTranslet() {
  89. return _aloadTranslet;
  90. }
  91. public final String getDOMClass() {
  92. return _domClass;
  93. }
  94. public final String getDOMClassSig() {
  95. return _domClassSig;
  96. }
  97. public final String getApplyTemplatesSig() {
  98. return _applyTemplatesSig;
  99. }
  100. /**
  101. * Returns <tt>true</tt> or <tt>false</tt> depending on whether
  102. * this class inherits from <tt>AbstractTranslet</tt> or not.
  103. */
  104. public boolean isExternal() {
  105. return false;
  106. }
  107. }