vgritsenko    2002/09/20 19:13:21

  Modified:    src/java/org/apache/cocoon/components/language/generator
                        ProgramGenerator.java ProgramGeneratorImpl.java
  Log:
  Load programs from the Source, not from the 'File' (it's not file really, it's a 
source).
  Deprecate previous method.
  
  Revision  Changes    Path
  1.9       +33 -3     
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.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- ProgramGenerator.java     12 Aug 2002 07:50:52 -0000      1.8
  +++ ProgramGenerator.java     21 Sep 2002 02:13:21 -0000      1.9
  @@ -52,6 +52,7 @@
   
   import org.apache.avalon.framework.component.Component;
   import org.apache.avalon.framework.component.ComponentManager;
  +import org.apache.excalibur.source.Source;
   
   import org.apache.cocoon.environment.SourceResolver;
   
  @@ -78,6 +79,7 @@
        * the program must be written
        * @return The loaded object
        * @exception Exception If an error occurs during generation or loading
  +     * @deprecated Pass Source object instead of file name.
        */
       CompiledComponent load(
               ComponentManager newManager,
  @@ -87,10 +89,38 @@
               SourceResolver resolver) throws Exception;
   
       /**
  -     * Release a program built from an XML document written in a
  +     * 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 source The input document's <code>File</code> name
  +     * @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,
  +            Source source,
  +            String markupLanguage,
  +            String programmingLanguage,
  +            SourceResolver resolver) throws Exception;
  +
  +    /**
  +     * Release a program instance built from an XML document written in a
        * <code>MarkupLanguage</code>.
        *
  -     * @param CompiledSheet
  +     * @param component to be released.
        */
       void release(CompiledComponent component);
  +
  +    /**
  +     * Remove a program from the generator's cache and dipose all
  +     * instances of this program.
  +     *
  +     * @param source of the program to be removed.
  +     */
  +    void remove(Source source);
   }
  
  
  
  1.22      +55 -24    
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.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- ProgramGeneratorImpl.java 11 Sep 2002 12:44:09 -0000      1.21
  +++ ProgramGeneratorImpl.java 21 Sep 2002 02:13:21 -0000      1.22
  @@ -204,8 +204,7 @@
               // VG: File is located outside of contextDir, using systemId
               contextFilename.append(systemId);
           }
  -        String normalizedName = 
