You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by cz...@apache.org on 2006/12/11 15:41:08 UTC

svn commit: r485681 - in /cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/src/main/java/org/apache/cocoon: components/profiler/ profiling/statistics/

Author: cziegeler
Date: Mon Dec 11 06:41:06 2006
New Revision: 485681

URL: http://svn.apache.org/viewvc?view=rev&rev=485681
Log:
Clean up code

Modified:
    cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/src/main/java/org/apache/cocoon/components/profiler/EnvironmentInfo.java
    cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/src/main/java/org/apache/cocoon/components/profiler/Profiler.java
    cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/src/main/java/org/apache/cocoon/components/profiler/ProfilerData.java
    cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/src/main/java/org/apache/cocoon/components/profiler/ProfilerImpl.java
    cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/src/main/java/org/apache/cocoon/components/profiler/ProfilingCachingProcessingPipeline.java
    cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/src/main/java/org/apache/cocoon/components/profiler/ProfilingNonCachingProcessingPipeline.java
    cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/src/main/java/org/apache/cocoon/components/profiler/ProfilingXMLPipe.java
    cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/src/main/java/org/apache/cocoon/profiling/statistics/CollectorImpl.java

Modified: cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/src/main/java/org/apache/cocoon/components/profiler/EnvironmentInfo.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/src/main/java/org/apache/cocoon/components/profiler/EnvironmentInfo.java?view=diff&rev=485681&r1=485680&r2=485681
==============================================================================
--- cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/src/main/java/org/apache/cocoon/components/profiler/EnvironmentInfo.java (original)
+++ cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/src/main/java/org/apache/cocoon/components/profiler/EnvironmentInfo.java Mon Dec 11 06:41:06 2006
@@ -33,43 +33,40 @@
  */
 public class EnvironmentInfo {
 
-  	HashMap requestParameters = new HashMap();
-	  HashMap sessionAttributes = new HashMap();
-  	String uri;
-	  String uriPrefix;
+  	protected Map requestParameters = new HashMap();
+    protected Map sessionAttributes = new HashMap();
+    protected String uri;
 
     public EnvironmentInfo(Environment environment)	{
+        final Map objectModel = environment.getObjectModel();
+        final Request request = ObjectModelHelper.getRequest(objectModel);
+        
+        // make a copy of the request parameters
+        final Enumeration requestParameterNames = request.getParameterNames();
+        while (requestParameterNames.hasMoreElements()) {
+            final String paramName = (String)requestParameterNames.nextElement();
+            final String rawValue = request.getParameter(paramName);
+            final String value = rawValue != null ? rawValue : "null";
+            this.requestParameters.put(paramName, value);
+        }
+
+        // make a copy of the session contents
+        final Session session = request.getSession(false);
+        if (session != null) {
+            final Enumeration sessionAttributeNames = session.getAttributeNames();
+            while (sessionAttributeNames.hasMoreElements()) {
+                final String attrName = (String)sessionAttributeNames.nextElement();
+                final Object rawValue = session.getAttribute(attrName);
+                final String value = rawValue != null ? rawValue.toString() : "null";
+                this.sessionAttributes.put(attrName, value);
+            }
+        }
 
-		    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();
+        this.uri = environment.getURI();
     }
 
     public String getURI() {
-        return uri;
+        return this.uri;
     } 
 
     public Map getRequestParameters() {

Modified: cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/src/main/java/org/apache/cocoon/components/profiler/Profiler.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/src/main/java/org/apache/cocoon/components/profiler/Profiler.java?view=diff&rev=485681&r1=485680&r2=485681
==============================================================================
--- cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/src/main/java/org/apache/cocoon/components/profiler/Profiler.java (original)
+++ cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/src/main/java/org/apache/cocoon/components/profiler/Profiler.java Mon Dec 11 06:41:06 2006
@@ -5,9 +5,9 @@
  * The ASF licenses this file to You under the Apache License, Version 2.0
  * (the "License"); you may not use this file except in compliance with
  * the License.  You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

Modified: cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/src/main/java/org/apache/cocoon/components/profiler/ProfilerData.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/src/main/java/org/apache/cocoon/components/profiler/ProfilerData.java?view=diff&rev=485681&r1=485680&r2=485681
==============================================================================
--- cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/src/main/java/org/apache/cocoon/components/profiler/ProfilerData.java (original)
+++ cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/src/main/java/org/apache/cocoon/components/profiler/ProfilerData.java Mon Dec 11 06:41:06 2006
@@ -5,9 +5,9 @@
  * The ASF licenses this file to You under the Apache License, Version 2.0
  * (the "License"); you may not use this file except in compliance with
  * the License.  You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -30,7 +30,7 @@
     /**
      * Entry, which stores the role and source of a component from a pipeline.
      */
-    public class Entry {
+    public static class Entry {
 
         public String role;
         public String source;
@@ -45,7 +45,7 @@
     }
 
     // List of all entries
-    private ArrayList entries = null;
+    private ArrayList entries;
 
     // Environment information
     private EnvironmentInfo environmentinfo;

Modified: cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/src/main/java/org/apache/cocoon/components/profiler/ProfilerImpl.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/src/main/java/org/apache/cocoon/components/profiler/ProfilerImpl.java?view=diff&rev=485681&r1=485680&r2=485681
==============================================================================
--- cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/src/main/java/org/apache/cocoon/components/profiler/ProfilerImpl.java (original)
+++ cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/src/main/java/org/apache/cocoon/components/profiler/ProfilerImpl.java Mon Dec 11 06:41:06 2006
@@ -40,8 +40,7 @@
 
     private Map results;
 
-    public ProfilerImpl()
-    {
+    public ProfilerImpl() {
         results = new HashMap();
     }
 
@@ -52,24 +51,21 @@
      * @param configuration the class configurations.
      */
     public void configure(Configuration configuration)
-        throws ConfigurationException {
-
+    throws ConfigurationException {
         this.results_count = configuration.getAttributeAsInteger("results", 10);
     }
 
     /**
      * Clear the results.
      */
-    public void clearResults()
-    {
+    public void clearResults() {
         results.clear();
     }
 
     /**
      * Remove the specified result.
      */
-    public void clearResult(Object key)
-    {
+    public void clearResult(Object key) {
         results.remove(key);
     }
 
@@ -78,8 +74,7 @@
      *
      * @return Keys of all results.
      */
-    public Collection getResultKeys()
-    {
+    public Collection getResultKeys() {
         return results.keySet();
     }
 
@@ -88,8 +83,7 @@
      *
      * @return Collection of results.
      */
-    public Collection getResults()
-    {
+    public Collection getResults() {
         return results.values();
     }
 
@@ -99,8 +93,7 @@
      * @param key Key of the result.
      * @return Result of the profiling
      */
-    public ProfilerResult getResult(Object key)
-    {
+    public ProfilerResult getResult(Object key) {
         return (ProfilerResult)results.get(key);
     }
 
@@ -110,8 +103,7 @@
      * @param uri URI of the request
      * @param data Result of the profiling
      */
-    public void addResult(String uri, ProfilerData data)
-    {
+    public void addResult(String uri, ProfilerData data) {
         Long key = new Long(data.getKey(uri));
         ProfilerResult result = (ProfilerResult)results.get(key);
         if(result == null){

Modified: cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/src/main/java/org/apache/cocoon/components/profiler/ProfilingCachingProcessingPipeline.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/src/main/java/org/apache/cocoon/components/profiler/ProfilingCachingProcessingPipeline.java?view=diff&rev=485681&r1=485680&r2=485681
==============================================================================
--- cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/src/main/java/org/apache/cocoon/components/profiler/ProfilingCachingProcessingPipeline.java (original)
+++ cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/src/main/java/org/apache/cocoon/components/profiler/ProfilingCachingProcessingPipeline.java Mon Dec 11 06:41:06 2006
@@ -34,7 +34,8 @@
 /**
  * @version $Id$
  */
-public class ProfilingCachingProcessingPipeline extends CachingProcessingPipeline {
+public class ProfilingCachingProcessingPipeline
+    extends CachingProcessingPipeline {
 
     private Profiler profiler;
 
@@ -43,18 +44,18 @@
     private int index;
 
     /**
-     * Composable
+     * @see org.apache.cocoon.components.pipeline.AbstractProcessingPipeline#service(org.apache.avalon.framework.service.ServiceManager)
      */
-    public void service(ServiceManager manager) throws ServiceException {
-        super.service(manager);
+    public void service(ServiceManager aManager) throws ServiceException {
+        super.service(aManager);
         this.profiler = (Profiler) manager.lookup(Profiler.ROLE);
     }
 
     /**
-     * Disposable
+     * @see org.apache.cocoon.components.pipeline.impl.BaseCachingProcessingPipeline#dispose()
      */
     public void dispose() {
-        if (this.profiler!=null) {
+        if (this.manager != null) {
             this.manager.release(this.profiler);
             this.profiler = null;
         }
@@ -62,7 +63,7 @@
     }
 
     /**
-     * Recyclable
+     * @see org.apache.cocoon.components.pipeline.impl.AbstractCachingProcessingPipeline#recycle()
      */
     public void recycle() {
         this.data = null;
@@ -179,7 +180,7 @@
             Iterator transformerParamItt = this.transformerParams.iterator();
 
             // Setup transformers
-            int index = 1;
+            int localIndex = 1;
             while (transformerItt.hasNext()) {
                 Transformer trans = (Transformer) transformerItt.next();
 
@@ -187,7 +188,7 @@
                 trans.setup(this.processor.getSourceResolver(), environment.getObjectModel(),
                             (String) transformerSourceItt.next(),
                             (Parameters) transformerParamItt.next());
-                this.data.setSetupTime(index++, System.currentTimeMillis() - time);
+                this.data.setSetupTime(localIndex++, System.currentTimeMillis() - time);
             }
 
             // Setup serializer
@@ -200,7 +201,7 @@
                     serializerParam
                 );
             }
-            this.data.setSetupTime(index++, System.currentTimeMillis() - time);
+            this.data.setSetupTime(localIndex++, System.currentTimeMillis() - time);
 
             setMimeTypeForSerializer(environment);
         } catch (SAXException e) {

Modified: cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/src/main/java/org/apache/cocoon/components/profiler/ProfilingNonCachingProcessingPipeline.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/src/main/java/org/apache/cocoon/components/profiler/ProfilingNonCachingProcessingPipeline.java?view=diff&rev=485681&r1=485680&r2=485681
==============================================================================
--- cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/src/main/java/org/apache/cocoon/components/profiler/ProfilingNonCachingProcessingPipeline.java (original)
+++ cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/src/main/java/org/apache/cocoon/components/profiler/ProfilingNonCachingProcessingPipeline.java Mon Dec 11 06:41:06 2006
@@ -48,26 +48,27 @@
 
     private int index;
 
-    /* (non-Javadoc)
-     * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
+    /**
+     * @see org.apache.cocoon.components.pipeline.AbstractProcessingPipeline#service(org.apache.avalon.framework.service.ServiceManager)
      */
-    public void service(ServiceManager manager) throws ServiceException {
-        super.service(manager);
+    public void service(ServiceManager aManager) throws ServiceException {
+        super.service(aManager);
         this.profiler = (Profiler) manager.lookup(Profiler.ROLE);
     }
 
     /**
-     * Disposable
+     * @see org.apache.avalon.framework.activity.Disposable#dispose()
      */
     public void dispose() {
-        if (this.profiler!=null) {
+        if (this.manager != null) {
             this.manager.release(this.profiler);
             this.profiler = null;
+            this.manager = null;
         }
     }
 
     /**
-     * Recyclable
+     * @see org.apache.cocoon.components.pipeline.AbstractProcessingPipeline#recycle()
      */
     public void recycle() {
         this.data = null;
@@ -185,7 +186,7 @@
             Iterator transformerParamItt = this.transformerParams.iterator();
 
             // Setup transformers
-            int index = 1;
+            int localIndex = 1;
             while (transformerItt.hasNext()) {
                 Transformer trans = (Transformer) transformerItt.next();
 
@@ -193,7 +194,7 @@
                 trans.setup(this.processor.getSourceResolver(), environment.getObjectModel(),
                             (String) transformerSourceItt.next(),
                             (Parameters) transformerParamItt.next());
-                this.data.setSetupTime(index++,
+                this.data.setSetupTime(localIndex++,
                                        System.currentTimeMillis()-time);
             }
 
@@ -207,7 +208,7 @@
                     serializerParam
                 );
             }
-            this.data.setSetupTime(index++, System.currentTimeMillis()-time);
+            this.data.setSetupTime(localIndex++, System.currentTimeMillis()-time);
 
             setMimeTypeForSerializer(environment);
         } catch (SAXException e) {

Modified: cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/src/main/java/org/apache/cocoon/components/profiler/ProfilingXMLPipe.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/src/main/java/org/apache/cocoon/components/profiler/ProfilingXMLPipe.java?view=diff&rev=485681&r1=485680&r2=485681
==============================================================================
--- cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/src/main/java/org/apache/cocoon/components/profiler/ProfilingXMLPipe.java (original)
+++ cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/src/main/java/org/apache/cocoon/components/profiler/ProfilingXMLPipe.java Mon Dec 11 06:41:06 2006
@@ -128,8 +128,8 @@
         this.serializer.ignorableWhitespace(c, start, len);
     }
 
-    public void processingInstruction(String target, String data) throws SAXException {
-        this.serializer.processingInstruction(target, data);
+    public void processingInstruction(String target, String d) throws SAXException {
+        this.serializer.processingInstruction(target, d);
     }
 
     public void skippedEntity(String name) throws SAXException {

Modified: cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/src/main/java/org/apache/cocoon/profiling/statistics/CollectorImpl.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/src/main/java/org/apache/cocoon/profiling/statistics/CollectorImpl.java?view=diff&rev=485681&r1=485680&r2=485681
==============================================================================
--- cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/src/main/java/org/apache/cocoon/profiling/statistics/CollectorImpl.java (original)
+++ cocoon/trunk/blocks/cocoon-profiler/cocoon-profiler-impl/src/main/java/org/apache/cocoon/profiling/statistics/CollectorImpl.java Mon Dec 11 06:41:06 2006
@@ -24,20 +24,17 @@
 import java.util.Map;
 
 import org.apache.avalon.framework.activity.Disposable;
-import org.apache.avalon.framework.context.Context;
-import org.apache.avalon.framework.context.ContextException;
-import org.apache.avalon.framework.context.Contextualizable;
-import org.apache.avalon.framework.logger.AbstractLogEnabled;
 import org.apache.avalon.framework.service.ServiceException;
 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.auth.ApplicationUtil;
 import org.apache.cocoon.auth.User;
-import org.apache.cocoon.components.ContextHelper;
 import org.apache.cocoon.environment.ObjectModelHelper;
 import org.apache.cocoon.environment.Request;
 import org.apache.cocoon.environment.Session;
+import org.apache.cocoon.processing.ProcessInfoProvider;
+import org.apache.cocoon.util.AbstractLogEnabled;
 import org.apache.excalibur.store.Store;
 import org.apache.excalibur.store.StoreJanitor;
 
@@ -53,7 +50,7 @@
  */
 public class CollectorImpl
     extends AbstractLogEnabled
-    implements Collector, Store, ThreadSafe, Serviceable, Disposable, Contextualizable {
+    implements Collector, Store, ThreadSafe, Serviceable, Disposable {
 
     private static final String COUNT_ATTRIBUTE = CollectorImpl.class.getName();
 
@@ -72,15 +69,8 @@
     /** The service manager. */
     protected ServiceManager manager;
 
-    /** The component context. */
-    protected Context context;
-
-    /**
-     * @see org.apache.avalon.framework.context.Contextualizable#contextualize(org.apache.avalon.framework.context.Context)
-     */
-    public void contextualize(Context c) throws ContextException {
-        this.context = c;
-    }
+    /** The process info provider. */
+    protected ProcessInfoProvider provider;
 
     /**
      * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
@@ -89,6 +79,7 @@
         this.manager = aManager;
         this.janitor = (StoreJanitor)this.manager.lookup(StoreJanitor.ROLE);
         this.janitor.register(this);
+        this.provider = (ProcessInfoProvider)this.manager.lookup(ProcessInfoProvider.ROLE);
     }
 
     /**
@@ -101,6 +92,8 @@
             }
             this.manager.release(this.janitor);
             this.janitor = null;
+            this.manager.release(this.provider);
+            this.provider = null;
             this.manager = null;
         }
     }
@@ -176,7 +169,7 @@
     }
 
     protected String getRequestKey() {
-        final Map objectModel = ContextHelper.getObjectModel(this.context);
+        final Map objectModel = this.provider.getObjectModel();
         final User user = ApplicationUtil.getUser(objectModel);
         final Request request = ObjectModelHelper.getRequest(objectModel);
         final Session session = request.getSession();