You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by vg...@apache.org on 2002/02/07 05:07:28 UTC

cvs commit: xml-cocoon2/src/java/org/apache/cocoon/components/language/programming/java JavaProgram.java JavaLanguage.java

vgritsenko    02/02/06 20:07:28

  Modified:    src/java/org/apache/cocoon/components/language/generator
                        GeneratorSelector.java ProgramGenerator.java
                        ProgramGeneratorImpl.java
               src/java/org/apache/cocoon/components/language/markup
                        AbstractMarkupLanguage.java
               src/java/org/apache/cocoon/components/language/programming
                        AbstractProgrammingLanguage.java
                        CompiledProgrammingLanguage.java
                        ProgrammingLanguage.java
               src/java/org/apache/cocoon/components/language/programming/java
                        JavaLanguage.java
  Added:       src/java/org/apache/cocoon/components/language/programming
                        Program.java
               src/java/org/apache/cocoon/components/language/programming/java
                        JavaProgram.java
  Log:
  Fix programming languages support:
   - Decouple ProgrammingLanguage from Class object, to allow interpreting languages.
   - Improve a little bit program reloading mechanism
  
  Revision  Changes    Path
  1.6       +40 -45    xml-cocoon2/src/java/org/apache/cocoon/components/language/generator/GeneratorSelector.java
  
  Index: GeneratorSelector.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/language/generator/GeneratorSelector.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- GeneratorSelector.java	4 Feb 2002 12:22:22 -0000	1.5
  +++ GeneratorSelector.java	7 Feb 2002 04:07:27 -0000	1.6
  @@ -67,17 +67,24 @@
   import org.apache.avalon.framework.context.Context;
   import org.apache.cocoon.Constants;
   import org.apache.cocoon.components.classloader.ClassLoaderManager;
  +import org.apache.cocoon.components.language.programming.Program;
   
   import java.io.File;
  -import java.util.*;
  +import java.util.HashMap;
  +import java.util.Map;
  +import java.util.ArrayList;
  +import java.util.List;
  +import java.util.Iterator;
   
   /**
    * This interface is the common base of all Compiled Components.  This
    * includes Sitemaps and XSP Pages
    *
    * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
  - * @version CVS $Id: GeneratorSelector.java,v 1.5 2002/02/04 12:22:22 cziegeler Exp $
  + * @author <a href="mailto:vgritsenko@apache.org">Vadim Gritsenko</a>
  + * @version CVS $Id: GeneratorSelector.java,v 1.6 2002/02/07 04:07:27 vgritsenko Exp $
    */
  +// FIXME: remove extends, add implements ComponentSelector
   public class GeneratorSelector extends ExcaliburComponentSelector implements Disposable {
   
       public static String ROLE = "org.apache.cocoon.components.language.generator.ServerPages";
  @@ -131,9 +138,10 @@
       }
   
       public Component select(Object hint) throws ComponentException {
  -        try {
  -            return super.select(hint);
  -        } catch (Exception e) {
  +//        try {
  +//            return super.select(hint);
  +//        } catch (Exception e) {
  +
               // if it isn't loaded, it may already be compiled...
               try {
                   ComponentHandler handler = (ComponentHandler) this.componentHandlers.get(hint);
  @@ -144,7 +152,7 @@
                   getLogger().debug("Could not access component for hint: " + hint);
                   throw new ComponentException("Could not access component for hint: " + hint, null);
               }
  -        }
  +//        }
       }
   
       public void release(Component component) {
  @@ -155,73 +163,60 @@
               } catch (Exception e) {
                   getLogger().error("Error trying to release component", e);
               }
  -        } else {
  -            super.release(component);
  +//        } else {
  +//            super.release(component);
           }
       }
   
  -    private void addGenerator(Object hint) throws Exception {
  -        Class generator;
  -        String className = hint.toString().replace(File.separatorChar, '.');
  -        generator = this.classManager.loadClass(className);
  -
  -        this.addGenerator(this.manager, hint, generator);
  -    }
  -
  -    protected void addGenerator(ComponentManager newManager, Object hint, Class generator) throws Exception {
  -        try
  -        {
  +    protected void addGenerator(ComponentManager newManager,
  +                                Object hint, Program generator)
  +            throws Exception {
  +        try {
               final ComponentHandler handler =
  -                ComponentHandler.getComponentHandler( generator,
  -                                                      new DefaultConfiguration("", "GeneratorSelector"),
  -                                                      newManager,
  -                                                      this.context,
  -                                                      this.roles,
  -                                                      this.logKitManager );
  -
  -            handler.setLogger( getLogger() );
  +                    generator.getHandler(newManager, this.context, this.roles, this.logKitManager);
  +            handler.setLogger(getLogger());
               handler.initialize();
  -            this.componentHandlers.put( hint, handler );
  -            getLogger().debug( "Adding " + generator.getName() + " for " + hint.toString() );
  -        }
  -        catch( final Exception e )
  -        {
  -            getLogger().error("Could not set up Component for hint: " + hint, e);
  +            this.componentHandlers.put(hint, handler);
  +            if (getLogger().isDebugEnabled()) {
  +                getLogger().debug("Adding " + generator.getName() + " for " + hint);
  +            }
  +        } catch(final Exception e) {
  +            // Error will be logged by caller. This is for debug only
  +            getLogger().debug("Could not set up Component for hint: " + hint, e);
               throw e;
           }
       }
   
       protected void removeGenerator(Object hint) {
           ComponentHandler handler = (ComponentHandler) this.componentHandlers.remove(hint);
  -        handler.dispose();
  -        this.classManager.reinstantiate();
  -        getLogger().debug( "Removing " + handler.getClass().getName() + " for " + hint.toString());
  +        if (handler != null) {
  +            handler.dispose();
  +            this.classManager.reinstantiate();
  +            getLogger().debug("Removing " + handler.getClass().getName() + " for " + hint.toString());
  +        }
       }
   
       public void dispose() {
           this.manager.release(this.classManager);
   
  -        synchronized(this)
  -        {
  +        synchronized(this) {
               Iterator keys = this.componentHandlers.keySet().iterator();
               List keyList = new ArrayList();
   
  -            while( keys.hasNext() )
  -            {
  +            while(keys.hasNext()) {
                   Object key = keys.next();
                   ComponentHandler handler =
  -                    (ComponentHandler)this.componentHandlers.get( key );
  +                    (ComponentHandler)this.componentHandlers.get(key);
   
                   handler.dispose();
   
  -                keyList.add( key );
  +                keyList.add(key);
               }
   
               keys = keyList.iterator();
   
  -            while( keys.hasNext() )
  -            {
  -                this.componentHandlers.remove( keys.next() );
  +            while(keys.hasNext()) {
  +                this.componentHandlers.remove(keys.next());
               }
   
               keyList.clear();
  
  
  
  1.5       +28 -28    xml-cocoon2/src/java/org/apache/cocoon/components/language/generator/ProgramGenerator.java
  
  Index: ProgramGenerator.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/language/generator/ProgramGenerator.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ProgramGenerator.java	4 Feb 2002 12:22:22 -0000	1.4
  +++ ProgramGenerator.java	7 Feb 2002 04:07:27 -0000	1.5
  @@ -57,6 +57,7 @@
   
   import org.apache.avalon.framework.component.Component;
   import org.apache.avalon.framework.component.ComponentManager;
  +
   import org.apache.cocoon.environment.SourceResolver;
   
   /**
  @@ -64,38 +65,37 @@
    * documents written in a <code>MarkupLanguage</code>
    *
    * @author <a href="mailto:ricardo@apache.org">Ricardo Rocha</a>
  - * @version CVS $Id: ProgramGenerator.java,v 1.4 2002/02/04 12:22:22 cziegeler Exp $
  + * @version CVS $Id: ProgramGenerator.java,v 1.5 2002/02/07 04:07:27 vgritsenko Exp $
    */
   public interface ProgramGenerator extends Component {
   
       String ROLE = "org.apache.cocoon.components.language.generator.ProgramGenerator";
   
  -  /**
  -   * Load a program built from an XML document written in a
  -   * <code>MarkupLanguage</code>
  -   *
  -   * @param newManager  The ComponentManager that it will be loaded with.
  -   * @param file The input document's <code>File</code>
  -   * @param markupLanguage The <code>MarkupLanguage</code> in which the input
  -   * document is written
  -   * @param programmingLanguage The <code>ProgrammingLanguage</code> in which
  -   * the program must be written
  -   * @return The loaded object
  -   * @exception Exception If an error occurs during generation or loading
  -   */
  -  CompiledComponent load(
  -    ComponentManager newManager,
  -    String fileName,
  -    String markupLanguage,
  -    String programmingLanguage,
  -    SourceResolver resolver
  -  ) throws Exception;
  +    /**
  +     * Load a program built from an XML document written in a
  +     * <code>MarkupLanguage</code>
  +     *
  +     * @param newManager  The ComponentManager that it will be loaded with.
  +     * @param file The input document's <code>File</code>
  +     * @param markupLanguage The <code>MarkupLanguage</code> in which the input
  +     * document is written
  +     * @param programmingLanguage The <code>ProgrammingLanguage</code> in which
  +     * the program must be written
  +     * @return The loaded object
  +     * @exception Exception If an error occurs during generation or loading
  +     */
  +    CompiledComponent load(
  +            ComponentManager newManager,
  +            String fileName,
  +            String markupLanguage,
  +            String programmingLanguage,
  +            SourceResolver resolver) throws Exception;
   
  -  /**
  -   * Release a program built from an XML document written in a
  -   * <code>MarkupLanguage</code>.
  -   *
  -   * @param CompiledSheet
  -   */
  -  void release(CompiledComponent component);
  +    /**
  +     * Release a program built from an XML document written in a
  +     * <code>MarkupLanguage</code>.
  +     *
  +     * @param CompiledSheet
  +     */
  +    void release(CompiledComponent component);
   }
  
  
  
  1.7       +144 -155  xml-cocoon2/src/java/org/apache/cocoon/components/language/generator/ProgramGeneratorImpl.java
  
  Index: ProgramGeneratorImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/language/generator/ProgramGeneratorImpl.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- ProgramGeneratorImpl.java	4 Feb 2002 12:22:22 -0000	1.6
  +++ ProgramGeneratorImpl.java	7 Feb 2002 04:07:27 -0000	1.7
  @@ -78,6 +78,7 @@
   import org.apache.cocoon.components.language.markup.sitemap.SitemapMarkupLanguage;
   import org.apache.cocoon.components.language.programming.CodeFormatter;
   import org.apache.cocoon.components.language.programming.ProgrammingLanguage;
  +import org.apache.cocoon.components.language.programming.Program;
   import org.apache.cocoon.components.store.Store;
   import org.apache.cocoon.environment.Source;
   import org.apache.cocoon.environment.SourceResolver;
  @@ -89,8 +90,10 @@
   
   /**
    * The default implementation of <code>ProgramGenerator</code>
  + *
    * @author <a href="mailto:ricardo@apache.org">Ricardo Rocha</a>
  - * @version CVS $Id: ProgramGeneratorImpl.java,v 1.6 2002/02/04 12:22:22 cziegeler Exp $
  + * @author <a href="mailto:vgritsenko@apache.org">Vadim Gritsenko</a>
  + * @version CVS $Id: ProgramGeneratorImpl.java,v 1.7 2002/02/07 04:07:27 vgritsenko Exp $
    */
   public class ProgramGeneratorImpl extends AbstractLoggable
       implements ProgramGenerator, Contextualizable, Composable, Parameterizable,
  @@ -102,7 +105,10 @@
       /** The pre-loading option */
       protected boolean preload = false;
   
  -    /** The ComponentSelector for CompiledPages */
  +    /**
  +     * The ComponentSelector for programs. Caches Program by program
  +     * source file.
  +     */
       protected GeneratorSelector cache;
   
       /** The repository store */
  @@ -187,7 +193,26 @@
       }
   
       /**
  +     * Generates program source file name in the working directory
  +     * from the source SystemID
  +     */
  +    private String getNormalizedName(final String systemId) {
  +        StringBuffer contextFilename = new StringBuffer(this.rootPackage.replace('.', File.separatorChar));
  +        contextFilename.append(File.separator);
  +        if(systemId.startsWith(this.contextDir)) {
  +            // VG: File is located under contextDir, using relative file name
  +            contextFilename.append(systemId.substring(this.contextDir.length()));
  +        } else {
  +            // VG: File is located outside of contextDir, using systemId
  +            contextFilename.append(systemId);
  +        }
  +        String normalizedName = IOUtils.normalizedFilename(contextFilename.toString());
  +        return normalizedName;
  +    }
  +
  +    /**
        * Load a program built from an XML document written in a <code>MarkupLanguage</code>
  +     *
        * @param file The input document's <code>File</code>
        * @param markupLanguage The <code>MarkupLanguage</code> in which the input document is written
        * @param programmingLanguage The <code>ProgrammingLanguage</code> in which the program must be written
  @@ -201,213 +226,177 @@
                                     SourceResolver resolver)
           throws Exception {
   
  -        Source source = resolver.resolve(fileName);
  +        final Source source = resolver.resolve(fileName);
  +        final String id = source.getSystemId();
  +
  +        ProgrammingLanguage programmingLanguage = null;
  +        MarkupLanguage markupLanguage = null;
           try {
  -            // Set filenames
  -            StringBuffer contextFilename = new StringBuffer(this.rootPackage.replace('.', File.separatorChar));
  -            contextFilename.append(File.separator);
  -            String id = source.getSystemId();
  -            if(id.startsWith(this.contextDir)) {
  -                // VG: File is located under contextDir, using relative file name
  -                contextFilename.append(id.substring(this.contextDir.length()));
  -            } else {
  -                // VG: File is located outside of contextDir, using systemId
  -                getLogger().debug("Loading from external source " + id);
  -                contextFilename.append(id);
  -            }
  -            String normalizedName = IOUtils.normalizedFilename(contextFilename.toString());
  +            // Create file name for the program generated from the provided source.
  +            final String normalizedName = getNormalizedName(id);
   
               // Ensure no 2 requests for the same file overlap
  -            Class program = null;
  +            Program program = null;
               CompiledComponent programInstance = null;
   
               // Attempt to load program object from cache
               try {
  -                programInstance = (CompiledComponent) select(normalizedName);
  +                programInstance = (CompiledComponent)this.cache.select(normalizedName);
               } catch (Exception e) {
                   getLogger().debug("The instance was not accessible from the internal cache. Proceeding.");
               }
   
  -            if ((programInstance == null) && this.preload) {
  +            if (programInstance == null && this.preload) {
  +                // Preloading: Load program if its source/[object file] is available
                   String className = normalizedName.replace(File.separatorChar, '.');
                   try {
  -                    program = this.classManager.loadClass(className);
  -                    this.addCompiledComponent(newManager, normalizedName, program);
  -                    programInstance = (CompiledComponent) select(normalizedName);
  +                    markupLanguage =
  +                            (MarkupLanguage)this.markupSelector.select(markupLanguageName);
  +                    programmingLanguage =
  +                            (ProgrammingLanguage)this.languageSelector.select(programmingLanguageName);
  +                    programmingLanguage.setLanguageName(programmingLanguageName);
  +                    program = programmingLanguage.load(normalizedName,
  +                            this.workDir, markupLanguage.getEncoding());
  +
  +                    this.cache.addGenerator(newManager, normalizedName, program);
  +                    programInstance = (CompiledComponent)this.cache.select(normalizedName);
                   } catch (Exception e) {
  -                    getLogger().debug("The class was not preloaded");
  +                    getLogger().debug("The program was not preloaded");
                   }
               }
   
  -            if (programInstance == null) {
  -                programInstance =
  -                    this.createResource(
  -                        newManager, fileName, normalizedName,
  -                        markupLanguageName, programmingLanguageName, resolver
  -                    );
  -            }
  -
  -            if (!this.autoReload) {
  -                return programInstance;
  -            }
  -
               /*
                * FIXME: It's the program (not the instance) that must
                * be queried for changes!!!
                */
  -            long lastModified = source.getLastModified();
  -            if (programInstance != null &&
  -                (lastModified == 0 || programInstance.modifiedSince(lastModified)))
  -            {
  -                // Release the component.
  -                release(programInstance);
  -
  -                // Unload program
  -                ProgrammingLanguage programmingLanguage = (ProgrammingLanguage)this.languageSelector.select(programmingLanguageName);
  -                programmingLanguage.setLanguageName(programmingLanguageName);
  -                programmingLanguage.unload(program, normalizedName, this.workDir);
  -                this.cache.removeGenerator(normalizedName);
  -
  -                // Invalidate previous program/instance pair
  -                program = null;
  -                programInstance = null;
  +            if (programInstance != null && this.autoReload) {
  +                // Autoreloading: Unload program if its source is modified
  +                long lastModified = source.getLastModified();
  +                if (lastModified == 0 || programInstance.modifiedSince(lastModified)) {
  +                    // Release the component.
  +                    release(programInstance);
  +                    programInstance = null;
  +
  +                    // Unload program
  +                    if (programmingLanguage == null) {
  +                        programmingLanguage =
  +                                (ProgrammingLanguage)this.languageSelector.select(programmingLanguageName);
  +                        programmingLanguage.setLanguageName(programmingLanguageName);
  +                    }
  +
  +                    programmingLanguage.unload(program, normalizedName, this.workDir);
  +                    this.cache.removeGenerator(normalizedName);
  +                    program = null;
  +                }
               }
   
  +            // Not preloaded or just unloaded: (re)create.
               if (programInstance == null) {
  -                if (program == null) {
  -                    programInstance =
  -                        this.createResource(
  -                            newManager, fileName, normalizedName,
  -                            markupLanguageName, programmingLanguageName,
  -                            resolver
  -                        );
  -                } else {
  -                    programInstance = (CompiledComponent) select(normalizedName);
  +                if (programmingLanguage == null) {
  +                    programmingLanguage =
  +                            (ProgrammingLanguage)this.languageSelector.select(programmingLanguageName);
  +                    programmingLanguage.setLanguageName(programmingLanguageName);
  +                }
  +                if (markupLanguage == null) {
  +                    markupLanguage =
  +                            (MarkupLanguage)this.markupSelector.select(markupLanguageName);
                   }
  +                programInstance = this.createResource(newManager,
  +                        source, normalizedName, markupLanguage,
  +                        programmingLanguage, resolver);
               }
   
               return programInstance;
           } finally {
               source.recycle();
  +            this.manager.release(markupLanguage);
  +            this.manager.release(programmingLanguage);
           }
       }
   
       /**
        * Helper method to create resources in a threadsafe manner.
        */
  -    private CompiledComponent createResource(
  -        ComponentManager newManager,
  -        String fileName,
  -        String normalizedName,
  -        String markupLanguageName,
  -        String programmingLanguageName,
  -        SourceResolver resolver
  -    )
  -    throws Exception {
  +    private CompiledComponent createResource(ComponentManager newManager,
  +                                             Source source,
  +                                             String normalizedName,
  +                                             MarkupLanguage markupLanguage,
  +                                             ProgrammingLanguage programmingLanguage,
  +                                             SourceResolver resolver)
  +            throws Exception {
   
           CompiledComponent programInstance = null;
  -        MarkupLanguage markupLanguage = null;
  -        ProgrammingLanguage programmingLanguage = null;
  -        Class program = null;
   
  -        // prevent 2 requests from generating this resource simultaneously
  +        // Prevent 2 requests from generating this resource simultaneously
           synchronized (this) {
  +            // Select first. Works for threads entering this synchronized block
  +            // after another thread
               try {
  -                programInstance = (CompiledComponent) select(normalizedName);
  -            } catch (Exception e) {
  +                return (CompiledComponent)this.cache.select(normalizedName);
  +            } catch (Exception cme) { }
   
  -                getLogger().debug(
  -                     "Creating resource " +
  -                     normalizedName.replace(File.separatorChar, '.') +
  -                     ", using generator " + this
  -                );
  +            // If failed, generate. This is for the first thread entering this block
  +            getLogger().debug("Creating resource " + normalizedName +
  +                 ", using generator " + this);
   
  -                try {
  -                    // Get markup and programming languages
  -                    markupLanguage = (MarkupLanguage)this.markupSelector.select(markupLanguageName);
  -                    programmingLanguage = (ProgrammingLanguage)this.languageSelector.select(programmingLanguageName);
  -                    programmingLanguage.setLanguageName(programmingLanguageName);
  -                    program = this.generateResource(newManager, fileName, normalizedName, markupLanguage, programmingLanguage, resolver);
  -                } catch (LanguageException le) {
  -                    getLogger().debug("Language Exception", le);
  -                    throw new ProcessingException("Language Exception", le);
  -                } finally {
  -                    if (this.markupSelector != null) {
  -                        this.markupSelector.release(markupLanguage);
  -                    }
  +            try {
  +                Program program = this.generateResource(newManager, source,
  +                        normalizedName, markupLanguage, programmingLanguage, resolver);
   
  -                    if (this.languageSelector != null) {
  -                        this.languageSelector.release(programmingLanguage);
  -                    }
  -                }
  +                // Store generated program in cache
  +                this.cache.addGenerator(newManager, normalizedName, program);
  +            } catch (LanguageException le) {
  +                getLogger().debug("Language Exception", le);
  +                throw new ProcessingException("Language Exception", le);
  +            }
   
  -                try {
  -                    programInstance = (CompiledComponent) select(normalizedName);
  -                } catch (Exception cme) {
  -                    getLogger().debug("Can't load ServerPage", cme);
  -                }
  +            // Select instance of newly generated program
  +            try {
  +                programInstance = (CompiledComponent)this.cache.select(normalizedName);
  +            } catch (Exception cme) {
  +                getLogger().debug("Can't load ServerPage", cme);
               }
           }
   
  -    return programInstance;
  +        return programInstance;
       }
   
  -    private Class generateResource(ComponentManager newManager,
  -                                   String fileName,
  -                                   String normalizedName,
  -                                   MarkupLanguage markupLanguage,
  -                                   ProgrammingLanguage programmingLanguage,
  -                                   SourceResolver resolver)
  -        throws Exception {
  -
  -        Source source = resolver.resolve(fileName);
  -        try {
  -            // Input Source
  -            InputSource is = source.getInputSource();
  -            // Generate code
  -            String code = markupLanguage.generateCode(is, normalizedName, programmingLanguage, resolver);
  -            String encoding = markupLanguage.getEncoding();
  -            // Format source code if applicable
  -            CodeFormatter codeFormatter = programmingLanguage.getCodeFormatter();
  -            if (codeFormatter != null) {
  -                code = codeFormatter.format(code, encoding);
  -            }
  -            // Store generated code
  -            String sourceFilename = new StringBuffer(normalizedName).append(".")
  -                                    .append(programmingLanguage.getSourceExtension()).toString();
  -            repository.store(sourceFilename, code);
  -            // [Compile]/Load generated program
  -            Class program = programmingLanguage.load(normalizedName, this.workDir, markupLanguage.getEncoding());
  -            // Store generated program in cache
  -            this.addCompiledComponent(newManager, normalizedName, program);
  +    /**
  +     * Generates Program out of Source using specified languages.
  +     */
  +    private Program generateResource(ComponentManager newManager,
  +                                     Source source,
  +                                     String normalizedName,
  +                                     MarkupLanguage markupLanguage,
  +                                     ProgrammingLanguage programmingLanguage,
  +                                     SourceResolver resolver)
  +            throws Exception {
  +
  +        // Input Source
  +        // FIXME(VG): Use Source.toSAX()
  +        InputSource is = source.getInputSource();
  +
  +        // Generate code
  +        String code = markupLanguage.generateCode(is, normalizedName, programmingLanguage, resolver);
  +        String encoding = markupLanguage.getEncoding();
  +
  +        // Format source code if applicable
  +        CodeFormatter codeFormatter = programmingLanguage.getCodeFormatter();
  +        if (codeFormatter != null) {
  +            code = codeFormatter.format(code, encoding);
  +        }
   
  -            // FIXME: Do we want this functionality?  All analysis says no.
  -            if (markupLanguage.getClass().equals(SitemapMarkupLanguage.class)) {
  -                try {
  -                    select("sitemap");
  -                } catch (Exception e) {
  -                    // If the root sitemap has not been compiled, add an alias here.
  -                    this.addCompiledComponent(newManager, "sitemap", program);
  -                }
  -            }
  +        // Store generated code
  +        String sourceFilename = normalizedName + "." + programmingLanguage.getSourceExtension();
   
  -            return program;
  -        } finally {
  -            source.recycle();
  -        }
  -    }
  +        // FIXME(VG): Get rid of repository.
  +        repository.store(sourceFilename, code);
   
  -    private final void addCompiledComponent(ComponentManager newManager,
  -                                            String normalizedName,
  -                                            Class program)
  -    throws Exception {
  -        this.cache.addGenerator(newManager, normalizedName, program);
  -    }
  +        // [Compile]/Load generated program
  +        Program program = programmingLanguage.load(normalizedName,
  +                this.workDir, markupLanguage.getEncoding());
   
  -    public CompiledComponent select(String componentName)
  -        throws Exception {
  -        CompiledComponent component = (CompiledComponent)this.cache.select(componentName);
  -        return component;
  +        return program;
       }
   
       public void release(CompiledComponent component) {
  
  
  
  1.12      +3 -1      xml-cocoon2/src/java/org/apache/cocoon/components/language/markup/AbstractMarkupLanguage.java
  
  Index: AbstractMarkupLanguage.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/language/markup/AbstractMarkupLanguage.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- AbstractMarkupLanguage.java	6 Feb 2002 04:40:28 -0000	1.11
  +++ AbstractMarkupLanguage.java	7 Feb 2002 04:07:27 -0000	1.12
  @@ -102,7 +102,7 @@
    * @author <a href="mailto:ricardo@apache.org">Ricardo Rocha</a>
    * @author <a href="mailto:dims@yahoo.com">Davanum Srinivas</a>
    * @author <a href="mailto:ovidiu@cup.hp.com">Ovidiu Predescu</a>
  - * @version CVS $Id: AbstractMarkupLanguage.java,v 1.11 2002/02/06 04:40:28 vgritsenko Exp $
  + * @version CVS $Id: AbstractMarkupLanguage.java,v 1.12 2002/02/07 04:07:27 vgritsenko Exp $
    */
   public abstract class AbstractMarkupLanguage
           extends AbstractLoggable
  @@ -371,11 +371,13 @@
        */
       public String generateCode(InputSource input, String filename, ProgrammingLanguage programmingLanguage,
                                  SourceResolver resolver) throws Exception {
  +
           String languageName = programmingLanguage.getLanguageName();
           LanguageDescriptor language = (LanguageDescriptor)this.languages.get(languageName);
           if (language == null) {
               throw new IllegalArgumentException("Unsupported programming language: " + languageName);
           }
  +
           // Create a XMLReader
           XMLReader reader = XMLReaderFactory.createXMLReader();
           // Get the needed preprocess filter
  
  
  
  1.5       +96 -98    xml-cocoon2/src/java/org/apache/cocoon/components/language/programming/AbstractProgrammingLanguage.java
  
  Index: AbstractProgrammingLanguage.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/language/programming/AbstractProgrammingLanguage.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- AbstractProgrammingLanguage.java	4 Feb 2002 12:22:23 -0000	1.4
  +++ AbstractProgrammingLanguage.java	7 Feb 2002 04:07:27 -0000	1.5
  @@ -55,13 +55,14 @@
   
   package org.apache.cocoon.components.language.programming;
   
  -import org.apache.avalon.framework.configuration.Configurable;
  -import org.apache.avalon.framework.configuration.Configuration;
  -import org.apache.avalon.framework.configuration.ConfigurationException;
   import org.apache.avalon.framework.logger.AbstractLoggable;
   import org.apache.avalon.framework.logger.Loggable;
  +import org.apache.avalon.framework.parameters.Parameterizable;
   import org.apache.avalon.framework.parameters.Parameters;
  +import org.apache.avalon.framework.parameters.ParameterException;
  +
   import org.apache.cocoon.components.language.LanguageException;
  +import org.apache.cocoon.components.language.generator.CompiledComponent;
   import org.apache.cocoon.util.ClassUtils;
   
   import java.io.File;
  @@ -72,102 +73,99 @@
    * unloading.
    *
    * @author <a href="mailto:ricardo@apache.org">Ricardo Rocha</a>
  - * @version CVS $Id: AbstractProgrammingLanguage.java,v 1.4 2002/02/04 12:22:23 cziegeler Exp $
  + * @author <a href="mailto:vgritsenko@apache.org">Vadim Gritsenko</a>
  + * @version CVS $Id: AbstractProgrammingLanguage.java,v 1.5 2002/02/07 04:07:27 vgritsenko Exp $
    */
   public abstract class AbstractProgrammingLanguage extends AbstractLoggable
  -  implements ProgrammingLanguage, Configurable
  -{
  -  /** The source code formatter */
  -  protected Class codeFormatter;
  -
  -  protected String languageName;
  -
  -  /**
  -   * Configure the language
  -   */
  -  public void configure(Configuration conf) throws ConfigurationException {
  -      try {
  -          getLogger().debug("Setting the parameters");
  -          this.setParameters( Parameters.fromConfiguration(conf) );
  -      } catch (Exception e) {
  -          getLogger().error("Could not set Parameters", e);
  -          throw new ConfigurationException("Could not get parameters because: " +
  -                                           e.getMessage());
  -      }
  -  }
  -
  -  /**
  -   * Set the configuration parameters. This method instantiates the
  -   * sitemap-specified source code formatter
  -   *
  -   * @param params The configuration parameters
  -   * @exception Exception If the language compiler cannot be loaded
  -   */
  -  protected void setParameters(Parameters params) throws Exception
  -  {
  -    try {
  -      String className = params.getParameter("code-formatter", null);
  -      if (className != null) {
  -        this.codeFormatter = ClassUtils.loadClass(className);
  -      }
  -    } catch (Exception e) {
  -       getLogger().error("Error with \"code-formatter\" parameter", e);
  -       throw e;
  -    }
  -  }
  -
  -  /**
  -   * Return this language's source code formatter. A new formatter instance is
  -   * created on each invocation.
  -   *
  -   * @return The language source code formatter
  -   */
  -  public CodeFormatter getCodeFormatter() {
  -    if (this.codeFormatter != null) {
  -      try {
  -        CodeFormatter formatter = (CodeFormatter) this.codeFormatter.newInstance();
  -        if (formatter instanceof Loggable) {
  -            ((Loggable)formatter).setLogger(this.getLogger());
  +        implements ProgrammingLanguage, Parameterizable {
  +
  +    /** The source code formatter */
  +    protected Class codeFormatter;
  +
  +    protected String languageName;
  +
  +    /**
  +     * Set the configuration parameters. This method instantiates the
  +     * sitemap-specified source code formatter
  +     *
  +     * @param params The configuration parameters
  +     * @exception Exception If the language compiler cannot be loaded
  +     */
  +    public void parameterize(Parameters params) throws ParameterException {
  +        String className = params.getParameter("code-formatter", null);
  +
  +        try {
  +            if (className != null) {
  +                this.codeFormatter = ClassUtils.loadClass(className);
  +            }
  +        } catch (Exception e) {
  +            getLogger().error("Error with \"code-formatter\" parameter", e);
  +            throw new ParameterException("Unable to load code formatter: " + className, e);
  +        }
  +    }
  +
  +    /**
  +     * Return this language's source code formatter. A new formatter instance is
  +     * created on each invocation.
  +     *
  +     * @return The language source code formatter
  +     */
  +    public CodeFormatter getCodeFormatter() {
  +        if (this.codeFormatter != null) {
  +            try {
  +                CodeFormatter formatter = (CodeFormatter) this.codeFormatter.newInstance();
  +                if (formatter instanceof Loggable) {
  +                    ((Loggable) formatter).setLogger(this.getLogger());
  +                }
  +                return formatter;
  +            } catch (Exception e) {
  +                getLogger().error("Error instantiating CodeFormatter", e);
  +            }
  +        }
  +
  +        return null;
  +    }
  +
  +    /**
  +     * Unload a previously loaded program
  +     *
  +     * @param program A previously loaded object program
  +     * @exception LanguageException If an error occurs during unloading
  +     */
  +    protected abstract void doUnload(Object program, String filename,
  +                                     File baseDirectory)
  +            throws LanguageException;
  +
  +    public final void unload(Object program, String filename, File baseDirectory)
  +            throws LanguageException {
  +
  +        File file = new File(baseDirectory,
  +                             filename + "." + getSourceExtension());
  +        file.delete();
  +        this.doUnload(program, filename, baseDirectory);
  +    }
  +
  +    public final void setLanguageName(String name) {
  +        this.languageName = name;
  +    }
  +
  +    public final String getLanguageName() {
  +        return this.languageName;
  +    }
  +
  +    /**
  +     * Create a new instance for the given class
  +     *
  +     * @param program The Java class
  +     * @return A new class instance
  +     * @exception LanguageException If an instantiation error occurs
  +     */
  +    public CompiledComponent instantiate(Program program) throws LanguageException {
  +        try {
  +            return program.newInstance();
  +        } catch (Exception e) {
  +            getLogger().warn("Could not instantiate program instance", e);
  +            throw new LanguageException("Could not instantiate program instance due to a " + e.getClass().getName() + ": " + e.getMessage());
           }
  -        return formatter;
  -      } catch (Exception e) {
  -          getLogger().error("Error instantiating CodeFormatter", e);
  -      }
  -    }
  -
  -    return null;
  -  }
  -
  -  /**
  -   * Unload a previously loaded program
  -   *
  -   * @param program A previously loaded object program
  -   * @exception LanguageException If an error occurs during unloading
  -   */
  -  protected abstract void doUnload(
  -    Object program, String filename, File baseDirectory
  -  )
  -    throws LanguageException;
  -
  -  public final void unload(
  -    Object program, String filename, File baseDirectory
  -  )
  -    throws LanguageException
  -  {
  -    File file = new File (
  -      baseDirectory, new StringBuffer(filename).append(".").append(this.getSourceExtension()).toString()
  -    );
  -
  -    file.delete();
  -
  -    this.doUnload(program, filename, baseDirectory);
  -  }
  -
  -  public final void setLanguageName(String name) {
  -    this.languageName = name;
  -  }
  -
  -  public final String getLanguageName() {
  -    return this.languageName;
  -  }
  +    }
   }
  
  
  
  1.5       +20 -11    xml-cocoon2/src/java/org/apache/cocoon/components/language/programming/CompiledProgrammingLanguage.java
  
  Index: CompiledProgrammingLanguage.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/language/programming/CompiledProgrammingLanguage.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- CompiledProgrammingLanguage.java	4 Feb 2002 12:22:23 -0000	1.4
  +++ CompiledProgrammingLanguage.java	7 Feb 2002 04:07:27 -0000	1.5
  @@ -59,8 +59,11 @@
   import org.apache.avalon.framework.context.ContextException;
   import org.apache.avalon.framework.context.Contextualizable;
   import org.apache.avalon.framework.parameters.Parameters;
  +import org.apache.avalon.framework.parameters.ParameterException;
  +
   import org.apache.cocoon.Constants;
   import org.apache.cocoon.components.language.LanguageException;
  +import org.apache.cocoon.components.language.programming.java.JavaProgram;
   import org.apache.cocoon.util.ClassUtils;
   import org.apache.cocoon.util.IOUtils;
   
  @@ -70,9 +73,10 @@
    * A compiled programming language. This class extends <code>AbstractProgrammingLanguage</code> adding support for compilation
    * and object program files
    * @author <a href="mailto:ricardo@apache.org">Ricardo Rocha</a>
  - * @version CVS $Id: CompiledProgrammingLanguage.java,v 1.4 2002/02/04 12:22:23 cziegeler Exp $
  + * @version CVS $Id: CompiledProgrammingLanguage.java,v 1.5 2002/02/07 04:07:27 vgritsenko Exp $
    */
   public abstract class CompiledProgrammingLanguage extends AbstractProgrammingLanguage implements Contextualizable {
  +
       /** The compiler */
       protected Class compilerClass;
   
  @@ -87,13 +91,15 @@
        * @param params The configuration parameters
        * @exception Exception If the language compiler cannot be loaded
        */
  -    protected void setParameters(Parameters params) throws Exception {
  -        super.setParameters(params);
  -        String compilerClass = params.getParameter("compiler", null);
  -        if (compilerClass == null) {
  -            throw new LanguageException("Missing 'compiler' parameter for compiled language '" + this.getLanguageName() + "'");
  +    public void parameterize(Parameters params) throws ParameterException {
  +        super.parameterize(params);
  +
  +        String compilerClass = params.getParameter("compiler");
  +        try {
  +            this.compilerClass = ClassUtils.loadClass(compilerClass);
  +        } catch (ClassNotFoundException e) {
  +            throw new ParameterException("Unable to load compiler: " + compilerClass, e);
           }
  -        this.compilerClass = ClassUtils.loadClass(compilerClass);
           this.deleteSources = params.getParameterAsBoolean("delete-sources", false);
       }
   
  @@ -161,18 +167,20 @@
       protected abstract void compile(String filename, File baseDirectory, String encoding) throws LanguageException;
   
       /**
  -     * Load an object program from a file. This method compiled the corresponding source file if necessary
  +     * Load an object program from a file.
  +     * This method compiled the corresponding source file if necessary.
  +     *
        * @param filename The object program base file name
        * @param baseDirectory The directory containing the object program file
        * @param encoding The encoding expected in the source file or <code>null</code> if it is the platform's default encoding
        * @return The loaded object program
        * @exception LanguageException If an error occurs during compilation
        */
  -    public Class load(String filename, File baseDirectory, String encoding) throws LanguageException {
  +    public Program load(String filename, File baseDirectory, String encoding) throws LanguageException {
           // Does object file exist? Load and return instance
           File objectFile = new File(baseDirectory, new StringBuffer(filename).append(".").append(this.getObjectExtension()).toString());
           if (objectFile.exists() && objectFile.isFile() && objectFile.canRead()) {
  -            return this.loadProgram(filename, baseDirectory);
  +            return new JavaProgram(this.loadProgram(filename, baseDirectory));
           }
           // Does source file exist?
           File sourceFile = new File(baseDirectory, new StringBuffer(filename).append(".").append(this.getSourceExtension()).toString());
  @@ -212,6 +220,7 @@
           if (program == null) {
               throw new LanguageException("Can't load program : " + baseDirectory.toString() + File.separator + filename);
           }
  -        return program;
  +
  +        return new JavaProgram(program);
       }
   }
  
  
  
  1.5       +75 -72    xml-cocoon2/src/java/org/apache/cocoon/components/language/programming/ProgrammingLanguage.java
  
  Index: ProgrammingLanguage.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/language/programming/ProgrammingLanguage.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ProgrammingLanguage.java	4 Feb 2002 12:22:23 -0000	1.4
  +++ ProgrammingLanguage.java	7 Feb 2002 04:07:27 -0000	1.5
  @@ -56,6 +56,7 @@
   package org.apache.cocoon.components.language.programming;
   
   import org.apache.avalon.framework.component.Component;
  +
   import org.apache.cocoon.components.language.LanguageException;
   import org.apache.cocoon.components.language.generator.CompiledComponent;
   
  @@ -65,80 +66,82 @@
    * This interface states the functionality of a programming language processor
    *
    * @author <a href="mailto:ricardo@apache.org">Ricardo Rocha</a>
  - * @version CVS $Id: ProgrammingLanguage.java,v 1.4 2002/02/04 12:22:23 cziegeler Exp $
  + * @version CVS $Id: ProgrammingLanguage.java,v 1.5 2002/02/07 04:07:27 vgritsenko Exp $
    */
   public interface ProgrammingLanguage extends Component {
   
       String ROLE = "org.apache.cocoon.components.language.programming.ProgrammingLanguage";
  -  /**
  -   * Return the programming language's source file extension
  -   *
  -   * @return The canonical source file extension
  -   */
  -  String getSourceExtension();
  -
  -  /**
  -   * Load a program from a file
  -   *
  -   * @param filename The program base file name
  -   * @param baseDirectory The directory containing the program file
  -   * @param encoding The encoding expected in the source file or
  -   * <code>null</code> if it is the platform's default encoding
  -   * @return The loaded program
  -   * @exception LanguageException If an error occurs during loading
  -   */
  -  Class load(String filename, File baseDirectory, String encoding)
  -    throws LanguageException;
  -
  -  /**
  -   * Create a new instance for the given program type
  -   *
  -   * @param program The program type
  -   * @return A new program type instance
  -   * @exception LanguageException If an instantiation error occurs
  -   */
  -  CompiledComponent instantiate(Class program) throws LanguageException;
  -
  -  /**
  -   * Unload from memory and invalidate a given program
  -   *
  -   * @param program The program
  -   * @param filename The name of the file this program was loaded from
  -   * @param baseDirectory The directory containing the program file
  -   * @exception LanguageException If an error occurs
  -   */
  -  void unload (Object program, String filename, File baseDirectory)
  -    throws LanguageException;
  -
  -  /**
  -   * Return the <code>CodeFormatter</code> associated with this programming
  -   * language
  -   *
  -   * @return The code formatter object or <code>null</code> if none is
  -   * available
  -   */
  -  CodeFormatter getCodeFormatter();
  -
  -  /**
  -   * Escape a <code>String</code> according to the programming language's
  -   * string constant encoding rules.
  -   *
  -   * @param constant The string to be escaped
  -   * @return The escaped string
  -   */
  -  String quoteString(String constant);
  -
  -  /**
  -   * Set Language Name
  -   *
  -   * @param name The name of the language
  -   */
  -  void setLanguageName(String name);
  -
  -  /**
  -   * Get Language Name
  -   *
  -   * @return The name of the language
  -   */
  -  String getLanguageName();
  +
  +    /**
  +     * Return the programming language's source file extension
  +     *
  +     * @return The canonical source file extension
  +     */
  +    String getSourceExtension();
  +
  +    /**
  +     * Load a program from a file
  +     *
  +     * @param filename The program base file name
  +     * @param baseDirectory The directory containing the program file
  +     * @param encoding The encoding expected in the source file or
  +     * <code>null</code> if it is the platform's default encoding
  +     * @return The loaded program
  +     * @exception LanguageException If an error occurs during loading
  +     */
  +    Program load(String filename, File baseDirectory, String encoding)
  +            throws LanguageException;
  +
  +    /**
  +     * Create a new instance for the given program type
  +     *
  +     * @param program The program type
  +     * @return A new program type instance
  +     * @exception LanguageException If an instantiation error occurs
  +     */
  +    // FIXME(VG): Not used
  +    CompiledComponent instantiate(Program program) throws LanguageException;
  +
  +    /**
  +     * Unload from memory and invalidate a given program
  +     *
  +     * @param program The program
  +     * @param filename The name of the file this program was loaded from
  +     * @param baseDirectory The directory containing the program file
  +     * @exception LanguageException If an error occurs
  +     */
  +    void unload(Object program, String filename, File baseDirectory) // unload(Program ?
  +            throws LanguageException;
  +
  +    /**
  +     * Return the <code>CodeFormatter</code> associated with this programming
  +     * language
  +     *
  +     * @return The code formatter object or <code>null</code> if none is
  +     * available
  +     */
  +    CodeFormatter getCodeFormatter();
  +
  +    /**
  +     * Escape a <code>String</code> according to the programming language's
  +     * string constant encoding rules.
  +     *
  +     * @param constant The string to be escaped
  +     * @return The escaped string
  +     */
  +    String quoteString(String constant);
  +
  +    /**
  +     * Set Language Name
  +     *
  +     * @param name The name of the language
  +     */
  +    void setLanguageName(String name);
  +
  +    /**
  +     * Get Language Name
  +     *
  +     * @return The name of the language
  +     */
  +    String getLanguageName();
   }
  
  
  
  1.1                  xml-cocoon2/src/java/org/apache/cocoon/components/language/programming/Program.java
  
  Index: Program.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache Cocoon" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  package org.apache.cocoon.components.language.programming;
  
  import org.apache.avalon.framework.component.ComponentManager;
  import org.apache.avalon.framework.context.Context;
  
  import org.apache.avalon.excalibur.component.ComponentHandler;
  import org.apache.avalon.excalibur.component.RoleManager;
  import org.apache.avalon.excalibur.logger.LogKitManager;
  
  import org.apache.cocoon.components.language.generator.CompiledComponent;
  
  /**
   * This interface states the functionality of a program.
   * For compilable languages this is the wrapper for a Java Class object.
   *
   * @author <a href="mailto:vgritsenko@apache.org">Vadim Gritsenko</a>
   * @version CVS $Id: Program.java,v 1.1 2002/02/07 04:07:27 vgritsenko Exp $
   */
  public interface Program {
  
      /**
       * Get the name of this program.
       */
      String getName();
  
      /**
       * Get ComponentHandler which holds instances of this program.
       */
      ComponentHandler getHandler(ComponentManager manager,
                                  Context context,
                                  RoleManager roles,
                                  LogKitManager logKitManager) throws Exception;
  
      /**
       * Create new instance of the program.
       */
      CompiledComponent newInstance() throws Exception;
  }
  
  
  
  1.6       +12 -21    xml-cocoon2/src/java/org/apache/cocoon/components/language/programming/java/JavaLanguage.java
  
  Index: JavaLanguage.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/language/programming/java/JavaLanguage.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- JavaLanguage.java	4 Feb 2002 12:22:24 -0000	1.5
  +++ JavaLanguage.java	7 Feb 2002 04:07:28 -0000	1.6
  @@ -60,12 +60,14 @@
   import org.apache.avalon.framework.component.ComponentManager;
   import org.apache.avalon.framework.component.Composable;
   import org.apache.avalon.framework.parameters.Parameters;
  +import org.apache.avalon.framework.parameters.ParameterException;
   import org.apache.avalon.framework.thread.ThreadSafe;
   import org.apache.cocoon.components.classloader.ClassLoaderManager;
   import org.apache.cocoon.components.language.LanguageException;
   import org.apache.cocoon.components.language.generator.CompiledComponent;
   import org.apache.cocoon.components.language.programming.CompiledProgrammingLanguage;
   import org.apache.cocoon.components.language.programming.CompilerError;
  +import org.apache.cocoon.components.language.programming.Program;
   import org.apache.cocoon.util.ClassUtils;
   import org.apache.cocoon.util.JavaArchiveFilter;
   
  @@ -78,7 +80,7 @@
    * The Java programming language processor
    *
    * @author <a href="mailto:ricardo@apache.org">Ricardo Rocha</a>
  - * @version CVS $Id: JavaLanguage.java,v 1.5 2002/02/04 12:22:24 cziegeler Exp $
  + * @version CVS $Id: JavaLanguage.java,v 1.6 2002/02/07 04:07:28 vgritsenko Exp $
    */
   public class JavaLanguage extends CompiledProgrammingLanguage implements ThreadSafe, Composable, Disposable {
   
  @@ -122,12 +124,17 @@
      * @param params The configuration parameters
      * @exception Exception If the class loader manager cannot be instantiated
      */
  -  protected void setParameters(Parameters params) throws Exception {
  -    super.setParameters(params);
  +  public void parameterize(Parameters params) throws ParameterException {
  +    super.parameterize(params);
   
  -    String compilerClass = params.getParameter("class-loader", "org.apache.cocoon.components.classloader.ClassLoaderManagerImpl");
  +    String compilerClass = params.getParameter("class-loader",
  +            "org.apache.cocoon.components.classloader.ClassLoaderManagerImpl");
       if (compilerClass != null) {
  -        this.classLoaderManager = (ClassLoaderManager) ClassUtils.newInstance(compilerClass);
  +        try {
  +            this.classLoaderManager = (ClassLoaderManager) ClassUtils.newInstance(compilerClass);
  +        } catch (Exception e) {
  +            throw new ParameterException("Unable to load compiler: " + compilerClass, e);
  +        }
       }
     }
   
  @@ -261,22 +268,6 @@
       } catch (IOException e) {
         getLogger().warn("Error during compilation", e);
         throw new LanguageException("Error during compilation: " + e.getMessage());
  -    }
  -  }
  -
  -  /**
  -   * Create a new instance for the given class
  -   *
  -   * @param program The Java class
  -   * @return A new class instance
  -   * @exception LanguageException If an instantiation error occurs
  -   */
  -  public CompiledComponent instantiate(Class program) throws LanguageException {
  -    try {
  -      return (CompiledComponent) program.newInstance();
  -    } catch (Exception e) {
  -      getLogger().warn("Could not instantiate program instance", e);
  -      throw new LanguageException("Could not instantiate program instance due to a " + e.getClass().getName() + ": " + e.getMessage());
       }
     }
   
  
  
  
  1.1                  xml-cocoon2/src/java/org/apache/cocoon/components/language/programming/java/JavaProgram.java
  
  Index: JavaProgram.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache Cocoon" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  package org.apache.cocoon.components.language.programming.java;
  
  import org.apache.avalon.framework.configuration.DefaultConfiguration;
  import org.apache.avalon.framework.component.ComponentManager;
  import org.apache.avalon.framework.context.Context;
  
  import org.apache.avalon.excalibur.component.ComponentHandler;
  import org.apache.avalon.excalibur.component.RoleManager;
  import org.apache.avalon.excalibur.logger.LogKitManager;
  
  import org.apache.cocoon.components.language.generator.CompiledComponent;
  import org.apache.cocoon.components.language.programming.Program;
  
  /**
   * This represents program in Java language. 
   * It wraps Java Class object.
   *
   * @author <a href="mailto:vgritsenko@apache.org">Vadim Gritsenko</a>
   * @version CVS $Id: JavaProgram.java,v 1.1 2002/02/07 04:07:28 vgritsenko Exp $
   */
  public class JavaProgram implements Program {
  
      protected Class program;
  
      public JavaProgram(Class program) {
          this.program = program;
      }
  
      public String getName() {
          return program.getName();
      }
  
      public ComponentHandler getHandler(ComponentManager manager,
                                         Context context,
                                         RoleManager roles,
                                         LogKitManager logKitManager)
              throws Exception {
  
          return ComponentHandler.getComponentHandler(
                  program,
                  new DefaultConfiguration("", "GeneratorSelector"),
                  manager, context, roles, logKitManager);
      }
  
      public CompiledComponent newInstance() throws Exception {
          return (CompiledComponent)this.program.newInstance();
      }
  }
  
  
  

----------------------------------------------------------------------
In case of troubles, e-mail:     webmaster@xml.apache.org
To unsubscribe, e-mail:          cocoon-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: cocoon-cvs-help@xml.apache.org