cziegeler 2004/06/11 01:51:57
Modified: src/java/org/apache/cocoon/components/treeprocessor/sitemap
PreparableMatchNode.java ActTypeNode.java
CallNode.java MatchNode.java
src/java/org/apache/cocoon/sitemap SitemapExecutor.java
src/java/org/apache/cocoon/sitemap/impl DefaultExecutor.java
src/java/org/apache/cocoon/components/treeprocessor
AbstractParentProcessingNode.java
src/blocks/profiler/java/org/apache/cocoon/components/profiler
SimpleSitemapExecutor.java
Log:
Add matchers to profiling - unify method parameters
Revision Changes Path
1.6 +13 -4
cocoon-2.1/src/java/org/apache/cocoon/components/treeprocessor/sitemap/PreparableMatchNode.java
Index: PreparableMatchNode.java
===================================================================
RCS file:
/home/cvs/cocoon-2.1/src/java/org/apache/cocoon/components/treeprocessor/sitemap/PreparableMatchNode.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- PreparableMatchNode.java 5 Mar 2004 13:02:52 -0000 1.5
+++ PreparableMatchNode.java 11 Jun 2004 08:51:56 -0000 1.6
@@ -56,17 +56,23 @@
protected ComponentManager manager;
- public PreparableMatchNode(String type, String pattern, String name)
throws PatternException {
+ public PreparableMatchNode(String type, String pattern, String name) {
super(type);
this.pattern = pattern;
this.name = name;
}
+ /* (non-Javadoc)
+ * @see
org.apache.cocoon.components.treeprocessor.ParameterizableProcessingNode#setParameters(java.util.Map)
+ */
public void setParameters(Map parameterMap) {
this.parameters = parameterMap;
}
+ /* (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;
setSelector((ComponentSelector)manager.lookup(Matcher.ROLE +
"Selector"));
@@ -92,6 +98,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 {
@@ -135,8 +144,8 @@
}
}
- /**
- * Disposable Interface
+ /* (non-Javadoc)
+ * @see org.apache.avalon.framework.activity.Disposable#dispose()
*/
public void dispose() {
if (this.threadSafeMatcher != null) {
1.9 +3 -3
cocoon-2.1/src/java/org/apache/cocoon/components/treeprocessor/sitemap/ActTypeNode.java
Index: ActTypeNode.java
===================================================================
RCS file:
/home/cvs/cocoon-2.1/src/java/org/apache/cocoon/components/treeprocessor/sitemap/ActTypeNode.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- ActTypeNode.java 9 Jun 2004 11:59:23 -0000 1.8
+++ ActTypeNode.java 11 Jun 2004 08:51:56 -0000 1.9
@@ -119,20 +119,20 @@
// If action is ThreadSafe, avoid select() and try/catch block
(faster !)
if (this.threadSafeAction != null) {
actionResult = this.executor.invokeAction(this,
+ objectModel,
this.threadSafeAction,
redirector,
resolver,
- objectModel,
resolvedSource,
resolvedParams);
} else {
Action action = (Action)this.selector.select(this.componentName);
try {
actionResult = this.executor.invokeAction(this,
+ objectModel,
action,
redirector,
resolver,
- objectModel,
resolvedSource,
resolvedParams);
} finally {
1.5 +5 -5
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.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- CallNode.java 9 Jun 2004 13:43:04 -0000 1.4
+++ CallNode.java 11 Jun 2004 08:51:56 -0000 1.5
@@ -103,13 +103,13 @@
if (this.resourceNode != null) {
// Static resource name
- params = this.executor.pushVariables(this, null, params);
+ params = this.executor.pushVariables(this, objectModel, null,
params);
context.pushMap(null, params);
try {
return this.resourceNode.invoke(env, context);
} finally {
- this.executor.popVariables(this);
+ this.executor.popVariables(this, objectModel);
context.popMap();
}
@@ -121,13 +121,13 @@
}
// and only now push the parameters
- params = this.executor.pushVariables(this, null, params);
+ params = this.executor.pushVariables(this, objectModel, null,
params);
context.pushMap(null,params);
try {
return this.resources.invokeByName(name, env, context);
} finally {
- this.executor.popVariables(this);
+ this.executor.popVariables(this, objectModel);
context.popMap();
}
}
1.4 +11 -3
cocoon-2.1/src/java/org/apache/cocoon/components/treeprocessor/sitemap/MatchNode.java
Index: MatchNode.java
===================================================================
RCS file:
/home/cvs/cocoon-2.1/src/java/org/apache/cocoon/components/treeprocessor/sitemap/MatchNode.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- MatchNode.java 5 Mar 2004 13:02:52 -0000 1.3
+++ MatchNode.java 11 Jun 2004 08:51:56 -0000 1.4
@@ -86,12 +86,20 @@
if (this.threadSafeMatcher != null) {
// Avoid select() and try/catch block (faster !)
- result = this.threadSafeMatcher.match(resolvedPattern,
objectModel, resolvedParams);
+ result = this.executor.invokeMatcher(this,
+ objectModel,
+ this.threadSafeMatcher,
+ resolvedPattern,
+ resolvedParams);
} else {
// Get matcher from selector
Matcher matcher =
(Matcher)this.selector.select(this.componentName);
try {
- result = matcher.match(resolvedPattern, objectModel,
resolvedParams);
+ result = this.executor.invokeMatcher(this,
+ objectModel,
+ matcher,
+ resolvedPattern,
+ resolvedParams);
} finally {
this.selector.release(matcher);
}
1.3 +32 -5
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.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- SitemapExecutor.java 9 Jun 2004 13:43:04 -0000 1.2
+++ SitemapExecutor.java 11 Jun 2004 08:51:57 -0000 1.3
@@ -21,6 +21,8 @@
import org.apache.cocoon.acting.Action;
import org.apache.cocoon.environment.Redirector;
import org.apache.cocoon.environment.SourceResolver;
+import org.apache.cocoon.matching.Matcher;
+import org.apache.cocoon.matching.PreparableMatcher;
/**
* The sitemap executor executes all sitemap statements, so it actually
@@ -42,29 +44,54 @@
* Invoke an action and return the result.
*/
Map invokeAction(ExecutionContext context,
+ Map objectModel,
Action action,
Redirector redirector,
SourceResolver resolver,
- Map objectModel,
String resolvedSource,
Parameters resolvedParams )
throws Exception;
+ /**
+ * Invoke a match and return the result
+ */
+ Map invokeMatcher(ExecutionContext context,
+ Map objectModel,
+ Matcher matcher,
+ String pattern,
+ Parameters resolvedParams )
+ throws PatternException;
/**
+ * Invoke a match and return the result
+ */
+ Map invokePreparableMatcher(ExecutionContext context,
+ Map objectModel,
+ PreparableMatcher matcher,
+ Object preparedPattern,
+ Parameters resolvedParams )
+ throws PatternException;
+
+ /**
* Push map of information on the context stack.
* @param context The execution context
+ * @param objectModel The object model
* @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);
+ Map pushVariables(ExecutionContext context,
+ Map objectModel,
+ String key,
+ Map variables);
/**
* Pop a map of information from the context stack.
- * @param context The execution context
+ * @param context The execution context
+ * @param objectModel The object model
*/
- void popVariables(ExecutionContext context);
+ void popVariables(ExecutionContext context,
+ Map objectModel);
}
1.3 +37 -7
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.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- DefaultExecutor.java 9 Jun 2004 13:43:04 -0000 1.2
+++ DefaultExecutor.java 11 Jun 2004 08:51:57 -0000 1.3
@@ -21,7 +21,10 @@
import org.apache.cocoon.acting.Action;
import org.apache.cocoon.environment.Redirector;
import org.apache.cocoon.environment.SourceResolver;
+import org.apache.cocoon.matching.Matcher;
+import org.apache.cocoon.matching.PreparableMatcher;
import org.apache.cocoon.sitemap.ExecutionContext;
+import org.apache.cocoon.sitemap.PatternException;
import org.apache.cocoon.sitemap.SitemapExecutor;
/**
@@ -36,13 +39,13 @@
implements SitemapExecutor {
/* (non-Javadoc)
- * @see
org.apache.cocoon.sitemap.SitemapExecutor#invokeAction(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)
+ * @see
org.apache.cocoon.sitemap.SitemapExecutor#invokeAction(org.apache.cocoon.sitemap.ExecutionContext,
java.util.Map, org.apache.cocoon.acting.Action,
org.apache.cocoon.environment.Redirector,
org.apache.cocoon.environment.SourceResolver, java.lang.String,
org.apache.avalon.framework.parameters.Parameters)
*/
public Map invokeAction(final ExecutionContext context,
+ final Map objectModel,
final Action action,
final Redirector redirector,
final SourceResolver resolver,
- final Map objectModel,
final String resolvedSource,
final Parameters resolvedParams )
throws Exception {
@@ -51,16 +54,43 @@
}
/* (non-Javadoc)
- * @see org.apache.cocoon.sitemap.SitemapExecutor#popVariables()
+ * @see
org.apache.cocoon.sitemap.SitemapExecutor#invokeMatcher(org.apache.cocoon.sitemap.ExecutionContext,
java.util.Map, org.apache.cocoon.matching.Matcher, java.lang.String,
org.apache.avalon.framework.parameters.Parameters)
+ */
+ public Map invokeMatcher(ExecutionContext context,
+ Map objectModel,
+ Matcher matcher,
+ String pattern,
+ Parameters resolvedParams)
+ throws PatternException {
+ return matcher.match(pattern, objectModel, resolvedParams);
+ }
+
+ /* (non-Javadoc)
+ * @see
org.apache.cocoon.sitemap.SitemapExecutor#invokePreparableMatcher(org.apache.cocoon.sitemap.ExecutionContext,
java.util.Map, org.apache.cocoon.matching.PreparableMatcher, java.lang.Object,
org.apache.avalon.framework.parameters.Parameters)
+ */
+ public Map invokePreparableMatcher(ExecutionContext context,
+ Map objectModel,
+ PreparableMatcher matcher,
+ Object preparedPattern,
+ Parameters resolvedParams )
+ throws PatternException {
+ return matcher.preparedMatch(preparedPattern, objectModel,
resolvedParams);
+ }
+
+ /* (non-Javadoc)
+ * @see
org.apache.cocoon.sitemap.SitemapExecutor#popVariables(org.apache.cocoon.sitemap.ExecutionContext,
java.util.Map)
*/
- public void popVariables(ExecutionContext context) {
+ public void popVariables(ExecutionContext context,
+ Map objectModel) {
// nothing to do
}
/* (non-Javadoc)
- * @see
org.apache.cocoon.sitemap.SitemapExecutor#pushVariables(java.lang.String,
java.util.Map)
+ * @see
org.apache.cocoon.sitemap.SitemapExecutor#pushVariables(org.apache.cocoon.sitemap.ExecutionContext,
java.util.Map, java.lang.String, java.util.Map)
*/
- public Map pushVariables(ExecutionContext context, String key, Map
variables) {
+ public Map pushVariables(ExecutionContext context,
+ Map objectModel,
+ String key, Map variables) {
return variables;
}
}
1.6 +3 -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.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- AbstractParentProcessingNode.java 9 Jun 2004 13:43:04 -0000 1.5
+++ AbstractParentProcessingNode.java 11 Jun 2004 08:51:57 -0000 1.6
@@ -49,7 +49,7 @@
Map currentMap)
throws Exception {
- currentMap = this.executor.pushVariables(this, currentName,
currentMap);
+ currentMap = this.executor.pushVariables(this, env.getObjectModel(),
currentName, currentMap);
context.pushMap(currentName,currentMap);
try {
@@ -60,7 +60,7 @@
}
}
} finally {
- this.executor.popVariables(this);
+ this.executor.popVariables(this, env.getObjectModel());
// No success
context.popMap();
}
1.2 +65 -14
cocoon-2.1/src/blocks/profiler/java/org/apache/cocoon/components/profiler/SimpleSitemapExecutor.java
Index: SimpleSitemapExecutor.java
===================================================================
RCS file:
/home/cvs/cocoon-2.1/src/blocks/profiler/java/org/apache/cocoon/components/profiler/SimpleSitemapExecutor.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- SimpleSitemapExecutor.java 9 Jun 2004 13:43:04 -0000 1.1
+++ SimpleSitemapExecutor.java 11 Jun 2004 08:51:57 -0000 1.2
@@ -24,7 +24,11 @@
import org.apache.cocoon.acting.Action;
import org.apache.cocoon.environment.Redirector;
import org.apache.cocoon.environment.SourceResolver;
+import org.apache.cocoon.matching.Matcher;
+import org.apache.cocoon.matching.PreparableMatcher;
import org.apache.cocoon.sitemap.ExecutionContext;
+import org.apache.cocoon.sitemap.PatternException;
+import org.apache.cocoon.sitemap.SitemapExecutor;
/**
* Sampe sitemap executor that prints out everything to a logger
@@ -34,37 +38,84 @@
*/
public class SimpleSitemapExecutor
extends AbstractLogEnabled
- implements ThreadSafe {
+ implements ThreadSafe, SitemapExecutor {
/* (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)
+ * @see
org.apache.cocoon.sitemap.SitemapExecutor#invokeAction(org.apache.cocoon.sitemap.ExecutionContext,
java.util.Map, org.apache.cocoon.acting.Action,
org.apache.cocoon.environment.Redirector,
org.apache.cocoon.environment.SourceResolver, 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)
+ public Map invokeAction(final ExecutionContext context,
+ final Map objectModel,
+ final Action action,
+ final Redirector redirector,
+ final SourceResolver resolver,
+ final String resolvedSource,
+ final Parameters resolvedParams )
throws Exception {
this.getLogger().info("- Invoking action '" + context.getType() + "'
(" +
- context.getLocation() + ").");
+ context.getLocation() + ").");
final Map result = action.act(redirector, resolver, objectModel,
resolvedSource, resolvedParams);
if ( result != null ) {
- this.getLogger().info("- Action '" + context.getType() + "'
returned a map.");
+ this.getLogger().info("- Action '" + context.getType() + "'
returned a map.");
} else {
- this.getLogger().info("- Action '" + context.getType() + "' did
not return a map.");
+ 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)
+ * @see
org.apache.cocoon.sitemap.SitemapExecutor#invokeMatcher(org.apache.cocoon.sitemap.ExecutionContext,
java.util.Map, org.apache.cocoon.matching.Matcher, java.lang.String,
org.apache.avalon.framework.parameters.Parameters)
*/
- public void popVariables(ExecutionContext context) {
+ public Map invokeMatcher(ExecutionContext context,
+ Map objectModel,
+ Matcher matcher,
+ String pattern,
+ Parameters resolvedParams)
+ throws PatternException {
+ this.getLogger().info("- Invoking matcher '" + context.getType() +
"' (" +
+ context.getLocation() + ").");
+ final Map result = matcher.match(pattern, objectModel,
resolvedParams);
+ if ( result != null ) {
+ this.getLogger().info("- Matcher '" + context.getType() + "'
returned a map.");
+ } else {
+ this.getLogger().info("- Matcher '" + context.getType() + "' did
not return a map.");
+ }
+ return result;
+ }
+
+ /* (non-Javadoc)
+ * @see
org.apache.cocoon.sitemap.SitemapExecutor#invokePreparableMatcher(org.apache.cocoon.sitemap.ExecutionContext,
java.util.Map, org.apache.cocoon.matching.PreparableMatcher, java.lang.Object,
org.apache.avalon.framework.parameters.Parameters)
+ */
+ public Map invokePreparableMatcher(ExecutionContext context,
+ Map objectModel,
+ PreparableMatcher matcher,
+ Object preparedPattern,
+ Parameters resolvedParams )
+ throws PatternException {
+ this.getLogger().info("- Invoking matcher '" + context.getType() +
"' (" +
+ context.getLocation() + ").");
+ final Map result = matcher.preparedMatch(preparedPattern,
objectModel, resolvedParams);
+ if ( result != null ) {
+ this.getLogger().info("- Matcher '" + context.getType() + "'
returned a map.");
+ } else {
+ this.getLogger().info("- Matcher '" + context.getType() + "' did
not return a map.");
+ }
+ return result;
+ }
+
+ /* (non-Javadoc)
+ * @see
org.apache.cocoon.sitemap.SitemapExecutor#popVariables(org.apache.cocoon.sitemap.ExecutionContext,
java.util.Map)
+ */
+ public void popVariables(ExecutionContext context,
+ Map objectModel) {
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)
+ * @see
org.apache.cocoon.sitemap.SitemapExecutor#pushVariables(org.apache.cocoon.sitemap.ExecutionContext,
java.util.Map, java.lang.String, java.util.Map)
*/
- public Map pushVariables(ExecutionContext context, String key, Map
variables) {
+ public Map pushVariables(ExecutionContext context,
+ Map objectModel,
+ String key, Map variables) {
this.getLogger().info("- New Variable Context: " + (key != null ?
"('" + key + "')" : ""));
Iterator keys = variables.entrySet().iterator();
while (keys.hasNext()) {
@@ -73,6 +124,6 @@
}
return variables;
}
-
+
}