You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by mo...@apache.org on 2001/10/02 13:16:52 UTC

cvs commit: xml-xalan/java/src/org/apache/xalan/xsltc/trax TemplatesImpl.java TransformerFactoryImpl.java TransformerImpl.java

morten      01/10/02 04:16:52

  Modified:    java/src/org/apache/xalan/xsltc/trax TemplatesImpl.java
                        TransformerFactoryImpl.java TransformerImpl.java
  Log:
  Fix to ensure that plain filenames can be passed in to the Transformer
  and TransformerFactory. Up until now only URLs were accepted by the
  TransformerFactory.
  PR:		n/a
  Obtained from:	n/a
  Submitted by:	morten@xml.apache.org
  Reviewed by:	morten@xml.apache.org
  
  Revision  Changes    Path
  1.7       +52 -35    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.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- TemplatesImpl.java	2001/09/28 14:39:14	1.6
  +++ TemplatesImpl.java	2001/10/02 11:16:52	1.7
  @@ -1,5 +1,5 @@
   /*
  - * @(#)$Id: TemplatesImpl.java,v 1.6 2001/09/28 14:39:14 morten Exp $
  + * @(#)$Id: TemplatesImpl.java,v 1.7 2001/10/02 11:16:52 morten Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -64,6 +64,9 @@
   package org.apache.xalan.xsltc.trax;
   
   import java.io.Serializable;
  +import java.io.ObjectInput;
  +import java.io.ObjectOutput;
  +import java.io.IOException;
   import java.util.Properties;
   import java.security.AccessController;
   import java.security.PrivilegedAction;
  @@ -84,6 +87,10 @@
       // any auxiliary classes (representing node sort records, predicates, etc.)
       private byte[][] _bytecodes = null;
   
  +    private Class[]    _class = null;
  +
  +    private int _transletIndex = -1;
  +
       // This error could occur when a compilation inside the TransformerFactory
       // failed and when a template has been loaded from stable storage.
       private final static String NO_TRANSLET_CODE =
  @@ -102,6 +109,20 @@
   	}
       }
   
  +    public void writeExternal(ObjectOutput out) throws IOException {
  +	out.writeObject(_transletName);
  +	out.writeObject(_bytecodes);
  +	out.flush();
  +    }
  +
  +    public void readExternal(ObjectInput in)
  +	throws IOException, ClassNotFoundException {
  +	_transletName = (String)in.readObject();
  +	_bytecodes    = (byte[][])in.readObject();
  +	_class        = null;
  +    }
  +
  +
       /**
        * The only way to create an XSLTC emplate object
        * The bytecodes for the translet and auxiliary classes, plus the name of
  @@ -145,7 +166,7 @@
        * Defines the translet class and auxiliary classes.
        * Returns a reference to the Class object that defines the main class
        */
  -    private Translet defineTransletClasses()
  +    private void defineTransletClasses()
   	throws TransformerConfigurationException {
   
   	if (_bytecodes == null)
  @@ -161,25 +182,18 @@
   		);
   
   	try {
  -	    int transletIndex = -1;
   	    final int classCount = _bytecodes.length;
  -	    Class[] clazz = new Class[classCount];
  +	    _class = new Class[classCount];
   
   	    for (int i = 0; i < classCount; i++) {
  -		clazz[i] = loader.defineClass(_bytecodes[i]);
  -		if (clazz[i].getName().equals(_transletName)) transletIndex = i;
  +		_class[i] = loader.defineClass(_bytecodes[i]);
  +		if (_class[i].getName().equals(_transletName))
  +		    _transletIndex = i;
   	    }
   
  -	    if (transletIndex < 0)
  +	    if (_transletIndex < 0)
   		throw new TransformerConfigurationException(NO_MAIN_TRANSLET+
   							    _transletName);
  -
  -	    Translet translet = (Translet)clazz[transletIndex].newInstance();
  -	    for (int i = 0; i < classCount; i++) {
  -		if (i != transletIndex)
  -		    translet.addAuxiliaryClass(clazz[i]);
  -	    }
  -	    return translet;
   	}
   
   	catch (ClassFormatError e)       {
  @@ -190,14 +204,6 @@
   	    throw new TransformerConfigurationException(TRANSLET_OBJECT_ERR+
   							_transletName);
   	}
  -	catch (InstantiationException e) {
  -	    throw new TransformerConfigurationException(TRANSLET_OBJECT_ERR+
  -							_transletName);
  -	}
  -	catch (IllegalAccessException e) {
  -	    throw new TransformerConfigurationException(TRANSLET_OBJECT_ERR+
  -							_transletName);
  -	}
       }
   
       /**
  @@ -207,21 +213,32 @@
        */
       private Translet getTransletInstance()
   	throws TransformerConfigurationException {
  -	if (_transletName == null) return null;
  -
  -	// First assume that the JVM already had the class definition
   	try {
  -	    Class transletClass = Class.forName(_transletName);
  -	    return((Translet)transletClass.newInstance());
  -	}
  -	// Ignore these for now, try to define translet class again
  -	catch (LinkageError e) { }
  -	catch (InstantiationException e) { }
  -	catch (ClassNotFoundException e) { }
  -	catch (IllegalAccessException e) { }
  +	    if (_transletName == null) return null;
   
  -	// Create the class definition from the bytecodes if failed
  -	return((Translet)defineTransletClasses());
  +	    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();
  +	    final int classCount = _bytecodes.length;
  +	    for (int i = 0; i < classCount; i++) {
  +		if (i != _transletIndex)
  +		    translet.addAuxiliaryClass(_class[i]);
  +	    }
  +	    return translet;
  +	}
  +	catch (InstantiationException e) {
  +	    throw new TransformerConfigurationException(TRANSLET_OBJECT_ERR+
  +							_transletName);
  +	}
  +	catch (IllegalAccessException e) {
  +	    throw new TransformerConfigurationException(TRANSLET_OBJECT_ERR+
  +							_transletName);
  +	}
       }
   
       /**
  
  
  
  1.19      +7 -8      xml-xalan/java/src/org/apache/xalan/xsltc/trax/TransformerFactoryImpl.java
  
  Index: TransformerFactoryImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/trax/TransformerFactoryImpl.java,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- TransformerFactoryImpl.java	2001/08/02 16:01:51	1.18
  +++ TransformerFactoryImpl.java	2001/10/02 11:16:52	1.19
  @@ -1,5 +1,5 @@
   /*
  - * @(#)$Id: TransformerFactoryImpl.java,v 1.18 2001/08/02 16:01:51 morten Exp $
  + * @(#)$Id: TransformerFactoryImpl.java,v 1.19 2001/10/02 11:16:52 morten Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -393,7 +393,7 @@
   	throws TransformerConfigurationException {
   
   	InputSource input = null;
  -	final String systemId = source.getSystemId();
  +	String systemId = source.getSystemId();
   
   	try {
   
  @@ -427,13 +427,12 @@
   	    else {
   		throw new TransformerConfigurationException(UNKNOWN_SOURCE_ERR);
   	    }
  +
  +	    if ((new File(systemId)).exists())
  +		systemId = "file:"+systemId;
  +
   	    // Try to create an InputStream from the SystemId if no input so far
  -	    if (input == null) {
  -		if ((new File(systemId)).exists())
  -		    input = new InputSource("file:/"+systemId);
  -		else
  -		    input = new InputSource(systemId);
  -	    }
  +	    if (input == null) input = new InputSource(systemId);
   
   	    // Pass system id to InputSource just to be on the safe side
   	    input.setSystemId(systemId);
  
  
  
  1.16      +2 -2      xml-xalan/java/src/org/apache/xalan/xsltc/trax/TransformerImpl.java
  
  Index: TransformerImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/trax/TransformerImpl.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- TransformerImpl.java	2001/09/28 14:39:14	1.15
  +++ TransformerImpl.java	2001/10/02 11:16:52	1.16
  @@ -1,5 +1,5 @@
   /*
  - * @(#)$Id: TransformerImpl.java,v 1.15 2001/09/28 14:39:14 morten Exp $
  + * @(#)$Id: TransformerImpl.java,v 1.16 2001/10/02 11:16:52 morten Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -230,7 +230,7 @@
   	    // other contents of the Result object could not be used
   	    if (systemId != null) {
   		if ((new File(systemId)).exists())
  -		    systemId = "file:/"+systemId;
  +		    systemId = "file:"+systemId;
   		final URL url = new URL(systemId);
   		final URLConnection connection = url.openConnection();
   		final OutputStream ostream = connection.getOutputStream();
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-cvs-help@xml.apache.org