vgritsenko 2004/07/08 05:42:27
Modified: src/java/org/apache/cocoon Cocoon.java
src/java/org/apache/cocoon/environment/internal
EnvironmentHelper.java
Log:
Check environment depth on entrance and exit out of Cocoon
(instead of checking for zero depth). Allows to re-enter Cocoon.
Revision Changes Path
1.29 +9 -14 cocoon-2.1/src/java/org/apache/cocoon/Cocoon.java
Index: Cocoon.java
===================================================================
RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/Cocoon.java,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -r1.28 -r1.29
--- Cocoon.java 6 Jul 2004 20:21:51 -0000 1.28
+++ Cocoon.java 8 Jul 2004 12:42:27 -0000 1.29
@@ -620,20 +620,20 @@
}
environment.startingProcessing();
+ final int environmentDepth = EnvironmentHelper.markEnvironment();
EnvironmentHelper.enterProcessor(this, this.serviceManager,
environment);
try {
boolean result;
if (getLogger().isDebugEnabled()) {
++activeRequestCount;
- this.debug(environment, false);
+ debug(environment, false);
}
if (this.requestListener != null) {
try {
requestListener.onRequestStart(environment);
- }
- catch (Exception e) {
+ } catch (Exception e) {
getLogger().error("Error encountered monitoring request
start: " + e.getMessage());
}
}
@@ -643,8 +643,7 @@
if (this.requestListener != null) {
try {
requestListener.onRequestEnd(environment);
- }
- catch (Exception e) {
+ } catch (Exception e) {
getLogger().error("Error encountered monitoring
request start: " + e.getMessage());
}
}
@@ -655,13 +654,11 @@
if (this.requestListener != null) {
try {
requestListener.onRequestEnd(environment);
- }
- catch (Exception e) {
+ } catch (Exception e) {
getLogger().error("Error encountered monitoring
request start: " + e.getMessage());
}
}
- }
- finally {
+ } finally {
this.componentManager.release(processor);
}
}
@@ -673,8 +670,7 @@
if (this.requestListener != null) {
try {
requestListener.onRequestException(environment, any);
- }
- catch (Exception e) {
+ } catch (Exception e) {
getLogger().error("Error encountered monitoring request
start: " + e.getMessage());
}
}
@@ -688,8 +684,7 @@
--activeRequestCount;
}
- // TODO (CZ): This is only for testing - remove it later on
- EnvironmentHelper.checkEnvironment(getLogger());
+ EnvironmentHelper.checkEnvironment(environmentDepth,
getLogger());
}
}
1.4 +60 -38
cocoon-2.1/src/java/org/apache/cocoon/environment/internal/EnvironmentHelper.java
Index: EnvironmentHelper.java
===================================================================
RCS file:
/home/cvs/cocoon-2.1/src/java/org/apache/cocoon/environment/internal/EnvironmentHelper.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- EnvironmentHelper.java 29 May 2004 17:39:38 -0000 1.3
+++ EnvironmentHelper.java 8 Jul 2004 12:42:27 -0000 1.4
@@ -1,12 +1,12 @@
/*
* 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.
@@ -36,9 +36,9 @@
/**
* Experimental code for cleaning up the environment handling
* This is an internal class, and it might change in an incompatible way
over time.
- * For developing your own components/applications based on Cocoon, you
shouldn't
+ * For developing your own components/applications based on Cocoon, you
shouldn't
* really need it.
- *
+ *
* @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a>
* @version CVS $Id$
* @since 2.2
@@ -49,13 +49,13 @@
/** The environment information */
static protected final InheritableThreadLocal environmentStack = new
CloningInheritableThreadLocal();
-
+
/** The real source resolver */
protected org.apache.excalibur.source.SourceResolver resolver;
-
+
/** The service manager */
protected ServiceManager manager;
-
+
/** The complete prefix */
protected String prefix;
@@ -64,7 +64,7 @@
/** The last prefix, which is stripped off from the request uri */
protected String lastPrefix;
-
+
/**
* Constructor
@@ -73,7 +73,7 @@
public EnvironmentHelper(String context) {
this.context = context;
}
-
+
/**
* Constructor
*
@@ -83,7 +83,7 @@
this.lastPrefix = parent.lastPrefix;
this.prefix = parent.prefix;
}
-
+
/* (non-Javadoc)
* @see
org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
*/
@@ -95,7 +95,7 @@
try {
source = this.resolver.resolveURI(this.context);
this.context = source.getURI();
-
+
} catch (IOException ioe) {
throw new ServiceException("EnvironmentHelper", "Unable to
resolve environment context. ", ioe);
} finally {
@@ -128,7 +128,7 @@
String baseURI,
final Map parameters)
throws MalformedURLException, IOException {
- return this.resolver.resolveURI(location,
+ return this.resolver.resolveURI(location,
(baseURI == null ? this.context :
baseURI),
parameters);
}
@@ -147,20 +147,20 @@
public String getContext() {
return this.context;
}
-
+
/**
* Return the prefix
*/
public String getPrefix() {
return this.prefix;
}
-
+
/**
* Change the context of the environment.
* @param env The environment to change
* @throws ProcessingException
*/
- public void changeContext(Environment env)
+ public void changeContext(Environment env)
throws ProcessingException {
if ( this.lastPrefix != null ) {
final String uris = env.getURI();
@@ -168,14 +168,14 @@
final String message = "The current URI (" + uris +
") doesn't start with given prefix (" +
this.lastPrefix + ")";
throw new ProcessingException(message);
- }
+ }
// we don't need to check for slash at the beginning
// of uris - the prefix always ends with a slash!
final int l = this.lastPrefix.length();
env.setURI(this.prefix, uris.substring(l));
}
}
-
+
/**
* Adds an prefix to the overall stripped off prefix from the request uri
*/
@@ -211,7 +211,7 @@
if (getLogger().isDebugEnabled()) {
getLogger().debug("Base context is zip: " + this.context);
}
-
+
org.apache.excalibur.source.Source source = null;
try {
source = this.resolver.resolveURI(this.context + newContext);
@@ -238,7 +238,7 @@
if (i != -1 && i + 1 < sContext.length()) {
sContext = sContext.substring(0, i + 1);
}
-
+
Source source = null;
try {
source = this.resolver.resolveURI(sContext);
@@ -252,17 +252,20 @@
getLogger().debug("New context is " + this.context);
}
}
-
+
/**
- * This hook must be called by the sitemap each time a sitemap is entered
- * This method should never raise an exception, except when the
- * parameters are not set!
+ * This hook must be called by the sitemap each time a sitemap is
entered.
+ *
+ * <p>This method should never raise an exception, except when the
+ * parameters are not set!</p>
+ *
+ * @throws ProcessingException if processor is null
*/
public static void enterProcessor(Processor processor,
ServiceManager manager,
- Environment env)
+ Environment env)
throws ProcessingException {
- if ( null == processor) {
+ if (null == processor) {
throw new ProcessingException("Processor is not set.");
}
@@ -272,12 +275,14 @@
environmentStack.set(stack);
}
stack.pushInfo(new EnvironmentInfo(processor, stack.getOffset(),
manager, env));
- stack.setOffset(stack.size()-1);
+ stack.setOffset(stack.size() - 1);
}
/**
* This hook must be called by the sitemap each time a sitemap is left.
- * It's the counterpart to [EMAIL PROTECTED] #enterProcessor(Processor,
ServiceManager, Environment)}.
+ *
+ * <p>It's the counterpart to the [EMAIL PROTECTED]
#enterProcessor(Processor, ServiceManager, Environment)}
+ * method.</p>
*/
public static void leaveProcessor() {
final EnvironmentStack stack =
(EnvironmentStack)environmentStack.get();
@@ -285,15 +290,32 @@
stack.setOffset(info.oldStackCount);
}
- public static void checkEnvironment(Logger logger)
+ /**
+ * INTERNAL METHOD. Do not use, can be removed without warning or
deprecation cycle.
+ */
+ public static int markEnvironment() {
+ // TODO (CZ): This is only for testing - remove it later on. See
also Cocoon.java.
+ final EnvironmentStack stack =
(EnvironmentStack)environmentStack.get();
+ if (stack != null) {
+ return stack.size();
+ }
+
+ return 0;
+ }
+
+ /**
+ * INTERNAL METHOD. Do not use, can be removed without warning or
deprecation cycle.
+ */
+ public static void checkEnvironment(int depth, Logger logger)
throws Exception {
- // TODO (CZ): This is only for testing - remove it later on
+ // TODO (CZ): This is only for testing - remove it later on. See
also Cocoon.java.
final EnvironmentStack stack =
(EnvironmentStack)environmentStack.get();
- if (stack != null && !stack.isEmpty() ) {
- logger.error("ENVIRONMENT STACK HAS NOT BEEN CLEANED PROPERLY");
- throw new ProcessingException("Environment stack has not been
cleaned up properly. "
- +"Please report this (if possible
together with a test case) "
- +"to the Cocoon developers.");
+ int currentDepth = stack != null? stack.size() : 0;
+ if (currentDepth != depth) {
+ logger.error("ENVIRONMENT STACK HAS NOT BEEN CLEANED PROPERLY!");
+ throw new ProcessingException("Environment stack has not been
cleaned up properly. " +
+ "Please report this (and if
possible, together with a test case) " +
+ "to the Cocoon developers.");
}
}
@@ -308,7 +330,7 @@
}
return null;
}
-
+
/**
* Return the current processor
*/
@@ -320,7 +342,7 @@
}
return null;
}
-
+
/**
* Get the current sitemap component manager.
* This method return the current sitemap component manager. This