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: UnsupportedElement.java,v 1.8 2004/02/16 22:25:10 minchau Exp $
  18. */
  19. package com.sun.org.apache.xalan.internal.xsltc.compiler;
  20. import java.util.Vector;
  21. import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen;
  22. import com.sun.org.apache.bcel.internal.generic.INVOKESTATIC;
  23. import com.sun.org.apache.bcel.internal.generic.InstructionList;
  24. import com.sun.org.apache.bcel.internal.generic.PUSH;
  25. import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator;
  26. import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMsg;
  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.xalan.internal.xsltc.compiler.util.Util;
  31. /**
  32. * @author Morten Jorgensen
  33. */
  34. final class UnsupportedElement extends SyntaxTreeNode {
  35. private Vector _fallbacks = null;
  36. private ErrorMsg _message = null;
  37. private boolean _isExtension = false;
  38. /**
  39. * Basic consutrcor - stores element uri/prefix/localname
  40. */
  41. public UnsupportedElement(String uri, String prefix, String local, boolean isExtension) {
  42. super(uri, prefix, local);
  43. _isExtension = isExtension;
  44. }
  45. /**
  46. * There are different categories of unsupported elements (believe it
  47. * or not): there are elements within the XSLT namespace (these would
  48. * be elements that are not yet implemented), there are extensions of
  49. * other XSLT processors and there are unrecognised extension elements
  50. * of this XSLT processor. The error message passed to this method
  51. * should describe the unsupported element itself and what category
  52. * the element belongs in.
  53. */
  54. public void setErrorMessage(ErrorMsg message) {
  55. _message = message;
  56. }
  57. /**
  58. * Displays the contents of this element
  59. */
  60. public void display(int indent) {
  61. indent(indent);
  62. Util.println("Unsupported element = " + _qname.getNamespace() +
  63. ":" + _qname.getLocalPart());
  64. displayContents(indent + IndentIncrement);
  65. }
  66. /**
  67. * Scan and process all fallback children of the unsupported element.
  68. */
  69. private void processFallbacks(Parser parser) {
  70. Vector children = getContents();
  71. if (children != null) {
  72. final int count = children.size();
  73. for (int i = 0; i < count; i++) {
  74. SyntaxTreeNode child = (SyntaxTreeNode)children.elementAt(i);
  75. if (child instanceof Fallback) {
  76. Fallback fallback = (Fallback)child;
  77. fallback.activate();
  78. fallback.parseContents(parser);
  79. if (_fallbacks == null) {
  80. _fallbacks = new Vector();
  81. }
  82. _fallbacks.addElement(child);
  83. }
  84. }
  85. }
  86. }
  87. /**
  88. * Find any fallback in the descendant nodes; then activate & parse it
  89. */
  90. public void parseContents(Parser parser) {
  91. processFallbacks(parser);
  92. }
  93. /**
  94. * Run type check on the fallback element (if any).
  95. */
  96. public Type typeCheck(SymbolTable stable) throws TypeCheckError {
  97. if (_fallbacks != null) {
  98. int count = _fallbacks.size();
  99. for (int i = 0; i < count; i++) {
  100. Fallback fallback = (Fallback)_fallbacks.elementAt(i);
  101. fallback.typeCheck(stable);
  102. }
  103. }
  104. return Type.Void;
  105. }
  106. /**
  107. * Translate the fallback element (if any).
  108. */
  109. public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
  110. if (_fallbacks != null) {
  111. int count = _fallbacks.size();
  112. for (int i = 0; i < count; i++) {
  113. Fallback fallback = (Fallback)_fallbacks.elementAt(i);
  114. fallback.translate(classGen, methodGen);
  115. }
  116. }
  117. // We only go into the else block in forward-compatibility mode, when
  118. // the unsupported element has no fallback.
  119. else {
  120. // If the unsupported element does not have any fallback child, then
  121. // at runtime, a runtime error should be raised when the unsupported
  122. // element is instantiated. Otherwise, no error is thrown.
  123. ConstantPoolGen cpg = classGen.getConstantPool();
  124. InstructionList il = methodGen.getInstructionList();
  125. final int unsupportedElem = cpg.addMethodref(BASIS_LIBRARY_CLASS, "unsupported_ElementF",
  126. "(" + STRING_SIG + "Z)V");
  127. il.append(new PUSH(cpg, getQName().toString()));
  128. il.append(new PUSH(cpg, _isExtension));
  129. il.append(new INVOKESTATIC(unsupportedElem));
  130. }
  131. }
  132. }