cziegeler 2003/03/04 08:33:31
Modified: src/java/org/apache/cocoon/environment/wrapper EnvironmentWrapper.java src/java/org/apache/cocoon/components CocoonComponentManager.java Log: Fixing ArrayIndexOutOfBounds exception reported by Martin. Revision Changes Path 1.30 +10 -12 xml-cocoon2/src/java/org/apache/cocoon/environment/wrapper/EnvironmentWrapper.java Index: EnvironmentWrapper.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/environment/wrapper/EnvironmentWrapper.java,v retrieving revision 1.29 retrieving revision 1.30 diff -u -r1.29 -r1.30 --- EnvironmentWrapper.java 3 Mar 2003 21:25:18 -0000 1.29 +++ EnvironmentWrapper.java 4 Mar 2003 16:33:30 -0000 1.30 @@ -80,7 +80,9 @@ * @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a> * @version $Id$ */ -public class EnvironmentWrapper extends AbstractEnvironment implements Environment { +public class EnvironmentWrapper + extends AbstractEnvironment + implements Environment { /** The wrapped environment */ protected Environment environment; @@ -106,9 +108,6 @@ /** The stream to output to */ protected OutputStream outputStream; - /** The processor used */ - protected Processor processor; - /** * Constructs an EnvironmentWrapper object from a Request * and Response objects @@ -323,12 +322,6 @@ public void changeContext(String prefix, String context) throws MalformedURLException { - // HACK: As processing enters sitemap, capture current processor. - // If pipeline is successfully assembled, this will contain proper processor. - // Used by cocoon protocol. - // FIXME (CZ) : Is this the right place? This was before - // in the setComponentManager method! - this.processor = CocoonComponentManager.getCurrentProcessor(); super.changeContext(prefix, context); this.lastContext = this.context; this.lastPrefix = this.prefix.toString(); @@ -343,7 +336,12 @@ this.setContext(this.lastContext); this.setURIPrefix(this.lastPrefix); this.uris = this.lastURI; - return this.processor; + // HACK: As processing enters sitemap, capture current processor. + // If pipeline is successfully assembled, this will contain proper processor. + // Used by cocoon protocol. + // FIXME (CZ) : Is this the right place? This was before + // in the setComponentManager method! + return CocoonComponentManager.getCurrentProcessor(); } /** 1.50 +23 -19 xml-cocoon2/src/java/org/apache/cocoon/components/CocoonComponentManager.java Index: CocoonComponentManager.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/CocoonComponentManager.java,v retrieving revision 1.49 retrieving revision 1.50 diff -u -r1.49 -r1.50 --- CocoonComponentManager.java 3 Mar 2003 21:25:18 -0000 1.49 +++ CocoonComponentManager.java 4 Mar 2003 16:33:30 -0000 1.50 @@ -134,21 +134,23 @@ /** * 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! */ public static void enterEnvironment(Environment env, ComponentManager manager, Processor processor) { - final Map objectModel = env.getObjectModel(); - if (environmentStack.get() == null) { - environmentStack.set(new EnvironmentStack()); + if ( null == env || null == manager || null == processor) { + throw new RuntimeException("CocoonComponentManager.enterEnvironment: all parameters must be set: " + env + " - " + manager + " - " + processor); } - final EnvironmentStack stack = (EnvironmentStack)environmentStack.get(); - stack.push(new Object[] {env, processor, manager}); - EnvironmentDescription desc = (EnvironmentDescription)objectModel.get(PROCESS_KEY); - if ( null != desc ) { - desc.addSitemapConfiguration(processor.getComponentConfigurations()); - } + if (environmentStack.get() == null) { + environmentStack.set(new EnvironmentStack()); + } + final EnvironmentStack stack = (EnvironmentStack)environmentStack.get(); + stack.push(new Object[] {env, processor, manager}); + final EnvironmentDescription desc = (EnvironmentDescription)env.getObjectModel().get(PROCESS_KEY); + desc.addSitemapConfiguration(processor.getComponentConfigurations()); } /** @@ -156,23 +158,25 @@ */ public static void leaveEnvironment() { final EnvironmentStack stack = (EnvironmentStack)environmentStack.get(); - if (null != stack && !stack.empty()) { - final Object[] objects = (Object[])stack.pop(); - EnvironmentDescription desc = (EnvironmentDescription)((Environment)objects[0]).getObjectModel().get(PROCESS_KEY); - if ( null != desc ) { - desc.removeLastSitemapConfiguration(); - } - } + final Object[] objects = (Object[])stack.pop(); + final EnvironmentDescription desc = (EnvironmentDescription)((Environment)objects[0]).getObjectModel().get(PROCESS_KEY); + desc.removeLastSitemapConfiguration(); } /** * This hook has to be called before a request is processed. * The hook is called by the Cocoon component and by the * cocoon protocol implementation. + * This method should never raise an exception, except when + * the environment is not set. + * * @return A unique key within this thread. */ public static Object startProcessing(Environment env) { - EnvironmentDescription desc = new EnvironmentDescription(env); + if ( null == env) { + throw new RuntimeException("CocoonComponentManager.startProcessing: environment must be set."); + } + final EnvironmentDescription desc = new EnvironmentDescription(env); env.getObjectModel().put(PROCESS_KEY, desc); env.startingProcessing(); return desc; @@ -187,7 +191,7 @@ */ public static void endProcessing(Environment env, Object key) { env.finishingProcessing(); - EnvironmentDescription desc = (EnvironmentDescription)key; + final EnvironmentDescription desc = (EnvironmentDescription)key; desc.release(); env.getObjectModel().remove(PROCESS_KEY); }