KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > org > apache > xalan > internal > xsltc > compiler > UnsupportedElement


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
20 package com.sun.org.apache.xalan.internal.xsltc.compiler;
21
22 import java.util.Vector JavaDoc;
23
24 import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen;
25 import com.sun.org.apache.bcel.internal.generic.INVOKESTATIC;
26 import com.sun.org.apache.bcel.internal.generic.InstructionList;
27 import com.sun.org.apache.bcel.internal.generic.PUSH;
28
29 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator;
30 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMsg;
31 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator;
32 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type;
33 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.TypeCheckError;
34 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Util;
35
36 /**
37  * @author Morten Jorgensen
38  */

39 final class UnsupportedElement extends SyntaxTreeNode {
40
41     private Vector JavaDoc _fallbacks = null;
42     private ErrorMsg _message = null;
43     private boolean _isExtension = false;
44
45     /**
46      * Basic consutrcor - stores element uri/prefix/localname
47      */

48     public UnsupportedElement(String JavaDoc uri, String JavaDoc prefix, String JavaDoc local, boolean isExtension) {
49     super(uri, prefix, local);
50     _isExtension = isExtension;
51     }
52
53     /**
54      * There are different categories of unsupported elements (believe it
55      * or not): there are elements within the XSLT namespace (these would
56      * be elements that are not yet implemented), there are extensions of
57      * other XSLT processors and there are unrecognised extension elements
58      * of this XSLT processor. The error message passed to this method
59      * should describe the unsupported element itself and what category
60      * the element belongs in.
61      */

62     public void setErrorMessage(ErrorMsg message) {
63     _message = message;
64     }
65
66     /**
67      * Displays the contents of this element
68      */

69     public void display(int indent) {
70     indent(indent);
71     Util.println("Unsupported element = " + _qname.getNamespace() +
72              ":" + _qname.getLocalPart());
73     displayContents(indent + IndentIncrement);
74     }
75
76
77     /**
78      * Scan and process all fallback children of the unsupported element.
79      */

80     private void processFallbacks(Parser parser) {
81
82     Vector JavaDoc children = getContents();
83     if (children != null) {
84         final int count = children.size();
85         for (int i = 0; i < count; i++) {
86         SyntaxTreeNode child = (SyntaxTreeNode)children.elementAt(i);
87         if (child instanceof Fallback) {
88             Fallback fallback = (Fallback)child;
89             fallback.activate();
90             fallback.parseContents(parser);
91             if (_fallbacks == null) {
92                 _fallbacks = new Vector JavaDoc();
93             }
94             _fallbacks.addElement(child);
95         }
96         }
97     }
98     }
99
100     /**
101      * Find any fallback in the descendant nodes; then activate & parse it
102      */

103     public void parseContents(Parser parser) {
104         processFallbacks(parser);
105     }
106
107     /**
108      * Run type check on the fallback element (if any).
109      */

110     public Type typeCheck(SymbolTable stable) throws TypeCheckError {
111     if (_fallbacks != null) {
112         int count = _fallbacks.size();
113         for (int i = 0; i < count; i++) {
114             Fallback fallback = (Fallback)_fallbacks.elementAt(i);
115             fallback.typeCheck(stable);
116         }
117     }
118     return Type.Void;
119     }
120
121     /**
122      * Translate the fallback element (if any).
123      */

124     public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
125     if (_fallbacks != null) {
126         int count = _fallbacks.size();
127         for (int i = 0; i < count; i++) {
128             Fallback fallback = (Fallback)_fallbacks.elementAt(i);
129             fallback.translate(classGen, methodGen);
130         }
131     }
132     // We only go into the else block in forward-compatibility mode, when
133
// the unsupported element has no fallback.
134
else {
135         // If the unsupported element does not have any fallback child, then
136
// at runtime, a runtime error should be raised when the unsupported
137
// element is instantiated. Otherwise, no error is thrown.
138
ConstantPoolGen cpg = classGen.getConstantPool();
139         InstructionList il = methodGen.getInstructionList();
140         
141         final int unsupportedElem = cpg.addMethodref(BASIS_LIBRARY_CLASS, "unsupported_ElementF",
142                                                          "(" + STRING_SIG + "Z)V");
143         il.append(new PUSH(cpg, getQName().toString()));
144         il.append(new PUSH(cpg, _isExtension));
145         il.append(new INVOKESTATIC(unsupportedElem));
146     }
147     }
148 }
149
Popular Tags