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 2004/06/09 15:43:04 UTC
cvs commit: cocoon-2.1/src/blocks/profiler/java/org/apache/cocoon/components/profiler SimpleSitemapExecutor.java
cziegeler 2004/06/09 06:43:04
Modified: src/java/org/apache/cocoon/sitemap SitemapExecutor.java
src/java/org/apache/cocoon/sitemap/impl DefaultExecutor.java
src/java/org/apache/cocoon/components/treeprocessor/sitemap
CallNode.java
src/java/org/apache/cocoon/components/treeprocessor
AbstractParentProcessingNode.java
Added: src/blocks/profiler/java/org/apache/cocoon/components/profiler
SimpleSitemapExecutor.java
Log:
Support for context stack and a simple profiler
Revision Changes Path
1.2 +18 -1 cocoon-2.1/src/java/org/apache/cocoon/sitemap/SitemapExecutor.java
Index: SitemapExecutor.java
===================================================================
RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/sitemap/SitemapExecutor.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- SitemapExecutor.java 9 Jun 2004 11:59:23 -0000 1.1
+++ SitemapExecutor.java 9 Jun 2004 13:43:04 -0000 1.2
@@ -50,4 +50,21 @@
Parameters resolvedParams )
throws Exception;
+
+ /**
+ * Push map of information on the context stack.
+ * @param context The execution context
+ * @param key A key that can be used to identify this map (can be null)
+ * @param variables The variables as key/value pairs
+ * @return The variables that are used in the sitemap. The executor can
+ * modify the set of available variables by returning a different
+ * map.
+ */
+ Map pushVariables(ExecutionContext context, String key, Map variables);
+
+ /**
+ * Pop a map of information from the context stack.
+ * @param context The execution context
+ */
+ void popVariables(ExecutionContext context);
}
1.2 +14 -1 cocoon-2.1/src/java/org/apache/cocoon/sitemap/impl/DefaultExecutor.java
Index: DefaultExecutor.java
===================================================================
RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/sitemap/impl/DefaultExecutor.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- DefaultExecutor.java 9 Jun 2004 11:59:23 -0000 1.1
+++ DefaultExecutor.java 9 Jun 2004 13:43:04 -0000 1.2
@@ -50,4 +50,17 @@
resolvedSource, resolvedParams);
}
+ /* (non-Javadoc)
+ * @see org.apache.cocoon.sitemap.SitemapExecutor#popVariables()
+ */
+ public void popVariables(ExecutionContext context) {
+ // nothing to do
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.cocoon.sitemap.SitemapExecutor#pushVariables(java.lang.String, java.util.Map)
+ */
+ public Map pushVariables(ExecutionContext context, String key, Map variables) {
+ return variables;
+ }
}
1.4 +18 -2 cocoon-2.1/src/java/org/apache/cocoon/components/treeprocessor/sitemap/CallNode.java
Index: CallNode.java
===================================================================
RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/components/treeprocessor/sitemap/CallNode.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- CallNode.java 9 Jun 2004 11:59:23 -0000 1.3
+++ CallNode.java 9 Jun 2004 13:43:04 -0000 1.4
@@ -58,10 +58,16 @@
super(null);
}
+ /* (non-Javadoc)
+ * @see org.apache.avalon.framework.component.Composable#compose(org.apache.avalon.framework.component.ComponentManager)
+ */
public void compose(ComponentManager manager) throws ComponentException {
this.manager = manager;
}
+ /* (non-Javadoc)
+ * @see org.apache.cocoon.components.treeprocessor.ParameterizableProcessingNode#setParameters(java.util.Map)
+ */
public void setParameters(Map parameterMap) {
this.parameters = parameterMap;
}
@@ -71,6 +77,9 @@
this.resources = resources;
}
+ /* (non-Javadoc)
+ * @see org.apache.avalon.framework.activity.Initializable#initialize()
+ */
public void initialize() throws Exception {
if (VariableResolverFactory.needsResolve(this.resourceName)) {
// Will always be resolved at invoke time
@@ -81,6 +90,9 @@
}
}
+ /* (non-Javadoc)
+ * @see org.apache.cocoon.components.treeprocessor.ProcessingNode#invoke(org.apache.cocoon.environment.Environment, org.apache.cocoon.components.treeprocessor.InvokeContext)
+ */
public final boolean invoke(Environment env, InvokeContext context)
throws Exception {
@@ -91,11 +103,13 @@
if (this.resourceNode != null) {
// Static resource name
- context.pushMap(null,params);
+ params = this.executor.pushVariables(this, null, params);
+ context.pushMap(null, params);
try {
return this.resourceNode.invoke(env, context);
} finally {
+ this.executor.popVariables(this);
context.popMap();
}
@@ -107,11 +121,13 @@
}
// and only now push the parameters
+ params = this.executor.pushVariables(this, null, params);
context.pushMap(null,params);
try {
return this.resources.invokeByName(name, env, context);
} finally {
+ this.executor.popVariables(this);
context.popMap();
}
}
1.5 +4 -3 cocoon-2.1/src/java/org/apache/cocoon/components/treeprocessor/AbstractParentProcessingNode.java
Index: AbstractParentProcessingNode.java
===================================================================
RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/components/treeprocessor/AbstractParentProcessingNode.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- AbstractParentProcessingNode.java 9 Jun 2004 11:59:23 -0000 1.4
+++ AbstractParentProcessingNode.java 9 Jun 2004 13:43:04 -0000 1.5
@@ -49,6 +49,7 @@
Map currentMap)
throws Exception {
+ currentMap = this.executor.pushVariables(this, currentName, currentMap);
context.pushMap(currentName,currentMap);
try {
@@ -58,8 +59,8 @@
return true;
}
}
- }
- finally {
+ } finally {
+ this.executor.popVariables(this);
// No success
context.popMap();
}
1.1 cocoon-2.1/src/blocks/profiler/java/org/apache/cocoon/components/profiler/SimpleSitemapExecutor.java
Index: SimpleSitemapExecutor.java
===================================================================
/*
* Copyright 1999-2004 The Apache Software Foundation.
*
* Licensed 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.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.cocoon.components.profiler;
import java.util.Iterator;
import java.util.Map;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.avalon.framework.parameters.Parameters;
import org.apache.avalon.framework.thread.ThreadSafe;
import org.apache.cocoon.acting.Action;
import org.apache.cocoon.environment.Redirector;
import org.apache.cocoon.environment.SourceResolver;
import org.apache.cocoon.sitemap.ExecutionContext;
/**
* Sampe sitemap executor that prints out everything to a logger
*
* @since 2.2
* @version CVS $Id: SimpleSitemapExecutor.java,v 1.1 2004/06/09 13:43:04 cziegeler Exp $
*/
public class SimpleSitemapExecutor
extends AbstractLogEnabled
implements ThreadSafe {
/* (non-Javadoc)
* @see org.apache.cocoon.sitemap.SitemapExecutor#invokeAction(org.apache.cocoon.sitemap.ExecutionContext, org.apache.cocoon.acting.Action, org.apache.cocoon.environment.Redirector, org.apache.cocoon.environment.SourceResolver, java.util.Map, java.lang.String, org.apache.avalon.framework.parameters.Parameters)
*/
public Map invokeAction(ExecutionContext context, Action action,
Redirector redirector, SourceResolver resolver, Map objectModel,
String resolvedSource, Parameters resolvedParams)
throws Exception {
this.getLogger().info("- Invoking action '" + context.getType() + "' (" +
context.getLocation() + ").");
final Map result = action.act(redirector, resolver, objectModel, resolvedSource, resolvedParams);
if ( result != null ) {
this.getLogger().info("- Action '" + context.getType() + "' returned a map.");
} else {
this.getLogger().info("- Action '" + context.getType() + "' did not return a map.");
}
return result;
}
/* (non-Javadoc)
* @see org.apache.cocoon.sitemap.SitemapExecutor#popVariables(org.apache.cocoon.sitemap.ExecutionContext)
*/
public void popVariables(ExecutionContext context) {
this.getLogger().info("- Variable Context ends");
}
/* (non-Javadoc)
* @see org.apache.cocoon.sitemap.SitemapExecutor#pushVariables(org.apache.cocoon.sitemap.ExecutionContext, java.lang.String, java.util.Map)
*/
public Map pushVariables(ExecutionContext context, String key, Map variables) {
this.getLogger().info("- New Variable Context: " + (key != null ? "('" + key + "')" : ""));
Iterator keys = variables.entrySet().iterator();
while (keys.hasNext()) {
Map.Entry entry = (Map.Entry)keys.next();
this.getLogger().info(" " + entry.getKey() + " : " + entry.getValue());
}
return variables;
}
}