KickJava   Java API By Example, From Geeks To Geeks.

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


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
20 package com.sun.org.apache.xalan.internal.xsltc.compiler.util;
21
22 import com.sun.org.apache.bcel.internal.generic.ALOAD;
23 import com.sun.org.apache.bcel.internal.generic.ClassGen;
24 import com.sun.org.apache.bcel.internal.generic.Instruction;
25 import com.sun.org.apache.xalan.internal.xsltc.compiler.Constants;
26 import com.sun.org.apache.xalan.internal.xsltc.compiler.Parser;
27 import com.sun.org.apache.xalan.internal.xsltc.compiler.Stylesheet;
28
29 /**
30  * The class that implements any class that inherits from
31  * <tt>AbstractTranslet</tt>, i.e. any translet. Methods in this
32  * class may be of the following kinds:
33  *
34  * 1. Main method: applyTemplates, implemented by intances of
35  * <tt>MethodGenerator</tt>.
36  *
37  * 2. Named methods: for named templates, implemented by instances
38  * of <tt>NamedMethodGenerator</tt>.
39  *
40  * 3. Rt methods: for result tree fragments, implemented by
41  * instances of <tt>RtMethodGenerator</tt>.
42  * @author Jacek Ambroziak
43  * @author Santiago Pericas-Geertsen
44  */

45 public class ClassGenerator extends ClassGen {
46     protected static int TRANSLET_INDEX = 0;
47     protected static int INVALID_INDEX = -1;
48
49     private Stylesheet _stylesheet;
50     private final Parser _parser; // --> can be moved to XSLT
51
// a single instance cached here
52
private final Instruction _aloadTranslet;
53     private final String JavaDoc _domClass;
54     private final String JavaDoc _domClassSig;
55     private final String JavaDoc _applyTemplatesSig;
56
57     public ClassGenerator(String JavaDoc class_name, String JavaDoc super_class_name,
58               String JavaDoc file_name,
59               int access_flags, String JavaDoc[] interfaces,
60               Stylesheet stylesheet) {
61     super(class_name, super_class_name, file_name,
62           access_flags, interfaces);
63     _stylesheet = stylesheet;
64     _parser = stylesheet.getParser();
65     _aloadTranslet = new ALOAD(TRANSLET_INDEX);
66     
67     if (stylesheet.isMultiDocument()) {
68         _domClass = "com.sun.org.apache.xalan.internal.xsltc.dom.MultiDOM";
69         _domClassSig = "Lcom/sun/org/apache/xalan/internal/xsltc/dom/MultiDOM;";
70     }
71     else {
72         _domClass = "com.sun.org.apache.xalan.internal.xsltc.dom.DOMAdapter";
73         _domClassSig = "Lcom/sun/org/apache/xalan/internal/xsltc/dom/DOMAdapter;";
74     }
75     _applyTemplatesSig = "("
76         + Constants.DOM_INTF_SIG
77         + Constants.NODE_ITERATOR_SIG
78         + Constants.TRANSLET_OUTPUT_SIG
79         + ")V";
80     }
81
82     public final Parser getParser() {
83     return _parser;
84     }
85
86     public final Stylesheet getStylesheet() {
87     return _stylesheet;
88     }
89
90     /**
91      * Pretend this is the stylesheet class. Useful when compiling
92      * references to global variables inside a predicate.
93      */

94     public final String JavaDoc getClassName() {
95     return _stylesheet.getClassName();
96     }
97
98     public Instruction loadTranslet() {
99     return _aloadTranslet;
100     }
101
102     public final String JavaDoc getDOMClass() {
103     return _domClass;
104     }
105
106     public final String JavaDoc getDOMClassSig() {
107     return _domClassSig;
108     }
109
110     public final String JavaDoc getApplyTemplatesSig() {
111     return _applyTemplatesSig;
112     }
113
114     /**
115      * Returns <tt>true</tt> or <tt>false</tt> depending on whether
116      * this class inherits from <tt>AbstractTranslet</tt> or not.
117      */

118     public boolean isExternal() {
119     return false;
120     }
121 }
122
Popular Tags