santiagopg 2002/07/22 08:45:07
Modified: java/src/org/apache/xalan/xsltc/trax TemplatesImpl.java
Log:
Use the superclass to determine the main class of a translet.
Revision Changes Path
1.18 +46 -23
xml-xalan/java/src/org/apache/xalan/xsltc/trax/TemplatesImpl.java
Index: TemplatesImpl.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/trax/TemplatesImpl.java,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- TemplatesImpl.java 21 Jul 2002 22:28:01 -0000 1.17
+++ TemplatesImpl.java 22 Jul 2002 15:45:06 -0000 1.18
@@ -82,23 +82,45 @@
public final class TemplatesImpl implements Templates, Serializable {
- // Contains the name of the main translet class
- private String _name = null;
+ /**
+ * Name of the superclass of all translets. This is needed to
+ * determine which, among all classes comprising a translet,
+ * is the main one.
+ */
+ private static String ABSTRACT_TRANSLET
+ = "org.apache.xalan.xsltc.runtime.AbstractTranslet";
+
+ /**
+ * Name of the main class or default name if unknown.
+ */
+ private String _name = null;
- // Contains the actual class definition for the translet class and
- // any auxiliary classes (representing node sort records, predicates,
etc.)
+ /**
+ * Contains the actual class definition for the translet class and
+ * any auxiliary classes.
+ */
private byte[][] _bytecodes = null;
- // Contains the translet class definition(s). These are created when this
- // Templates is first instanciated or read back from disk (see
readObject())
- private Class[] _class = null;
+ /**
+ * Contains the translet class definition(s). These are created when
+ * this Templates is created or when it is read back from disk.
+ */
+ private Class[] _class = null;
- // This tells us which index the main translet class has in the _class
- // and _bytecodes arrays (above).
+ /**
+ * The index of the main translet class in the arrays _class[] and
+ * _bytecodes.
+ */
private int _transletIndex = -1;
+ /**
+ * Output properties of this translet.
+ */
private Properties _outputProperties;
+ /**
+ * Number of spaces to add for output indentation.
+ */
private int _indentNumber;
// Temporary
@@ -233,8 +255,12 @@
for (int i = 0; i < classCount; i++) {
_class[i] = loader.defineClass(_bytecodes[i]);
- if (_class[i].getName().equals(_name))
+ final Class superClass = _class[i].getSuperclass();
+
+ // Check if this is the main class
+ if (superClass.getName().equals(ABSTRACT_TRANSLET)) {
_transletIndex = i;
+ }
}
if (_transletIndex < 0) {
@@ -242,7 +268,6 @@
throw new TransformerConfigurationException(err.toString());
}
}
-
catch (ClassFormatError e) {
ErrorMsg err = new ErrorMsg(ErrorMsg.TRANSLET_CLASS_ERR, _name);
throw new TransformerConfigurationException(err.toString());
@@ -265,16 +290,14 @@
if (_class == null) defineTransletClasses();
- // The translet needs a reference to all its auxiliary class
- // definitions so that it can instanciate them on the fly. You
- // wouldn't think this is necessary, but it seems like the JVM
- // quickly forgets the classes we define here and the translet
- // needs to know them as long as it exists.
- Translet translet = (Translet)_class[_transletIndex].newInstance();
+ // The translet needs to keep a reference to all its auxiliary
+ // class to prevent the GC from collecting them
+ Translet translet = (Translet) _class[_transletIndex].newInstance();
final int classCount = _bytecodes.length;
for (int i = 0; i < classCount; i++) {
- if (i != _transletIndex)
+ if (i != _transletIndex) {
translet.addAuxiliaryClass(_class[i]);
+ }
}
return translet;
}
@@ -300,12 +323,12 @@
}
/**
- * Implements JAXP's Templates.getOutputProperties()
+ * Implements JAXP's Templates.getOutputProperties(). We need to
+ * instanciate a translet to get the output settings, so
+ * we might as well just instanciate a Transformer and use its
+ * implementation of this method.
*/
public Properties getOutputProperties() {
- // We need to instanciate a translet to get the output settings, so
- // we might as well just instanciate a Transformer and use its
- // implementation of this method
try {
Transformer transformer = newTransformer();
return transformer.getOutputProperties();
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]