Return-Path: Delivered-To: apmail-cocoon-cvs-archive@www.apache.org Received: (qmail 56862 invoked from network); 6 Oct 2005 13:26:00 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 6 Oct 2005 13:26:00 -0000 Received: (qmail 49875 invoked by uid 500); 6 Oct 2005 13:25:56 -0000 Delivered-To: apmail-cocoon-cvs-archive@cocoon.apache.org Received: (qmail 49825 invoked by uid 500); 6 Oct 2005 13:25:56 -0000 Mailing-List: contact cvs-help@cocoon.apache.org; run by ezmlm Precedence: bulk Reply-To: dev@cocoon.apache.org list-help: list-unsubscribe: List-Post: List-Id: Delivered-To: mailing list cvs@cocoon.apache.org Received: (qmail 49812 invoked by uid 99); 6 Oct 2005 13:25:56 -0000 X-ASF-Spam-Status: No, hits=-9.8 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.29) with SMTP; Thu, 06 Oct 2005 06:25:55 -0700 Received: (qmail 56015 invoked by uid 65534); 6 Oct 2005 13:25:34 -0000 Message-ID: <20051006132534.55910.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r306637 - /cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/TreeProcessor.java Date: Thu, 06 Oct 2005 13:25:30 -0000 To: cvs@cocoon.apache.org From: tcurdt@apache.org X-Mailer: svnmailer-1.0.5 X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: tcurdt Date: Thu Oct 6 06:25:18 2005 New Revision: 306637 URL: http://svn.apache.org/viewcvs?rev=306637&view=rev Log: started refactoring Modified: cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/TreeProcessor.java Modified: cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/TreeProcessor.java URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/TreeProcessor.java?rev=306637&r1=306636&r2=306637&view=diff ============================================================================== --- cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/TreeProcessor.java (original) +++ cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/TreeProcessor.java Thu Oct 6 06:25:18 2005 @@ -16,6 +16,7 @@ package org.apache.cocoon.components.treeprocessor; import java.io.File; +import java.io.IOException; import java.net.URL; import java.util.Collections; import java.util.HashMap; @@ -37,6 +38,7 @@ import org.apache.avalon.framework.service.ServiceManager; import org.apache.avalon.framework.service.Serviceable; import org.apache.avalon.framework.thread.ThreadSafe; +import org.apache.cocoon.ProcessingException; import org.apache.cocoon.Processor; import org.apache.cocoon.components.ContextHelper; import org.apache.cocoon.components.classloader.ClassLoaderFactory; @@ -63,6 +65,7 @@ import org.apache.excalibur.source.Source; import org.apache.excalibur.source.SourceResolver; import org.apache.regexp.RE; +import org.xml.sax.SAXException; /** * Interpreted tree-traversal implementation of a pipeline assembly language. @@ -561,6 +564,69 @@ } + private Configuration createSitemapProgram(Source source) throws ProcessingException, SAXException, IOException { + NamespacedSAXConfigurationHandler handler = new NamespacedSAXConfigurationHandler(); + AnnotationsFilter annotationsFilter = new AnnotationsFilter(handler); + SourceUtil.toSAX(source, annotationsFilter); + return handler.getConfiguration(); + } + + private void subscribeListeners(Map listerens, ConcreteTreeProcessor processor) { + if (getLogger().isDebugEnabled()) { + getLogger().debug("setting up listeners " + listerens); + } + for (final Iterator it = listerens.values().iterator(); it.hasNext();) { + final NotifyingListener newListener = (NotifyingListener) it.next(); + + newListener.setNotificationListener(processor); + + fam.subscribe(newListener); + } + } + + private void unsubscribeListeners(Map listerens) { + if (listerens != null && listerens.size() > 0) { + if (getLogger().isDebugEnabled()) { + getLogger().debug("unsubscribing " + listerens + " from fam"); + } + for (final Iterator it = listerens.values().iterator(); it.hasNext();) { + final FilesystemAlterationListener oldListener = (FilesystemAlterationListener) it.next(); + fam.unsubscribe(oldListener); + } + } + } + + private void waitForInitialCompilation(Map listeners) throws Exception { + if (listeners.size() > 0) { + // wait for the new ones to complete for the first time + for (final Iterator it = listeners.values().iterator(); it.hasNext();) { + final NotifyingListener newListener = (NotifyingListener) it.next(); + if (getLogger().isDebugEnabled()) { + getLogger().debug("waiting for initial compilation"); + } + newListener.waitForFirstCheck(); + } + } + } + + private void provideClasses(Map listeners, ClassLoader classloader) { + for (final Iterator it = listeners.values().iterator(); it.hasNext();) { + final NotifyingListener newListener = (NotifyingListener) it.next(); + + if (newListener instanceof ResourceStoringListener) { + ResourceStoringListener l = (ResourceStoringListener)newListener; + if (classloader instanceof ReloadingClassLoaderFactory.DefaultClassLoader) { + if (getLogger().isDebugEnabled()) { + getLogger().debug("adding store " + l.getStore() + " to classloader"); + } + ReloadingClassLoaderFactory.DefaultClassLoader cl = (ReloadingClassLoaderFactory.DefaultClassLoader) classloader; + cl.addResourceStore(l.getStore()); + } + } + } + } + + /** * Build the concrete processor (i.e. loads the sitemap). Should be called * only by setupProcessor(); @@ -603,11 +669,7 @@ try { - // Build a namespace-aware configuration object - NamespacedSAXConfigurationHandler handler = new NamespacedSAXConfigurationHandler(); - AnnotationsFilter annotationsFilter = new AnnotationsFilter(handler); - SourceUtil.toSAX(this.source, annotationsFilter); - Configuration sitemapProgram = handler.getConfiguration(); + Configuration sitemapProgram = createSitemapProgram(this.source); newLastModified = this.source.getLastModified(); newProcessor = createConcreteTreeProcessor(); @@ -622,52 +684,18 @@ Thread.currentThread().setContextClassLoader(classloader); newListeners = createClasspathListeners(oldListeners, classpathConfig); + newProcessor.setClasspathListeners(newListeners); - if (getLogger().isDebugEnabled()) { - getLogger().debug("setting up listeners " + newListeners); - } - for (final Iterator it = newListeners.values().iterator(); it.hasNext();) { - final NotifyingListener newListener = (NotifyingListener) it.next(); - - newListener.setNotificationListener(newProcessor); - - fam.subscribe(newListener); - - if (newListener instanceof ResourceStoringListener) { - ResourceStoringListener l = (ResourceStoringListener)newListener; - if (classloader instanceof ReloadingClassLoaderFactory.DefaultClassLoader) { - if (getLogger().isDebugEnabled()) { - getLogger().debug("adding store " + l.getStore() + " to classloader"); - } - ReloadingClassLoaderFactory.DefaultClassLoader cl = (ReloadingClassLoaderFactory.DefaultClassLoader) classloader; - cl.addResourceStore(l.getStore()); - } - } - } + subscribeListeners(newListeners, newProcessor); + + provideClasses(newListeners, classloader); } - if (oldListeners != null && oldListeners.size() > 0) { - if (getLogger().isDebugEnabled()) { - getLogger().debug("unsubscribing " + oldListeners + " from fam"); - } - for (final Iterator it = oldListeners.values().iterator(); it.hasNext();) { - final FilesystemAlterationListener oldListener = (FilesystemAlterationListener) it.next(); - fam.unsubscribe(oldListener); - } - } + unsubscribeListeners(oldListeners); + + waitForInitialCompilation(newListeners); - - if (newListeners.size() > 0) { - // wait for the new ones to complete for the first time - for (final Iterator it = newListeners.values().iterator(); it.hasNext();) { - final NotifyingListener newListener = (NotifyingListener) it.next(); - if (getLogger().isDebugEnabled()) { - getLogger().debug("waiting for initial compilation"); - } - newListener.waitForFirstCheck(); - } - } // Get the treebuilder that can handle this version of the sitemap. TreeBuilder treeBuilder = getTreeBuilder(sitemapProgram);