Fields Summary |
---|
static final long | serialVersionUID |
private static String | ABSTRACT_TRANSLETName of the superclass of all translets. This is needed to
determine which, among all classes comprising a translet,
is the main one. |
private String | _nameName of the main class or default name if unknown. |
private byte[] | _bytecodesContains the actual class definition for the translet class and
any auxiliary classes. |
private Class[] | _classContains the translet class definition(s). These are created when
this Templates is created or when it is read back from disk. |
private int | _transletIndexThe index of the main translet class in the arrays _class[] and
_bytecodes. |
private com.sun.org.apache.xalan.internal.xsltc.runtime.Hashtable | _auxClassesContains the list of auxiliary class definitions. |
private Properties | _outputPropertiesOutput properties of this translet. |
private int | _indentNumberNumber of spaces to add for output indentation. |
private transient URIResolver | _uriResolverThis URIResolver is passed to all Transformers.
Declaring it transient to fix bug 22438 |
private transient ThreadLocal | _sdomCache the DTM for the stylesheet in a thread local variable,
which is used by the document('') function.
Use ThreadLocal because a DTM cannot be shared between
multiple threads.
Declaring it transient to fix bug 22438 |
private transient TransformerFactoryImpl | _tfactoryA reference to the transformer factory that this templates
object belongs to. |
Constructors Summary |
---|
protected TemplatesImpl(byte[] bytecodes, String transletName, Properties outputProperties, int indentNumber, TransformerFactoryImpl tfactory)Create an XSLTC template object from the bytecodes.
The bytecodes for the translet and auxiliary classes, plus the name of
the main translet class, must be supplied.
_bytecodes = bytecodes;
_name = transletName;
_outputProperties = outputProperties;
_indentNumber = indentNumber;
_tfactory = tfactory;
|
protected TemplatesImpl(Class[] transletClasses, String transletName, Properties outputProperties, int indentNumber, TransformerFactoryImpl tfactory)Create an XSLTC template object from the translet class definition(s).
_class = transletClasses;
_name = transletName;
_transletIndex = 0;
_outputProperties = outputProperties;
_indentNumber = indentNumber;
_tfactory = tfactory;
|
public TemplatesImpl()Need for de-serialization, see readObject().
|
Methods Summary |
---|
private void | defineTransletClasses()Defines the translet class and auxiliary classes.
Returns a reference to the Class object that defines the main class
if (_bytecodes == null) {
ErrorMsg err = new ErrorMsg(ErrorMsg.NO_TRANSLET_CLASS_ERR);
throw new TransformerConfigurationException(err.toString());
}
TransletClassLoader loader = (TransletClassLoader)
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
return new TransletClassLoader(ObjectFactory.findClassLoader());
}
});
try {
final int classCount = _bytecodes.length;
_class = new Class[classCount];
if (classCount > 1) {
_auxClasses = new Hashtable();
}
for (int i = 0; i < classCount; i++) {
_class[i] = loader.defineClass(_bytecodes[i]);
final Class superClass = _class[i].getSuperclass();
// Check if this is the main class
if (superClass.getName().equals(ABSTRACT_TRANSLET)) {
_transletIndex = i;
}
else {
_auxClasses.put(_class[i].getName(), _class[i]);
}
}
if (_transletIndex < 0) {
ErrorMsg err= new ErrorMsg(ErrorMsg.NO_MAIN_TRANSLET_ERR, _name);
throw new TransformerConfigurationException(err.toString());
}
}
catch (ClassFormatError e) {
ErrorMsg err = new ErrorMsg(ErrorMsg.TRANSLET_CLASS_ERR, _name);
throw new TransformerConfigurationException(err.toString());
}
catch (LinkageError e) {
ErrorMsg err = new ErrorMsg(ErrorMsg.TRANSLET_OBJECT_ERR, _name);
throw new TransformerConfigurationException(err.toString());
}
|
public synchronized java.util.Properties | 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.
try {
return newTransformer().getOutputProperties();
}
catch (TransformerConfigurationException e) {
return null;
}
|
public com.sun.org.apache.xalan.internal.xsltc.DOM | getStylesheetDOM()Return the thread local copy of the stylesheet DOM.
return (DOM)_sdom.get();
|
private synchronized byte[][] | getTransletBytecodes()Returns the translet bytecodes stored in this template
Note: This method is private for security reasons. See
CR 6537898. When merging with Apache, we must ensure
that the privateness of this method is maintained (that
is why it wasn't removed).
return _bytecodes;
|
private synchronized java.lang.Class[] | getTransletClasses()Returns the translet bytecodes stored in this template
Note: This method is private for security reasons. See
CR 6537898. When merging with Apache, we must ensure
that the privateness of this method is maintained (that
is why it wasn't removed).
try {
if (_class == null) defineTransletClasses();
}
catch (TransformerConfigurationException e) {
// Falls through
}
return _class;
|
public synchronized int | getTransletIndex()Returns the index of the main class in array of bytecodes
try {
if (_class == null) defineTransletClasses();
}
catch (TransformerConfigurationException e) {
// Falls through
}
return _transletIndex;
|
private com.sun.org.apache.xalan.internal.xsltc.Translet | getTransletInstance()This method generates an instance of the translet class that is
wrapped inside this Template. The translet instance will later
be wrapped inside a Transformer object.
try {
if (_name == null) return null;
if (_class == null) defineTransletClasses();
// The translet needs to keep a reference to all its auxiliary
// class to prevent the GC from collecting them
AbstractTranslet translet = (AbstractTranslet) _class[_transletIndex].newInstance();
translet.postInitialization();
translet.setTemplates(this);
if (_auxClasses != null) {
translet.setAuxiliaryClasses(_auxClasses);
}
return translet;
}
catch (InstantiationException e) {
ErrorMsg err = new ErrorMsg(ErrorMsg.TRANSLET_OBJECT_ERR, _name);
throw new TransformerConfigurationException(err.toString());
}
catch (IllegalAccessException e) {
ErrorMsg err = new ErrorMsg(ErrorMsg.TRANSLET_OBJECT_ERR, _name);
throw new TransformerConfigurationException(err.toString());
}
|
protected synchronized java.lang.String | getTransletName()Returns the name of the main translet class stored in this template
return _name;
|
public synchronized javax.xml.transform.Transformer | newTransformer()Implements JAXP's Templates.newTransformer()
TransformerImpl transformer;
transformer = new TransformerImpl(getTransletInstance(), _outputProperties,
_indentNumber, _tfactory);
if (_uriResolver != null) {
transformer.setURIResolver(_uriResolver);
}
if (_tfactory.getFeature(XMLConstants.FEATURE_SECURE_PROCESSING)) {
transformer.setSecureProcessing(true);
}
return transformer;
|
private void | readObject(java.io.ObjectInputStream is)Overrides the default readObject implementation since we decided
it would be cleaner not to serialize the entire tranformer
factory. [ ref bugzilla 12317 ]
We need to check if the user defined class for URIResolver also
implemented Serializable
if yes then we need to deserialize the URIResolver
Fix for bugzilla bug 22438
is.defaultReadObject();
if (is.readBoolean()) {
_uriResolver = (URIResolver) is.readObject();
}
_tfactory = new TransformerFactoryImpl();
|
public void | setStylesheetDOM(com.sun.org.apache.xalan.internal.xsltc.DOM sdom)Set the thread local copy of the stylesheet DOM.
_sdom.set(sdom);
|
private synchronized void | setTransletBytecodes(byte[][] bytecodes)The TransformerFactory must pass us the translet bytecodes using this
method before we can create any translet instances
Note: This method is private for security reasons. See
CR 6537898. When merging with Apache, we must ensure
that the privateness of this method is maintained (that
is why it wasn't removed).
_bytecodes = bytecodes;
|
protected synchronized void | setTransletName(java.lang.String name)The TransformerFactory should call this method to set the translet name
_name = name;
|
public synchronized void | setURIResolver(javax.xml.transform.URIResolver resolver)Store URIResolver needed for Transformers.
_uriResolver = resolver;
|
private void | writeObject(java.io.ObjectOutputStream os)This is to fix bugzilla bug 22438
If the user defined class implements URIResolver and Serializable
then we want it to get serialized
os.defaultWriteObject();
if (_uriResolver instanceof Serializable) {
os.writeBoolean(true);
os.writeObject((Serializable) _uriResolver);
}
else {
os.writeBoolean(false);
}
|