IOUtils.normalizedFilename(contextFilename.toString());
  -        return normalizedName;
  +        return IOUtils.normalizedFilename(contextFilename.toString());
       }
   
       /**
  @@ -225,6 +224,25 @@
           throws Exception {
   
           final Source source = resolver.resolveURI(fileName);
  +        return load(newManager, source, markupLanguageName, 
programmingLanguageName, resolver);
  +    }
  +
  +    /**
  +     * Load a program built from an XML document written in a 
<code>MarkupLanguage</code>
  +     *
  +     * @param source The input document's <code>File</code>
  +     * @param markupLanguageName The <code>MarkupLanguage</code> in which the input 
document is written
  +     * @param programmingLanguageName The <code>ProgrammingLanguage</code> in which 
the program must be written
  +     * @return The loaded program instance
  +     * @exception Exception If an error occurs during generation or loading
  +     */
  +    public CompiledComponent load(ComponentManager newManager,
  +                                  Source source,
  +                                  String markupLanguageName,
  +                                  String programmingLanguageName,
  +                                  SourceResolver resolver)
  +        throws Exception {
  +
           final String id = source.getSystemId();
   
           ProgrammingLanguage programmingLanguage = null;
  @@ -234,10 +252,10 @@
               final String normalizedName = getNormalizedName(id);
   
               if (getLogger().isDebugEnabled()) {
  -                getLogger().debug("Loading serverpage fileName=[" + 
String.valueOf(fileName) + "]" +
  -                    " markupLanguageName=[" + String.valueOf(markupLanguageName) + 
"]" +
  -                    " programmingLanguageName=[" + 
String.valueOf(programmingLanguageName) + "]" +
  -                    " -> normalizedName=[" + String.valueOf(normalizedName) + "]");
  +                getLogger().debug("Loading serverpage systemId=[" + id + "]" +
  +                    " markupLanguageName=[" + markupLanguageName + "]" +
  +                    " programmingLanguageName=[" + programmingLanguageName + "]" +
  +                    " -> normalizedName=[" + normalizedName + "]");
               }
   
               markupLanguage = (MarkupLanguage) 
this.markupSelector.select(markupLanguageName);
  @@ -250,10 +268,9 @@
               // Attempt to load program object from cache
               try {
                   programInstance = (CompiledComponent) 
this.cache.select(normalizedName);
  -            }
  -            catch (Exception e) {
  +            } catch (Exception e) {
                   if (getLogger().isDebugEnabled()) {
  -                    getLogger().debug("The serverpage [" + String.valueOf(id) + "] 
is not in the cache yet");
  +                    getLogger().debug("The serverpage [" + id + "] is not in the 
cache yet");
                   }
               }
   
  @@ -266,12 +283,12 @@
                       programInstance = (CompiledComponent) 
this.cache.select(normalizedName);
   
                       if (getLogger().isDebugEnabled()) {
  -                        getLogger().debug("Successfully preloaded serverpage [" + 
String.valueOf(id) + "]");
  +                        getLogger().debug("Successfully preloaded serverpage [" + 
id + "]");
                       }
                   }
                   catch (Exception e) {
                       if (getLogger().isErrorEnabled()) {
  -                        getLogger().error("The serverpage [" + String.valueOf(id) + 
"] could not be preloaded");
  +                        getLogger().error("The serverpage [" + id + "] could not be 
preloaded");
                       }
                   }
               }
  @@ -279,7 +296,7 @@
               if (programInstance == null) {
                   // no instance found
                   if (getLogger().isDebugEnabled()) {
  -                    getLogger().debug("Creating new serverpage for [" + 
String.valueOf(id) + "]");
  +                    getLogger().debug("Creating new serverpage for [" + id + "]");
                   }
                   synchronized (this) {
                       generateSourcecode(source, normalizedName, markupLanguage, 
programmingLanguage, resolver);
  @@ -296,11 +313,11 @@
                       // In that case, let the program instance decide if it is 
modified or not.
                       if (programInstance.modifiedSince(sourceLastModified)) {
                           if (getLogger().isDebugEnabled()) {
  -                            getLogger().debug("ReCreating serverpage for [" + 
String.valueOf(id) + "]");
  +                            getLogger().debug("ReCreating serverpage for [" + id + 
"]");
                           }
                           synchronized (this) {
                               if (getLogger().isDebugEnabled()) {
  -                                getLogger().debug("Releasing old serverpage program 
[" + String.valueOf(id) + "]");
  +                                getLogger().debug("Releasing old serverpage program 
[" + id + "]");
                               }
                               release(programInstance);
                               programmingLanguage.unload(program, normalizedName, 
this.workDir);
  @@ -317,7 +334,7 @@
                           // check the repository for changes at all?
                           if (this.watchSource) {
                               if (getLogger().isDebugEnabled()) {
  -                                getLogger().debug("Checking sourcecode of [" + 
String.valueOf(id) + "] for a change");
  +                                getLogger().debug("Checking sourcecode of [" + id + 
"] for a change");
                               }
                               File sourcecodeFile = new File(this.workDir, 
normalizedName + "." + programmingLanguage.getSourceExtension());
                               // has sourcecode in repository changed ?
  @@ -325,11 +342,11 @@
                                   long sourcecodeLastModified = 
sourcecodeFile.lastModified();
                                   if (sourcecodeLastModified > sourceLastModified || 
sourceLastModified == 0 || sourcecodeLastModified == 0) {
                                       if (getLogger().isDebugEnabled()) {
  -                                        getLogger().debug("Create new serverpage 
program for [" + String.valueOf(id) + "] - repository has changed");
  +                                        getLogger().debug("Create new serverpage 
program for [" + id + "] - repository has changed");
                                       }
                                       synchronized (this) {
                                           if (getLogger().isDebugEnabled()) {
  -                                            getLogger().debug("Releasing old 
serverpage program [" + String.valueOf(id) + "]");
  +                                            getLogger().debug("Releasing old 
serverpage program [" + id + "]");
                                           }
                                           release(programInstance);
                                           //programmingLanguage.unload(program, 
normalizedName, this.workDir);
  @@ -342,13 +359,13 @@
                                   }
                                   else {
                                       if (getLogger().isDebugEnabled()) {
  -                                        getLogger().debug("Sourcecode of [" + 
String.valueOf(id) + "] has not changed - returning program from cache");
  +                                        getLogger().debug("Sourcecode of [" + id + 
"] has not changed - returning program from cache");
                                       }
                                   }
                               }
                               else {
                                   if (getLogger().isErrorEnabled()) {
  -                                    getLogger().error("Could not find sourcecode 
for [" + String.valueOf(id) + "]");
  +                                    getLogger().error("Could not find sourcecode 
for [" + id + "]");
                                   }
                               }
                           }
  @@ -395,13 +412,13 @@
           try {
   
               if (getLogger().isDebugEnabled()) {
  -                getLogger().debug("Loading program [" + 
String.valueOf(normalizedName) + "]");
  +                getLogger().debug("Loading program [" + normalizedName + "]");
               }
               Program program = programmingLanguage.load(normalizedName, 
this.workDir, markupLanguage.getEncoding());
   
               this.cache.addGenerator(newManager, normalizedName, program);
               if (getLogger().isDebugEnabled()) {
  -                getLogger().debug("Successfully loaded program [" + 
String.valueOf(normalizedName) + "]");
  +                getLogger().debug("Successfully loaded program [" + normalizedName 
+ "]");
               }
           }
           catch (LanguageException le) {
  @@ -433,7 +450,7 @@
               throws Exception {
   
           if (getLogger().isDebugEnabled()) {
  -            getLogger().debug("Creating sourcecode for [" + 
String.valueOf(source.getSystemId()) + "]");
  +            getLogger().debug("Creating sourcecode for [" + source.getSystemId() + 
"]");
           }
           // Input Source
           // FIXME(VG): Use Source.toSAX()
  @@ -466,12 +483,26 @@
           }
           IOUtils.serializeString(sourceFile, code);
           if (getLogger().isDebugEnabled()) {
  -            getLogger().debug("Successfully created sourcecode for [" + 
String.valueOf(source.getSystemId()) + "]");
  +            getLogger().debug("Successfully created sourcecode for [" + 
source.getSystemId() + "]");
           }
       }
   
  +    /**
  +     * Releases the program instance.
  +     * @param component program instance to be released
  +     */
       public void release(CompiledComponent component) {
           this.cache.release(component);
  +    }
  +
  +    /**
  +     * Removes named program from the program generator's cache.
  +     * Disposes all created instances of the program.
  +     * @param source of the program to be removed
  +     */
  +    public void remove(Source source) {
  +        final String normalizedName = getNormalizedName(source.getSystemId());
  +        this.cache.removeGenerator(normalizedName);
       }
   
       /**
  
  
  

----------------------------------------------------------------------
In case of troubles, e-mail:     [EMAIL PROTECTED]
To unsubscribe, e-mail:          [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to