Tim Funk wrote:
> Unless I am missing something - we will now have a one TldConfig per
> Context.
That is how it was before.

> And each TldConfig will have its own tldDigester.
No, tldDigester is static.

> But the
> tldDigester is only used once on startup to find all the listeners.
> 
> So tldDigester only needs to live for the life of execute() where
> eventType=Lifecycle.START_EVENT.
> 
> Long story short:
> I think tldDigester can now be a local variable in the execute() method.
> That way the tldDigester can be deallocated after startup by how the
> variable is scoped.
I'm not against that change although it may slow start-up slightly. I
haven't tested how expensive creating the parser is. It would also fix an
unreported bug that the xml validation settings are taken from the first
context and used for all contexts.

Mark

> 
> -Tim
> 
> [EMAIL PROTECTED] wrote:
>> Author: markt
>> Date: Fri Oct  3 04:53:28 2008
>> New Revision: 701355
>>
>> URL: http://svn.apache.org/viewvc?rev=701355&view=rev
>> Log:
>> Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=45933
>> Don't use parser from web-app for tld files
>>
>> Modified:
>>     tomcat/trunk/java/org/apache/catalina/core/StandardContext.java
>>     tomcat/trunk/java/org/apache/catalina/startup/LocalStrings.properties
>>     tomcat/trunk/java/org/apache/catalina/startup/TldConfig.java
>>
>> Modified: tomcat/trunk/java/org/apache/catalina/core/StandardContext.java
>> URL:
>> http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/StandardContext.java?rev=701355&r1=701354&r2=701355&view=diff
>>
>> ==============================================================================
>>
>> --- tomcat/trunk/java/org/apache/catalina/core/StandardContext.java
>> (original)
>> +++ tomcat/trunk/java/org/apache/catalina/core/StandardContext.java
>> Fri Oct  3 04:53:28 2008
>> @@ -4267,10 +4267,6 @@
>>                      ((Lifecycle) pipeline).start();
>>                  }
>>                  -                if(getProcessTlds()) {
>> -                    processTlds();
>> -                }
>> -                                 // Notify our interested
>> LifecycleListeners
>>                  lifecycle.fireLifecycleEvent(START_EVENT, null);
>>                  @@ -4481,40 +4477,6 @@
>>      }
>>  
>>      /**
>> -     * Processes TLDs.
>> -     *
>> -     * @throws LifecycleException If an error occurs
>> -     */
>> -     protected void processTlds() throws LifecycleException {
>> -       TldConfig tldConfig = new TldConfig();
>> -       tldConfig.setContext(this);
>> -
>> -       // (1)  check if the attribute has been defined
>> -       //      on the context element.
>> -       tldConfig.setTldValidation(tldValidation);
>> -       tldConfig.setTldNamespaceAware(tldNamespaceAware);
>> -
>> -       // (2) if the attribute wasn't defined on the context
>> -       //     try the host.
>> -       if (!tldValidation) {
>> -         tldConfig.setTldValidation
>> -           (((StandardHost) getParent()).getXmlValidation());
>> -       }
>> -
>> -       if (!tldNamespaceAware) {
>> -         tldConfig.setTldNamespaceAware
>> -           (((StandardHost) getParent()).getXmlNamespaceAware());
>> -       }
>> -                    -       try {
>> -         tldConfig.execute();
>> -       } catch (Exception ex) {
>> -         log.error("Error reading tld listeners "
>> -                    + ex.toString(), ex); -       }
>> -     }
>> -    -    /**
>>       * Stop this Context component.
>>       *
>>       * @exception LifecycleException if a shutdown error occurs
>> @@ -5327,6 +5289,10 @@
>>                  return;
>>              }
>>          }
>> +        if (processTlds) {
>> +            this.addLifecycleListener(new TldConfig());
>> +        }
>> +
>>          super.init();
>>                   // Notify our interested LifecycleListeners
>>
>> Modified:
>> tomcat/trunk/java/org/apache/catalina/startup/LocalStrings.properties
>> URL:
>> http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/startup/LocalStrings.properties?rev=701355&r1=701354&r2=701355&view=diff
>>
>> ==============================================================================
>>
>> ---
>> tomcat/trunk/java/org/apache/catalina/startup/LocalStrings.properties
>> (original)
>> +++
>> tomcat/trunk/java/org/apache/catalina/startup/LocalStrings.properties
>> Fri Oct  3 04:53:28 2008
>> @@ -87,6 +87,8 @@
>>  hostConfig.undeploy=Undeploying context [{0}]
>>  hostConfig.undeploy.error=Error undeploying web application at
>> context path {0}
>>  hostConfig.undeploying=Undeploying deployed web applications
>> +tldConfig.cce=Lifecycle event data object {0} is not a Context
>> +tldConfig.execute=Error processing TLD files for context path {0}
>>  userConfig.database=Exception loading user database
>>  userConfig.deploy=Deploying web application for user {0}
>>  userConfig.deploying=Deploying user web applications
>>
>> Modified: tomcat/trunk/java/org/apache/catalina/startup/TldConfig.java
>> URL:
>> http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/startup/TldConfig.java?rev=701355&r1=701354&r2=701355&view=diff
>>
>> ==============================================================================
>>
>> --- tomcat/trunk/java/org/apache/catalina/startup/TldConfig.java
>> (original)
>> +++ tomcat/trunk/java/org/apache/catalina/startup/TldConfig.java Fri
>> Oct  3 04:53:28 2008
>> @@ -47,20 +47,24 @@
>>  import javax.servlet.ServletException;
>>  
>>  import org.apache.catalina.Context;
>> +import org.apache.catalina.Lifecycle;
>> +import org.apache.catalina.LifecycleEvent;
>> +import org.apache.catalina.LifecycleListener;
>>  import org.apache.catalina.core.StandardContext;
>> +import org.apache.catalina.core.StandardHost;
>>  import org.apache.catalina.util.StringManager;
>>  import org.apache.tomcat.util.digester.Digester;
>>  import org.xml.sax.InputSource;
>>  
>>  /**
>> - * Startup event listener for a <b>Context</b> that configures the
>> properties
>> - * of that Context, and the associated defined servlets.
>> + * Startup event listener for a <b>Context</b> that configures
>> application
>> + * listeners configured in any TLD files.
>>   *
>>   * @author Craig R. McClanahan
>>   * @author Jean-Francois Arcand
>>   * @author Costin Manolache
>>   */
>> -public final class TldConfig  {
>> +public final class TldConfig  implements LifecycleListener {
>>  
>>      // Names of JARs that are known not to contain any TLDs
>>      private static HashSet<String> noTldJars;
>> @@ -387,20 +391,6 @@
>>      }
>>  
>>      /**
>> -     * Create (if necessary) and return a Digester configured to
>> process a tag
>> -     * library descriptor, looking for additional listener classes to be
>> -     * registered.
>> -     */
>> -    private static Digester createTldDigester() {
>> -
>> -        return DigesterFactory.newDigester(tldValidation,
>> -                                           tldNamespaceAware,
>> -                                           new TldRuleSet());
>> -
>> -    }
>> -
>> -
>> -    /**
>>       * Scan the JAR file at the specified resource path for TLDs in the
>>       * <code>META-INF</code> subdirectory, and scan each TLD for
>> application
>>       * event listeners that need to be registered.
>> @@ -502,10 +492,6 @@
>>      private void tldScanStream(InputSource resourceStream)
>>          throws Exception {
>>  
>> -        if (tldDigester == null){
>> -            tldDigester = createTldDigester();
>> -        }
>> -                 synchronized (tldDigester) {
>>              try {
>>                  tldDigester.push(this);
>> @@ -730,4 +716,51 @@
>>  
>>          return jarPathMap;
>>      }
>> +
>> +    public void lifecycleEvent(LifecycleEvent event) {
>> +        // Identify the context we are associated with
>> +        try {
>> +            context = (Context) event.getLifecycle();
>> +        } catch (ClassCastException e) {
>> +            log.error(sm.getString("tldConfig.cce",
>> event.getLifecycle()), e);
>> +            return;
>> +        }
>> +        +        if (event.getType().equals(Lifecycle.INIT_EVENT)) {
>> +            init();
>> +        } else if (event.getType().equals(Lifecycle.START_EVENT)) {
>> +            try {
>> +                execute();
>> +            } catch (Exception e) {
>> +                log.error(sm.getString(
>> +                        "tldConfig.execute", context.getPath()), e);
>> +            }
>> +        } // Ignore the other event types - nothing to do +    }
>> +    +    private void init() {
>> +        if (tldDigester == null){
>> +            // (1)  check if the attribute has been defined
>> +            //      on the context element.
>> +            setTldValidation(context.getTldValidation());
>> +            setTldNamespaceAware(context.getTldNamespaceAware());
>> +    +            // (2) if the attribute wasn't defined on the context
>> +            //     try the host.
>> +            if (!tldValidation) {
>> +              setTldValidation(
>> +                      ((StandardHost)
>> context.getParent()).getXmlValidation());
>> +            }
>> +    +            if (!tldNamespaceAware) {
>> +              setTldNamespaceAware(
>> +                      ((StandardHost)
>> context.getParent()).getXmlNamespaceAware());
>> +            }
>> +
>> +            tldDigester = DigesterFactory.newDigester(tldValidation,
>> +                    tldNamespaceAware, +                    new
>> TldRuleSet());
>> +            tldDigester.getParser();
>> +        }
>> +    }
>>  }
>>
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to