cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael Hussey <MHus...@Saba.com>
Subject XSPClassLoader: Caching problem in Cocoon 1.8 once page is succes sfully compiled.
Date Thu, 02 Nov 2000 21:19:08 GMT
We have found that our compiled pages are not updated even after the source
is updated.  A bug associated with this is in the XSPClassLoader.  The
findLoadedClass is finding it in memory so it never reloads the compiled
byte stream.  The following rewrite of loadClass() will fix the problem:

package org.apache.cocoon.processor.xsp.language.java;

import java.io.*;
import java.util.*; //SABA add

/**
 * @author <a href="mailto:ricardo@apache.org">Ricardo Rocha</a>
 * @version $Revision: 1.5 $ $Date: 2000/02/13 18:29:37 $
 */
public class XSPClassLoader extends ClassLoader {

    protected  Hashtable classCache = new Hashtable(); //SABA add

    protected File repository;

    public XSPClassLoader (File repository) {
        this.repository = repository;
    }

    public XSPClassLoader reinstantiate() {
        return new XSPClassLoader(this.repository);
    }

    protected Class loadClass (String name, boolean resolve)
    throws ClassNotFoundException
    {
        // SABA added caching and tries to loadClassData before
findLoadedClass and findSystemClass

        Class c = (Class) classCache.get(name);

        if (c==null) {
            
            byte[] bits = loadClassData(name);
            if (bits == null) {
                ClassLoader cl = this.getClass().getClassLoader();
                if (cl != null) {
                    c = cl.loadClass(name);
                }
            } else {
                c = defineClass (null, bits, 0, bits.length);
            }
            if (c!=null) {
                classCache.put(name,c);  //cache unresolved class

            }

        } // if wasn't in cache

        if (resolve) {
            resolveClass (c);
        }


/*     Class c = findLoadedClass(name);                         */
/*                                                              */
/*     if (c == null) {                                         */
/*       try {                                                  */
/*         c = findSystemClass(name);                           */
/*       } catch (ClassNotFoundException e) {                   */
/*         byte[] bits = loadClassData (name);                  */
/*                                                              */
/*         if (bits == null) {                                  */
/*           // ClassLoader cl = getParent();                   */
/*           ClassLoader cl = this.getClass().getClassLoader(); */
/*                                                              */
/*           if (cl != null)  {                                 */
/*             c = cl.loadClass (name);                         */
/*           }                                                  */
/*         } else {                                             */
/*           c = defineClass (null, bits, 0, bits.length);      */
/*                                                              */
/*           if (resolve) {                                     */
/*             resolveClass (c);                                */
/*           }                                                  */
/*         }                                                    */
/*       }                                                      */
/*                                                              */
/*       if (c == null) {                                       */
/*         throw new ClassNotFoundException (name);             */
/*       }                                                      */
/*     }                                                        */
/*                                                              */
        return c;
    }


Regards,
Michael


Mime
View raw message