01: // Copyright 2006, 2007 The Apache Software Foundation
02: //
03: // Licensed under the Apache License, Version 2.0 (the "License");
04: // you may not use this file except in compliance with the License.
05: // You may obtain a copy of the License at
06: //
07: // http://www.apache.org/licenses/LICENSE-2.0
08: //
09: // Unless required by applicable law or agreed to in writing, software
10: // distributed under the License is distributed on an "AS IS" BASIS,
11: // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12: // See the License for the specific language governing permissions and
13: // limitations under the License.
14:
15: package org.apache.tapestry.internal.services;
16:
17: import org.apache.commons.logging.Log;
18: import org.apache.tapestry.MarkupWriter;
19: import org.apache.tapestry.ioc.util.Stack;
20: import org.apache.tapestry.runtime.RenderCommand;
21: import org.apache.tapestry.runtime.RenderQueue;
22:
23: public class RenderQueueImpl implements RenderQueue {
24: private static final int INITIAL_QUEUE_DEPTH = 100;
25:
26: private final Stack<RenderCommand> _queue = new Stack<RenderCommand>(
27: INITIAL_QUEUE_DEPTH);
28:
29: private final Log _log;
30:
31: public RenderQueueImpl(Log log) {
32: _log = log;
33: }
34:
35: public void push(RenderCommand command) {
36: _queue.push(command);
37: }
38:
39: public void run(MarkupWriter writer) {
40: RenderCommand command = null;
41:
42: // Seems to make sense to use one try/finally around the whole process, rather than
43: // around each call to render() since the end result (in a failure scenario) is the same.
44:
45: try {
46: while (!_queue.isEmpty()) {
47: command = _queue.pop();
48:
49: if (_log.isDebugEnabled())
50: _log.debug(String.format("Executing: %s", command));
51:
52: command.render(writer, this );
53: }
54: } catch (RuntimeException ex) {
55: // This will likely leave the page in a dirty state, and it will not go back into the
56: // page pool.
57:
58: _log.error(ServicesMessages.renderQueueError(command, ex),
59: ex);
60:
61: throw ex;
62: }
63: }
64: }
|