You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by ni...@apache.org on 2002/12/26 15:03:39 UTC

cvs commit: xml-cocoon2/src/blocks/profiler/java/org/apache/cocoon/generation ProfilerGenerator.java

nicolaken    2002/12/26 06:03:39

  Added:       src/blocks/profiler/java/org/apache/cocoon/components/profiler
                        EnvironmentInfo.java Profiler.java
                        ProfilerData.java ProfilerImpl.java
                        ProfilerResult.java
                        ProfilingCachingProcessingPipeline.java
                        ProfilingNonCachingProcessingPipeline.java
                        ProfilingXMLPipe.java
               src/blocks/profiler/conf profiler.component.xmap
                        profiler.xconf profiler.xmap profiler.xroles
               src/blocks/profiler/java/org/apache/cocoon/generation
                        ProfilerGenerator.java
  Log:
  Profiler block.
  
  Revision  Changes    Path
  1.1                  xml-cocoon2/src/blocks/profiler/java/org/apache/cocoon/components/profiler/EnvironmentInfo.java
  
  Index: EnvironmentInfo.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, 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 (INCLU-
   DING, 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 and was  originally created by
   Stefano Mazzocchi  <st...@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.components.profiler;
  
  import org.apache.cocoon.environment.Environment;
  import org.apache.cocoon.environment.Request;
  import org.apache.cocoon.environment.ObjectModelHelper;
  import org.apache.cocoon.environment.Session;
  
  import java.util.HashMap;
  import java.util.Map;
  import java.util.Enumeration;
  
  /**
   * Holds information about the environment (such as request
   * parameters and session attributes) to be stored in the ProfilerData.
   *
   * @author <a href="mailto:bruno@outerthought.org">Bruno Dumon</a>,
   * @version CVS $Id: EnvironmentInfo.java,v 1.1 2002/12/26 14:03:38 nicolaken Exp $
   */
  public class EnvironmentInfo {
  
    	HashMap requestParameters = new HashMap();
  	  HashMap sessionAttributes = new HashMap();
    	String uri;
  	  String uriPrefix;
  
      public EnvironmentInfo(Environment environment)	{
  
  		    Map objectModel = environment.getObjectModel();
      		Request request = ObjectModelHelper.getRequest(objectModel);
  
  		    // make a copy of the request parameters
      		Enumeration requestParameterNames = request.getParameterNames();
  		    while (requestParameterNames.hasMoreElements()) {
        			String paramName = (String)requestParameterNames.nextElement();
        			String rawValue = request.getParameter(paramName);
  			      String value = rawValue != null ? rawValue : "null";
        			requestParameters.put(paramName, value);
  		    }
  
      		// make a copy of the session contents
      		Session session = request.getSession(false);
      		if (session != null) {
        			Enumeration sessionAttributeNames = session.getAttributeNames();
        			while (sessionAttributeNames.hasMoreElements()) {
          				String attrName = (String)sessionAttributeNames.nextElement();
          				Object rawValue = session.getAttribute(attrName);
  				        String value = rawValue != null ? rawValue.toString() : "null";
          				sessionAttributes.put(attrName, value);
  			      }
      		}
  
      		uri = environment.getURI();
  		    uriPrefix = environment.getURIPrefix();
      }
  
      public String getURI() {
          return uri;
      } 
  
      public Map getRequestParameters() {
          return requestParameters;
      }
  
      public Map getSessionAttributes() {
          return sessionAttributes;
      }
  }
  
  
  
  
  1.1                  xml-cocoon2/src/blocks/profiler/java/org/apache/cocoon/components/profiler/Profiler.java
  
  Index: Profiler.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, 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 (INCLU-
   DING, 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 and was  originally created by
   Stefano Mazzocchi  <st...@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.components.profiler;
  
  import org.apache.avalon.framework.component.Component;
  
  import java.util.Collection;
  
  /**
   * Profiler component interface.
   *
   * @author <a href="mailto:vgritsenko@apache.org">Vadim Gritsenko</a>
   * @author <a href="mailto:stephan@apache.org">Stephan Michels</a>
   * @version CVS $Id: Profiler.java,v 1.1 2002/12/26 14:03:38 nicolaken Exp $
   */
  public interface Profiler extends Component
  {
      String ROLE = Profiler.class.getName();
  
      /**
       * Clear the results.
       */
      void clearResults();
  
      /**
       * Remove a specified result.
       *
       * @param key Key of the result.
       */
      void clearResult(Object key);
  
      /**
       * Add a result for a request.
       * 
       * @param uri URI of the request
       * @param data Result of the profiling
       */
      void addResult(String uri, ProfilerData data);
  
      /**
       * Returns a collection of all keys
       *
       * @return Keys of all results.
       */
      Collection getResultKeys();
   
      /**
       * Returns a collection of the results.
       *
       * @return Collection of results.
       */
      Collection getResults();
   
      /**
       * Returns a result of a specifed key.
       *
       * @param key Key of the result.
       * @return Result.
       */
      ProfilerResult getResult(Object key);
  }
  
  
  
  1.1                  xml-cocoon2/src/blocks/profiler/java/org/apache/cocoon/components/profiler/ProfilerData.java
  
  Index: ProfilerData.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, 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 (INCLU-
   DING, 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 and was  originally created by
   Stefano Mazzocchi  <st...@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.components.profiler;
  
  import org.apache.cocoon.util.HashUtil;
  
  import java.util.ArrayList;
  
  /**
   * Request-time profiler information.
   *
   * @author <a href="mailto:vgritsenko@apache.org">Vadim Gritsenko</a>
   * @author <a href="mailto:bruno@outerthought.org">Bruno Dumon</a>
   * @author <a href="mailto:stephan@apache.org">Stephan Michels</a>
   * @version CVS $Id: ProfilerData.java,v 1.1 2002/12/26 14:03:38 nicolaken Exp $
   */
  public class ProfilerData
  {
      /**
       * Entry, which stores the role and source of a component from a pipeline.
       */
      public class Entry
      {
          public String role;
          public String source;
          public long time;
          public Object fragment;
  
          private Entry(String role, String source) {
              this.role = role;
              this.source = source;
          }
      }
  
      // List of all entries
      private ArrayList entries = null;
  
      // Environment information
      private EnvironmentInfo environmentinfo;
  
      // Measured total time
      private long totaltime = 0;
  
      public ProfilerData() {
          entries = new ArrayList();
      }
  
      /**
       * Add new component from the pipeling, which should be measured.
       * 
       * @param component Component of the pipeline.
       * @param role Role of the component.
       * @param source Source attribute of the component.
       */
      public void addComponent(Object component, String role, String source) {
          entries.add(new Entry(role!=null?role:component.getClass().getName(), source));
      }
  
      /**
       * Returns the count of components.
       *
       * @return Count of components.
       */
      public int getCount() {
          return entries.size();
      }
  
      /**
       * Set the environment information.
       *
       * @param environmentinfo Environment information.
       */
      public void setEnvironmentInfo(EnvironmentInfo environmentinfo) {
          this.environmentinfo = environmentinfo;
      }
  
      /**
       * Returns the environment information.
       *
       * @return Environment information.
       */
      public EnvironmentInfo getEnvironmentInfo() {
          return this.environmentinfo;
      }
  
      /**
       * Set measured time of precessing from the pipeline.
       *
       * @param time Total time of all components.
       */
      public void setTotalTime(long time) {
          this.totaltime = time;
      }
  
      /**
       * Return measured time of precessing from the pipeline.
       *
       * @return Total time of all components.
       */
      public long getTotalTime() {
          return this.totaltime;
      }
  
      /**
       * Set measured time of the i-th component of the pipeline.
       *
       * @param index Index of the component.
       * @param time Measured time of the component.
       */
      public void setTime(int index, long time) {
          ((Entry)entries.get(index)).time = time;
      }
  
      /**
       * Get measured time of the i-th component of the pipeline.
       *
       * @return Measured time of the component.
       */
      public long getTime(int index) {
          return ((Entry)entries.get(index)).time;
      }
  
      /**
       * Set the SAX fragment for the i-th component of the pipeline.
       *
       * @param index Index of the component.
       * @param fragment SAX fragment of the component.
       */
      public void setSAXFragment(int index, Object fragment)
      {
          ((Entry)entries.get(index)).fragment = fragment;
      }
  
      /**
       * Returns all measured times.
       *
       * @return Array of all entries.
       */
      public Entry[] getEntries() {
          return (Entry[])entries.toArray(new Entry[entries.size()]);
      }
  
      /**
       * Generate a key for a given URI for this pipeline
       * 
       * @return Hash key.
       */
      public long getKey(String uri)
      {
          StringBuffer key = new StringBuffer(uri);
          for(int i=0; i<entries.size(); i++){
              Entry entry = (Entry)entries.get(i);
  
              key.append(':');
              key.append(entry.role);
              key.append(':');
              key.append(entry.source);
          }
          return HashUtil.hash(key);
      }
  
  /*
      public void report(String uri)
      {
          System.err.println("-------------------------------------------------------------------------------");
          System.err.println("PROFILER DATA FOR: " + uri);
  
          Entry[] entries = getEntries();
          for(int i=0; i<entries.length; i++){
              long time = entries[i].time;
              if(i < entries.length - 1)
                  time -= entries[i+1].time;
              if(entries[i].role == null || entries[i].role.length() == 0)
                  System.err.println("PROFILER DATA: " + time
                      + "\tFOR " + entries[i].component);
              else
                  System.err.println("PROFILER DATA: " + time
                      + "\tFOR " + entries[i].role + "\t" + entries[i].source);
          }
          System.err.println("PROFILER DATA: " + entries[0].time + " TOTAL");
      }
  */
  }
  
  
  
  1.1                  xml-cocoon2/src/blocks/profiler/java/org/apache/cocoon/components/profiler/ProfilerImpl.java
  
  Index: ProfilerImpl.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, 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 (INCLU-
   DING, 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 and was  originally created by
   Stefano Mazzocchi  <st...@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.components.profiler;
  
  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.AbstractLogEnabled;
  import org.apache.avalon.framework.thread.ThreadSafe;
  
  import java.util.Collection;
  import java.util.HashMap;
  import java.util.Map;
  
  /**
   * Profiler component implementation. Stores profiler data for
   * all pipelines.
   *
   * @author <a href="mailto:vgritsenko@apache.org">Vadim Gritsenko</a>
   * @author <a href="mailto:stephan@apache.org">Stephan Michels</a>
   * @version CVS $Id: ProfilerImpl.java,v 1.1 2002/12/26 14:03:38 nicolaken Exp $
   */
  public class ProfilerImpl extends AbstractLogEnabled
      implements Profiler, ThreadSafe, Configurable {
  
      // Maximal count of entries, which should be stored.
      private int results_count = 10;
  
      private Map results;
  
      public ProfilerImpl()
      {
          results = new HashMap();
      }
  
      /**
       * Pass the Configuration to the Configurable class. This method must 
       * always be called after the constructor and before any other method.
       * 
       * @param configuration the class configurations.
       */
      public void configure(Configuration configuration)
          throws ConfigurationException {
  
          this.results_count = configuration.getAttributeAsInteger("results", 10);
      }
  
      /**
       * Clear the results.
       */
      public void clearResults()
      {
          results.clear();
      }
  
      /**
       * Remove the specified result.
       */
      public void clearResult(Object key)
      {
          results.remove(key);
      }
  
      /**
       * Returns a collection of all keys
       *
       * @return Keys of all results.
       */
      public Collection getResultKeys()
      {
          return results.keySet();
      }
  
      /**
       * Returns a collection of the results.
       *
       * @return Collection of results.
       */
      public Collection getResults()
      {
          return results.values();
      }
  
      /**
       * Returns a result of a specifed key.
       *
       * @param key Key of the result.
       * @return Result of the profiling
       */
      public ProfilerResult getResult(Object key)
      {
          return (ProfilerResult)results.get(key);
      }
  
      /** 
       * Add a result for a request.
       * 
       * @param uri URI of the request
       * @param data Result of the profiling
       */
      public void addResult(String uri, ProfilerData data)
      {
          Long key = new Long(data.getKey(uri));
          ProfilerResult result = (ProfilerResult)results.get(key);
          if(result == null){
              synchronized(results){
                  if((result = (ProfilerResult)results.get(key)) == null)
                      results.put(key, result = new ProfilerResult(uri, results_count));
              }
          }
  
          result.addData(data);
      }
  }
  
  
  
  1.1                  xml-cocoon2/src/blocks/profiler/java/org/apache/cocoon/components/profiler/ProfilerResult.java
  
  Index: ProfilerResult.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, 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 (INCLU-
   DING, 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 and was  originally created by
   Stefano Mazzocchi  <st...@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.components.profiler;
  
  
  
  /**
   * A ProfilerResult stores a collection of the lastest n ProfilerDatas 
   * for one pipeline.
   *
   * @author <a href="mailto:vgritsenko@apache.org">Vadim Gritsenko</a>
   * @author <a href="mailto:stephan@apache.org">Stephan Michels</a>
   * @author <a href="mailto:bruno@outerthought.org">Bruno Dumon</a>
   * @version CVS $Id: ProfilerResult.java,v 1.1 2002/12/26 14:03:38 nicolaken Exp $
   */
  public class ProfilerResult {
  
      // URI of the request
      private String uri;
  
      // Roles of the sitemap components
      private String[] roles;
  
      // Sources of the sitemap components
      private String[] sources;
  
      // Count of the ProfilerData entries
      private int count = 0;
  
      // Environment information of each request.
      private EnvironmentInfo[] latestEnvironmentInfo;
  
      // Total times of each request
      private long[] totalTime;
  
      // Times of each component of the latest n-requests
      private long[][] latestTimes;
  
      // SAX fragments of eac component of the latest n-requests
      private Object[][] latestFragments;
  
      public ProfilerResult(String uri, int latestResultsCount) {
          this.uri = uri;
          this.latestEnvironmentInfo = new EnvironmentInfo[(latestResultsCount>0)?latestResultsCount:5];
          this.latestTimes = new long[(latestResultsCount>0)?latestResultsCount:5][];
          this.totalTime = new long[(latestResultsCount>0)?latestResultsCount:5];
          this.latestFragments = new Object[(latestResultsCount>0)?latestResultsCount:5][];
          this.count = 0;
      }
  
      /**
       * Add a new profiler data from a request to the result.
       */
      public void addData(ProfilerData data) {
          ProfilerData.Entry[] entries = data.getEntries();
          synchronized(this){
              if(roles == null || roles.length != entries.length){
                  // Reinitialize arrays about the pipeline
                  roles = new String[entries.length];
                  sources = new String[entries.length];
                  for(int i=0; i<entries.length; i++){
                      roles[i] = entries[i].role;
                      sources[i] = entries[i].source;
                  }
  
                  // Clear counter
                  this.count = 0;
              }
  
              if (latestTimes != null) {
                  // move the current data 
                  for (int i = latestTimes.length - 1; i > 0; i--) {
                      latestEnvironmentInfo[i] = latestEnvironmentInfo[i - 1];
                      totalTime[i] = totalTime[i - 1];
                      latestTimes[i] = latestTimes[i - 1];
                      latestFragments[i] = latestFragments[i - 1];
                  }
                  latestEnvironmentInfo[0] = data.getEnvironmentInfo();
                  totalTime[0] = data.getTotalTime();
                  latestTimes[0] = new long[entries.length];
                  for(int i=0; i<entries.length; i++)
                      this.latestTimes[0][i] = entries[i].time;
                  latestFragments[0] = new Object[entries.length];
                  for(int i=0; i<entries.length; i++)
                      latestFragments[0][i] = entries[i].fragment;
  
                  if (count<latestTimes.length)
                      count++;
              }
          }
      }
  
      /**
       * The URI of the request.
       */
      public String getURI() {
          return uri;
      }
  
      /**
       * Roles of the sitemap components.
       */
      public String[] getRoles() {
          return roles;
      }
  
      /**
       * Sources of the sitemap components.
       */
      public String[] getSources() {
          return sources;
      }
  
      /**
       * Count of the ProfilerData entries
       */
      public int getCount() {
          return count;
      }
  
      /**
       * Environment infomation of the latest n-requests
       */
      public EnvironmentInfo[] getLatestEnvironmentInfos()  {
          return latestEnvironmentInfo;
      }
  
      /**
       * Total times of each request.
       */
      public long[] getTotalTime() {
          return totalTime;
      }
  
      /**
       * Times of each component of the latest n-requests
       */
      public long[][] getLastTimes() {
          return latestTimes;
      }
  
      /**
       * SAX fragment of each component of the latest n-requests
       */
      public Object[][] getLatestSAXFragments() {
          return latestFragments;
      }
    
  /*    public void report()
      {
          System.err.println("-------------------------------------------------------------------------------");
          System.err.println("PROFILER TOTALS FOR: " + uri);
  
          if(totalTime != null){
              long time = 0;
              for(int i=0; i<totalTime.length; i++){
                  System.err.println("PROFILER TOTALS: " + totalTime[i] + "\tFOR " + roles[i] + "\t" + sources[i]);
                  time += totalTime[i];
              }
              System.err.println("PROFILER TOTALS: " + time + " TIMES");
              System.err.println("PROFILER TOTALS: " + count + " REQUESTS");
          }
      }*/
  }
  
  
  
  1.1                  xml-cocoon2/src/blocks/profiler/java/org/apache/cocoon/components/profiler/ProfilingCachingProcessingPipeline.java
  
  Index: ProfilingCachingProcessingPipeline.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, 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 (INCLU-
   DING, 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 and was  originally created by
   Stefano Mazzocchi  <st...@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.components.profiler;
  
  import org.apache.avalon.framework.component.ComponentException;
  import org.apache.avalon.framework.component.ComponentManager;
  import org.apache.avalon.framework.parameters.Parameters;
  import org.apache.cocoon.ProcessingException;
  import org.apache.cocoon.components.pipeline.impl.CachingProcessingPipeline;
  import org.apache.cocoon.environment.Environment;
  import org.apache.cocoon.xml.XMLConsumer;
  import org.apache.cocoon.xml.XMLProducer;
  
  /**
   * @author <a href="mailto:vgritsenko@apache.org">Vadim Gritsenko</a>
   * @author <a href="mailto:stephan@apache.org">Stephan Michels</a>
   * @author <a href="mailto:bruno@outerthought.org">Bruno Dumon</a>
   * @version CVS $Id: ProfilingCachingProcessingPipeline.java,v 1.1 2002/12/26 14:03:38 nicolaken Exp $
   */
  public class ProfilingCachingProcessingPipeline
      extends CachingProcessingPipeline {
  
      private Profiler profiler;
  
      private ProfilerData data = null;
  
      private int index = 0;
  
      /**
       * Composable
       */
      public void compose(ComponentManager manager)
          throws ComponentException {
  
          super.compose(manager);
          this.profiler = (Profiler)manager.lookup(Profiler.ROLE);
      }
  
      /**
       * Disposable
       */
      public void dispose() {
          if (this.profiler != null){
              this.manager.release(this.profiler);
              this.profiler = null;
          }
          super.dispose();
      }
  
      /**
       * Recyclable
       */
      public void recycle() {
          this.data = null;
          super.recycle();
      }
  
      /**
       * Set the generator that will be used as the initial step in the pipeline.
       * The generator role is given : the actual <code>Generator</code> is fetched
       * from the latest <code>ComponentManager</code> given by <code>compose()</code>
       * or <code>recompose()</code>.
       *
       * @param role the generator role in the component manager.
       * @param source the source where to produce XML from, or <code>null</code> if no
       *        source is given.
       * @param param the parameters for the generator.
       * @throws ProcessingException if the generator couldn't be obtained.
       */
      public void setGenerator (String role, String source, Parameters param, Parameters hintParam)
          throws ProcessingException {
  
          super.setGenerator(role, source, param, hintParam);
  
          if(this.data == null)
              this.data = new ProfilerData();
          this.data.addComponent(super.generator, role, source);
      }
  
      /**
       * Add a transformer at the end of the pipeline.
       * The transformer role is given : the actual <code>Transformer</code> is fetched
       * from the latest <code>ComponentManager</code> given by <code>compose()</code>
       * or <code>recompose()</code>.
       *
       * @param role the transformer role in the component manager.
       * @param source the source used to setup the transformer (e.g. XSL file), or
       *        <code>null</code> if no source is given.
       * @param param the parameters for the transfomer.
       * @throws ProcessingException if the generator couldn't be obtained.
       */
      public void addTransformer (String role, String source, Parameters param,  Parameters hintParam)
          throws ProcessingException {
  
          super.addTransformer(role, source, param, hintParam);
  
          if(this.data == null)
              this.data = new ProfilerData();
          this.data.addComponent(super.transformers.get(super.transformers.size()-1), role, source);
      }
  
      /**
       * Set the serializer for this pipeline
       * @param mimeType Can be null
       */
      public void setSerializer (String role, String source, Parameters param, Parameters hintParam, String mimeType)
          throws ProcessingException {
  
          super.setSerializer(role, source, param, hintParam, mimeType);
  
          if(this.data == null)
              this.data = new ProfilerData();
          this.data.addComponent(super.serializer, role, source);
      }
  
      /** 
       * Set the reader for this pipeline
       * @param mimeType Can be null
       */ 
      public void setReader (String role, String source, Parameters param, String mimeType)
          throws ProcessingException {
  
          super.setReader(role, source, param, mimeType);
  
          if(this.data == null)
              this.data = new ProfilerData();
          this.data.addComponent(super.reader, role, source);
      }
  
      /**
       * Process the given <code>Environment</code>, producing the output.
       */
      public boolean process(Environment environment)
          throws ProcessingException {
  
          this.index = 0;
          if (this.data != null) {
  
              // Capture environment info
              this.data.setEnvironmentInfo(new EnvironmentInfo(environment));
  
              // Execute pipeline
              long time = System.currentTimeMillis();
              boolean result = super.process(environment);
              this.data.setTotalTime(System.currentTimeMillis() - time);
  
              // Report
              profiler.addResult(environment.getURI(), this.data);
              return result;
          } else {
  
              getLogger().warn("Profiler Data havn't any components to measure");
              return super.process( environment );
          }
      }
  
      /**
       * Connect the next component
       */
      protected void connect(Environment environment,
                             XMLProducer producer,
                             XMLConsumer consumer)
      throws ProcessingException {
          ProfilingXMLPipe connector = new ProfilingXMLPipe();
          connector.setup(this.index, this.data);
          this.index++;
          super.connect(environment, producer, connector);
          super.connect(environment, connector, consumer);
      }
  
  }
  
  
  
  1.1                  xml-cocoon2/src/blocks/profiler/java/org/apache/cocoon/components/profiler/ProfilingNonCachingProcessingPipeline.java
  
  Index: ProfilingNonCachingProcessingPipeline.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, 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 (INCLU-
   DING, 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 and was  originally created by
   Stefano Mazzocchi  <st...@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.components.profiler;
  
  import org.apache.avalon.framework.activity.Disposable;
  import org.apache.avalon.framework.component.ComponentException;
  import org.apache.avalon.framework.component.ComponentManager;
  import org.apache.avalon.framework.parameters.Parameters;
  import org.apache.cocoon.ProcessingException;
  import org.apache.cocoon.components.pipeline.impl.NonCachingProcessingPipeline;
  import org.apache.cocoon.environment.Environment;
  import org.apache.cocoon.xml.XMLConsumer;
  import org.apache.cocoon.xml.XMLProducer;
  
  /**
   * Special version of the NonCachingProcessingPipeline that supports capturing
   * the SAX-events that go through it and stores the result in the
   * ProfilerData.
   *
   * @author <a href="mailto:vgritsenko@apache.org">Vadim Gritsenko</a>
   * @author <a href="mailto:stephan@apache.org">Stephan Michels</a>
   * @author <a href="mailto:bruno@outerthought.org">Bruno Dumon</a>
   * @version CVS $Id: ProfilingNonCachingProcessingPipeline.java,v 1.1 2002/12/26 14:03:38 nicolaken Exp $
   */
  public class ProfilingNonCachingProcessingPipeline
      extends NonCachingProcessingPipeline
      implements Disposable {
  
      private Profiler profiler;
  
      private ProfilerData data = null;
  
      private int index = 0;
  
      /**
       * Composable
       */
      public void compose(ComponentManager manager)
          throws ComponentException {
  
          super.compose(manager);
          this.profiler = (Profiler)manager.lookup(Profiler.ROLE);
      }
  
      /**
       * Disposable
       */
      public void dispose() {
          if (this.profiler != null){
              this.manager.release(this.profiler);
              this.profiler = null;
          }
      }
  
      /**
       * Recyclable
       */
      public void recycle() {
          this.data = null;
          super.recycle();
      }
  
      /**
       * Set the generator that will be used as the initial step in the pipeline.
       * The generator role is given : the actual <code>Generator</code> is fetched
       * from the latest <code>ComponentManager</code> given by <code>compose()</code>
       * or <code>recompose()</code>.
       *
       * @param role the generator role in the component manager.
       * @param source the source where to produce XML from, or <code>null</code> if no
       *        source is given.
       * @param param the parameters for the generator.
       * @throws ProcessingException if the generator couldn't be obtained.
       */
      public void setGenerator (String role, String source, Parameters param, Parameters hintParam)
          throws ProcessingException {
  
          super.setGenerator(role, source, param, hintParam);
  
          if(this.data == null)
              this.data = new ProfilerData();
          this.data.addComponent(super.generator, role, source);
      }
      
      /**
       * Add a transformer at the end of the pipeline.
       * The transformer role is given : the actual <code>Transformer</code> is fetched
       * from the latest <code>ComponentManager</code> given by <code>compose()</code>
       * or <code>recompose()</code>.
       *
       * @param role the transformer role in the component manager.
       * @param source the source used to setup the transformer (e.g. XSL file), or
       *        <code>null</code> if no source is given.
       * @param param the parameters for the transfomer.
       * @throws ProcessingException if the generator couldn't be obtained.
       */
      public void addTransformer (String role, String source, Parameters param,  Parameters hintParam)
          throws ProcessingException {
  
          super.addTransformer(role, source, param, hintParam);
  
          if(this.data == null)
              this.data = new ProfilerData();
          this.data.addComponent(super.transformers.get(super.transformers.size()-1), role, source);
      }
  
      /**
       * Set the serializer for this pipeline
       * @param mimeType Can be null
       */
      public void setSerializer (String role, String source, Parameters param, Parameters hintParam, String mimeType)
          throws ProcessingException {
  
          super.setSerializer(role, source, param, hintParam, mimeType);
  
          if(this.data == null)
              this.data = new ProfilerData();
          this.data.addComponent(super.serializer, role, source);
      }
  
      /** 
       * Set the reader for this pipeline
       * @param mimeType Can be null
       */
      public void setReader (String role, String source, Parameters param, String mimeType)
          throws ProcessingException {
  
          super.setReader(role, source, param, mimeType);
  
          if(this.data == null)
              this.data = new ProfilerData();
          this.data.addComponent(super.reader, role, source);
      }
  
      /**
       * Process the given <code>Environment</code>, producing the output.
       */
      public boolean process(Environment environment)
          throws ProcessingException {
  
          this.index = 0;
          if (this.data != null) {
  
              // Capture environment info
              this.data.setEnvironmentInfo(new EnvironmentInfo(environment));
  
              // Execute pipeline
              long time = System.currentTimeMillis();
              boolean result = super.process(environment);
              this.data.setTotalTime(System.currentTimeMillis() - time);
  
              // Report
              profiler.addResult(environment.getURI(), this.data);
              return result;
          } else {
  
              getLogger().warn("Profiler Data havn't any components to measure");
              return super.process( environment );
          }
      }
  
      /**
       * Connect the next component
       */
      protected void connect(Environment environment,
                             XMLProducer producer,
                             XMLConsumer consumer)
      throws ProcessingException {
          ProfilingXMLPipe connector = new ProfilingXMLPipe();
          connector.setup(this.index, this.data);
          this.index++;
          super.connect(environment, producer, connector);
          super.connect(environment, connector, consumer);
      }
  
  }
  
  
  
  1.1                  xml-cocoon2/src/blocks/profiler/java/org/apache/cocoon/components/profiler/ProfilingXMLPipe.java
  
  Index: ProfilingXMLPipe.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, 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 (INCLU-
   DING, 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 and was  originally created by
   Stefano Mazzocchi  <st...@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.components.profiler;
  
  import org.apache.cocoon.components.sax.XMLByteStreamCompiler;
  import org.apache.cocoon.components.sax.XMLByteStreamInterpreter;
  import org.apache.cocoon.components.sax.XMLDeserializer;
  import org.apache.cocoon.components.sax.XMLSerializer;
  import org.apache.cocoon.xml.XMLConsumer;
  import org.apache.cocoon.xml.XMLPipe;
  import org.xml.sax.Attributes;
  import org.xml.sax.Locator;
  import org.xml.sax.SAXException;
  
  /**
   * This SAX connector measures time taken by each Sitemap component. This
   * class use the XMLSerializer/Interpreter to buffer the output, and to
   * seperate the measurement of the time. The SAX fragments were also stored
   * into the ProfilerData.
   *
   * @author <a href="mailto:stephan@apache.org">Stephan Michels</a>
   * @author <a href="mailto:bruno@outerthought.org">Bruno Dumon</a>
   * @version CVS $Id: ProfilingXMLPipe.java,v 1.1 2002/12/26 14:03:38 nicolaken Exp $
   */
  public class ProfilingXMLPipe implements XMLPipe {
  
      private XMLConsumer consumer;
  
      // Data of the profile
      private ProfilerData data;
  
      // Index of the component
      private int index;
  
      // Start time
      private long time;
  
      // Time difference
      private long total;
  
      private XMLDeserializer deserializer;
      private XMLSerializer serializer;
  
      /**
       * Setup this XMLPipe.
       *
       * @param index Index of the component.
       * @param data Data of the profile.
       */
      public void setup(int index, ProfilerData data) {
          this.index = index;
          this.data = data;
  
          // FIXME Retrieve components from the CM
          this.deserializer = new XMLByteStreamInterpreter();
          this.serializer = new XMLByteStreamCompiler();
      }
  
      /**
       * Set the <code>XMLConsumer</code> that will receive XML data.
       */
      public void setConsumer(XMLConsumer consumer) {
          this.consumer = consumer;
      }
  
      public void startDocument() throws SAXException {
          this.time = System.currentTimeMillis(); // Startup time
  
          this.serializer.startDocument();
      }
  
      public void endDocument() throws SAXException {
          this.total = System.currentTimeMillis() - this.time;
  
          this.serializer.endDocument();
          if (this.index != -1)
              this.data.setTime(this.index, this.total);
  
          // push the content of the buffer through the next component
          Object fragment = this.serializer.getSAXFragment();
  
          if (this.index != -1)
              this.data.setSAXFragment(this.index, fragment);
  
          this.deserializer.setConsumer(this.consumer);
  
          this.time = System.currentTimeMillis(); // Startup time
          this.deserializer.deserialize(fragment);
          this.total = System.currentTimeMillis() - this.time;
  
          if ((this.index != -1) && (this.index==(this.data.getCount()-2)))
              this.data.setTime(this.index+1, this.total);
      }
  
      public void setDocumentLocator(Locator locator) {
          this.serializer.setDocumentLocator(locator);
      }
  
      public void startPrefixMapping(String prefix, String uri) throws SAXException {
          this.serializer.startPrefixMapping(prefix, uri);
      }
  
      public void endPrefixMapping(String prefix) throws SAXException {
          this.serializer.endPrefixMapping(prefix);
      }
  
      public void startElement(String uri, String loc, String raw, Attributes a) throws SAXException {
          this.serializer.startElement(uri, loc, raw, a);
      }
  
      public void endElement(String uri, String loc, String raw) throws SAXException {
          this.serializer.endElement(uri, loc, raw);
      }
  
      public void characters(char c[], int start, int len) throws SAXException {
          this.serializer.characters(c, start, len);
      }
  
      public void ignorableWhitespace(char c[], int start, int len) throws SAXException {
          this.serializer.ignorableWhitespace(c, start, len);
      }
  
      public void processingInstruction(String target, String data) throws SAXException {
          this.serializer.processingInstruction(target, data);
      }
  
      public void skippedEntity(String name) throws SAXException {
          this.serializer.skippedEntity(name);
      }
  
      public void startDTD(String name, String publicId, String systemId) throws SAXException {
          this.serializer.startDTD(name, publicId, systemId);
      }
  
      public void endDTD() throws SAXException {
          this.serializer.endDTD();
      }
  
      public void startEntity(String name) throws SAXException {
          this.serializer.startEntity(name);
      }
  
      public void endEntity(String name) throws SAXException {
          this.serializer.endEntity(name);
      }
  
      public void startCDATA() throws SAXException {
          this.serializer.startCDATA();
      }
  
      public void endCDATA() throws SAXException {
          this.serializer.endCDATA();
      }
  
      public void comment(char ch[], int start, int len) throws SAXException {
          this.serializer.comment(ch, start, len);
      }
  }
  
  
  
  1.1                  xml-cocoon2/src/blocks/profiler/conf/profiler.component.xmap
  
  Index: profiler.component.xmap
  ===================================================================
  <?xml version="1.0"?>
  <xmap xpath="/sitemap/components/pipelines" unless="pipeline[@name='profile-caching']">
       <!-- The following two can be used for profiling:-->
       <map:pipeline name="profile-caching"
                     src="org.apache.cocoon.components.profiler.ProfilingCachingProcessingPipeline"/>
       <map:pipeline name="profile-noncaching"
                     src="org.apache.cocoon.components.profiler.ProfilingNonCachingProcessingPipeline"/>
  </xmap>
  
  
  
  1.1                  xml-cocoon2/src/blocks/profiler/conf/profiler.xconf
  
  Index: profiler.xconf
  ===================================================================
  <?xml version="1.0"?>
  <xconf xpath="/cocoon" unless="profiler">
  
    <!-- Profiler:
      The profiler facilitates the gathering of statistics about timings of
      different steps of pipelines. Profiler consists of several components:
       profiling pipeline and profiler generator
      which are used to generate the profile report. You need to enable all of
      these components to use profiler.
      -->
    <profiler results="10"/>
  </xconf>
  
  
  
  1.1                  xml-cocoon2/src/blocks/profiler/conf/profiler.xmap
  
  Index: profiler.xmap
  ===================================================================
  <?xml version="1.0"?>
  <xmap xpath="/sitemap/components/generators" unless="generator[@name='profiler']">
      <map:generator label="content,data" logger="sitemap.generator.profiler" name="profiler" src="org.apache.cocoon.generation.ProfilerGenerator"/>
  </xmap>
  
  
  1.1                  xml-cocoon2/src/blocks/profiler/conf/profiler.xroles
  
  Index: profiler.xroles
  ===================================================================
  <?xml version="1.0"?>
  <xroles xpath="/role-list" unless="role[@name='org.apache.cocoon.components.profiler.Profiler']">
  
    <role name="org.apache.cocoon.components.profiler.Profiler"
          shorthand="profiler"
          default-class="org.apache.cocoon.components.profiler.ProfilerImpl"/>
  </xroles>
  
  
  
  1.1                  xml-cocoon2/src/blocks/profiler/java/org/apache/cocoon/generation/ProfilerGenerator.java
  
  Index: ProfilerGenerator.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, 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 (INCLU-
   DING, 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 and was  originally created by
   Stefano Mazzocchi  <st...@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.generation;
  
  import org.apache.avalon.framework.component.ComponentException;
  import org.apache.avalon.framework.component.ComponentManager;
  import org.apache.avalon.framework.parameters.Parameters;
  import org.apache.cocoon.ProcessingException;
  import org.apache.cocoon.components.profiler.EnvironmentInfo;
  import org.apache.cocoon.components.profiler.Profiler;
  import org.apache.cocoon.components.profiler.ProfilerResult;
  import org.apache.cocoon.components.sax.XMLDeserializer;
  import org.apache.cocoon.environment.ObjectModelHelper;
  import org.apache.cocoon.environment.Request;
  import org.apache.cocoon.environment.SourceResolver;
  import org.apache.cocoon.xml.IncludeXMLConsumer;
  import org.xml.sax.SAXException;
  import org.xml.sax.helpers.AttributesImpl;
  
  import java.io.IOException;
  import java.text.DateFormat;
  import java.util.Collection;
  import java.util.Date;
  import java.util.Iterator;
  import java.util.Map;
  import java.util.Set;
  
  /**
   * Generates an XML representation of the current status of Profiler.
   *
   * @author <a href="mailto:vgritsenko@apache.org">Vadim Gritsenko</a>
   * @author <a href="mailto:bruno@outerthought.org">Bruno Dumon</a>
   * @author <a href="mailto:stephan@apache.org">Stephan Michels</a>
   * @version CVS $Id: ProfilerGenerator.java,v 1.1 2002/12/26 14:03:39 nicolaken Exp $
   */
  public class ProfilerGenerator extends ComposerGenerator {
  
      /**
       * The XML PROFILER_NS for the output document.
       */
      protected static final String PROFILER_NS = "http://apache.org/cocoon/profiler/1.0";
  
      protected static final String PROFILERINFO_ELEMENT = "profilerinfo";
      protected static final String RESULTS_ELEMENT = "pipeline";
      protected static final String RESULT_ELEMENT = "result";
      protected static final String AVERAGERESULT_ELEMENT = "average";
      protected static final String ENVIROMENTINFO_ELEMENT = "environmentinfo";
      protected static final String REQUESTPARAMETERS_ELEMENT = "request-parameters";
      protected static final String REQUESTPARAMETER_ELEMENT = "parameter";
      protected static final String SESSIONATTRIBUTES_ELEMENT = "session-attributes";
      protected static final String SESSIONATTRIBUTE_ELEMENT = "attribute";
      protected static final String COMPONENT_ELEMENT = "component";
      protected static final String FRAGMENT_ELEMENT = "fragment";
      
  
      private Profiler profiler;
  
      // the key identifying the ProfilerResult
      protected Long key = null;
  
      // Index of the result of latest results 
      protected int resultIndex = -1;
  
      // Index of the componen of the latest results
      protected int componentIndex = -1;
  
      /**
       * Composable
       */
      public void compose(ComponentManager manager)
      throws ComponentException {
          super.compose(manager);
          this.profiler = (Profiler)super.manager.lookup(Profiler.ROLE);
      }
  
      public void setup(SourceResolver resolver, Map objectModel, String soure, Parameters parameters) 
          throws ProcessingException, SAXException, IOException {
  
          super.setup(resolver, objectModel, source, parameters);
          Request request = ObjectModelHelper.getRequest(objectModel);
  
          if (request.getParameter("key")!=null)
              this.key = new Long(Long.parseLong(request.getParameter("key")));
          else
              this.key = null;
  
          if ((request.getParameter("result")!=null) && (this.key!=null))
              this.resultIndex = Integer.parseInt(request.getParameter("result"));
          else
              this.resultIndex = -1;
  
          if ((request.getParameter("component")!=null) && (this.resultIndex!=-1))
              this.componentIndex = Integer.parseInt(request.getParameter("component"));
          else
              this.componentIndex = -1;
      }
  
      /**
       * Disposable
       */
      public void dispose() {
          if (this.profiler != null){
              super.manager.release(this.profiler);
              this.profiler = null;
          }
          super.dispose();
      }
  
      /**
       * Generate the status information in XML format.
       * @throws SAXException
       *         when there is a problem creating the output SAX events.
       */
      public void generate() throws SAXException {
  
          // Start the document and set the PROFILER_NS.
          this.contentHandler.startDocument();
          this.contentHandler.startPrefixMapping("", PROFILER_NS);
  
          generateProfilerInfo();
  
          // End the document.
          this.contentHandler.endPrefixMapping("");
          this.contentHandler.endDocument();
      }
  
      /** Generate the main status document. */
      private void generateProfilerInfo() throws SAXException {
          // Root element.
  
          // The current date and time.
          String dateTime = DateFormat.getDateTimeInstance().format(new Date());
  
          AttributesImpl atts = new AttributesImpl();
          atts.addAttribute(PROFILER_NS, "date", "date", "CDATA", dateTime);
          this.contentHandler.startElement(PROFILER_NS, PROFILERINFO_ELEMENT, PROFILERINFO_ELEMENT, atts);
  
          Collection resultsKeys = profiler.getResultKeys();
          for(Iterator i = resultsKeys.iterator(); i.hasNext();) {
              Long key = (Long)i.next();
              if ((this.key==null) || (this.key.equals(key)))
                  generateResults(key, profiler.getResult(key));
          }
  
          // End root element.
          this.contentHandler.endElement(PROFILER_NS, PROFILERINFO_ELEMENT, PROFILERINFO_ELEMENT);
      }
  
      private void generateResults(Long key, ProfilerResult result) throws SAXException {
          AttributesImpl atts = new AttributesImpl();
  
          int count = result.getCount();
          String[] roles = result.getRoles(); // Roles of the components
          String[] sources = result.getSources(); // Source of the components
          
          EnvironmentInfo[] environmentInfos = result.getLatestEnvironmentInfos();
          long[] totalTime = result.getTotalTime(); // Total time of the requests
          long[][] timeOfComponents = result.getLastTimes(); // Time of each component
          Object[][] fragments = result.getLatestSAXFragments(); // SAX Fragments of each component
  
          // Total time of all requests
          long totalTimeSum = 0; 
          for(int i=0; i < count; i++)
              totalTimeSum += totalTime[i];
  
          atts.addAttribute(PROFILER_NS, "uri", "uri", "CDATA", result.getURI());
          atts.addAttribute(PROFILER_NS, "count", "count", "CDATA", Integer.toString(result.getCount()));
          atts.addAttribute(PROFILER_NS, "time", "time", "CDATA", Long.toString(totalTimeSum));
          atts.addAttribute(PROFILER_NS, "key", "key", "CDATA", key.toString());
          this.contentHandler.startElement(PROFILER_NS, RESULTS_ELEMENT, RESULTS_ELEMENT, atts);
          atts.clear();
  
          // Generate average result 
          if ((count > 0) && (this.resultIndex==-1)) {
              atts.addAttribute(PROFILER_NS, "time", "time", "CDATA", Long.toString(totalTimeSum / count));
              this.contentHandler.startElement(PROFILER_NS, AVERAGERESULT_ELEMENT, AVERAGERESULT_ELEMENT, atts);
              atts.clear();
  
              // Total time of each component for all requests
              long[] totalTimeOfComponents = new long[roles.length]; 
            
              for(int i=0; i<roles.length; i++) {
                  totalTimeOfComponents[i] = 0;
                  for(int j=0; j<count; j++) {
                      totalTimeOfComponents[i] += timeOfComponents[j][i];
                  }
              }
  
              for(int i=0; i<roles.length; i++){
                  atts.addAttribute(PROFILER_NS, "offset", "offset", "CDATA", String.valueOf(i));
  
                  if(roles[i] != null)
                      atts.addAttribute(PROFILER_NS, "role", "role", "CDATA", roles[i]);
  
                  if(sources[i] != null)
                      atts.addAttribute(PROFILER_NS, "source", "source", "CDATA", sources[i]);
  
                  atts.addAttribute(PROFILER_NS, "time", "time", "CDATA", 
                                    Long.toString(totalTimeOfComponents[i] / count));
  
                  this.contentHandler.startElement(PROFILER_NS, COMPONENT_ELEMENT, COMPONENT_ELEMENT, atts);
                  atts.clear();
                  this.contentHandler.endElement(PROFILER_NS, COMPONENT_ELEMENT, COMPONENT_ELEMENT);
              }
              this.contentHandler.endElement(PROFILER_NS, AVERAGERESULT_ELEMENT, AVERAGERESULT_ELEMENT);
          }
  
          for(int j=0; j<count; j++) {
              if ((this.resultIndex==-1) || (this.resultIndex==j))
                  generateResult(j, roles, sources, environmentInfos[j], 
                                 totalTime[j], timeOfComponents[j], fragments[j]);
          }
  
          this.contentHandler.endElement(PROFILER_NS, RESULTS_ELEMENT, RESULTS_ELEMENT);
      }
  
      private void generateResult(int resultIndex, String[] roles, String[] sources, 
                                  EnvironmentInfo environmentInfo,
                                  long totaltime, long[] times, Object[] fragments) throws SAXException  {
   
          AttributesImpl atts = new AttributesImpl();
          atts.addAttribute(PROFILER_NS, "time", "time", "CDATA", Long.toString(totaltime));
          atts.addAttribute(PROFILER_NS, "index", "index", "CDATA", String.valueOf(resultIndex));
          this.contentHandler.startElement(PROFILER_NS, RESULT_ELEMENT, RESULT_ELEMENT, atts);
          atts.clear();
  
          if (this.resultIndex!=-1)
              generateEnvironmentInfo(environmentInfo);
  
          for(int i=0; i<roles.length; i++) {
              generateComponent(i, roles[i], sources[i], times[i], fragments[i]);
          }
          this.contentHandler.endElement(PROFILER_NS, RESULT_ELEMENT, RESULT_ELEMENT);
      }
  
      private void generateComponent(int componentIndex, String role, String source, long time, Object fragment) 
          throws SAXException  {
  
          AttributesImpl atts = new AttributesImpl();
  
          atts.addAttribute(PROFILER_NS, "index", "index", "CDATA", String.valueOf(componentIndex));
  
          if (role != null)
              atts.addAttribute(PROFILER_NS, "role", "role", "CDATA", role);
  
          if (source != null)
              atts.addAttribute(PROFILER_NS, "source", "source", "CDATA", source);
  
          atts.addAttribute(PROFILER_NS, "time", "time", "CDATA", Long.toString(time));
  
          this.contentHandler.startElement(PROFILER_NS, COMPONENT_ELEMENT, COMPONENT_ELEMENT, atts);
          atts.clear();
  
          if (this.componentIndex==componentIndex)
              generateSAXFragment(fragment);
  
          this.contentHandler.endElement(PROFILER_NS, COMPONENT_ELEMENT, COMPONENT_ELEMENT);
      }
  
      private void generateEnvironmentInfo(EnvironmentInfo environmentInfo) throws SAXException  {
          this.contentHandler.startElement(PROFILER_NS, ENVIROMENTINFO_ELEMENT, ENVIROMENTINFO_ELEMENT, 
                                           new AttributesImpl());
  
          if (environmentInfo != null) {
              // Generate SAX events for the request parameters
              this.contentHandler.startElement(PROFILER_NS, REQUESTPARAMETERS_ELEMENT, REQUESTPARAMETERS_ELEMENT, 
                                          new AttributesImpl());
  
              Map requestParameters = environmentInfo.getRequestParameters();
              Set requestParamEntries = requestParameters.entrySet();
              Iterator requestParamEntriesIt = requestParamEntries.iterator();
              while (requestParamEntriesIt.hasNext()) {
                  AttributesImpl atts = new AttributesImpl();
                  Map.Entry entry = (Map.Entry)requestParamEntriesIt.next();
                  atts.addAttribute(PROFILER_NS, "name", "name", "CDATA", (String)entry.getKey());
                  atts.addAttribute(PROFILER_NS, "value", "value", "CDATA", (String)entry.getValue());
                  this.contentHandler.startElement(PROFILER_NS, REQUESTPARAMETER_ELEMENT, 
                                                   REQUESTPARAMETER_ELEMENT, atts);
                  this.contentHandler.endElement(PROFILER_NS, REQUESTPARAMETER_ELEMENT, 
                                                 REQUESTPARAMETER_ELEMENT);
              }
              this.contentHandler.endElement(PROFILER_NS, REQUESTPARAMETERS_ELEMENT, REQUESTPARAMETERS_ELEMENT);
  
              // Generate SAX events for the session attributes
              this.contentHandler.startElement(PROFILER_NS, SESSIONATTRIBUTES_ELEMENT, SESSIONATTRIBUTES_ELEMENT, 
                                          new AttributesImpl());
  
              Map sessionAttributes = environmentInfo.getSessionAttributes();
              Set sessionAttrEntries = sessionAttributes.entrySet();
              Iterator sessionAttrEntriesIt = sessionAttrEntries.iterator();
              while (sessionAttrEntriesIt.hasNext()) {
                  AttributesImpl atts = new AttributesImpl();
                  Map.Entry entry = (Map.Entry)sessionAttrEntriesIt.next();
                  atts.addAttribute(PROFILER_NS, "name", "name", "CDATA", (String)entry.getKey());
                  atts.addAttribute(PROFILER_NS, "value", "value", "CDATA", (String)entry.getValue());
                  this.contentHandler.startElement(PROFILER_NS, SESSIONATTRIBUTE_ELEMENT, 
                                                   SESSIONATTRIBUTE_ELEMENT, atts);
                  this.contentHandler.endElement(PROFILER_NS, SESSIONATTRIBUTE_ELEMENT, 
                                                 SESSIONATTRIBUTE_ELEMENT);
              }
              this.contentHandler.endElement(PROFILER_NS, SESSIONATTRIBUTES_ELEMENT, SESSIONATTRIBUTES_ELEMENT);
  
              // And the rest
              this.contentHandler.startElement(PROFILER_NS, "uri", "uri", new AttributesImpl());
              this.contentHandler.characters(environmentInfo.getURI().toCharArray(), 0, 
                                             environmentInfo.getURI().length());
              this.contentHandler.endElement(PROFILER_NS, "uri", "uri");
          }
  
          this.contentHandler.endElement(PROFILER_NS, ENVIROMENTINFO_ELEMENT, ENVIROMENTINFO_ELEMENT);
      }
  
      public void generateSAXFragment(Object fragment) throws SAXException {
  
          if (fragment!=null) {
  
              this.contentHandler.startElement(PROFILER_NS, FRAGMENT_ELEMENT, FRAGMENT_ELEMENT, 
                                               new AttributesImpl());
  
              XMLDeserializer deserializer = null;
              try {
                  deserializer = (XMLDeserializer)this.manager.lookup(XMLDeserializer.ROLE);
                  deserializer.setConsumer(new IncludeXMLConsumer(this.xmlConsumer));
                  deserializer.deserialize(fragment);
              } catch (ComponentException ce) {
                  getLogger().debug("Could not retrieve XMLDeserializer component", ce);
                  throw new SAXException("Could not retrieve XMLDeserializer component", ce);
              } catch (Exception e) {
                  getLogger().debug("Could not serialize SAX fragment", e);
                  throw new SAXException("Could not serialize SAX fragment", e);
              } finally { 
                  if (deserializer!=null)
                      this.manager.release(deserializer);
              }
  
              this.contentHandler.endElement(PROFILER_NS, FRAGMENT_ELEMENT, FRAGMENT_ELEMENT);
          }
      }
  }
  
  
  
  

----------------------------------------------------------------------
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