01: // Copyright 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.structure;
16:
17: import static org.apache.tapestry.ioc.internal.util.CollectionFactory.newList;
18:
19: import java.util.List;
20:
21: import org.apache.tapestry.Block;
22: import org.apache.tapestry.MarkupWriter;
23: import org.apache.tapestry.ioc.BaseLocatable;
24: import org.apache.tapestry.ioc.Location;
25: import org.apache.tapestry.runtime.RenderCommand;
26: import org.apache.tapestry.runtime.RenderQueue;
27:
28: public class BlockImpl extends BaseLocatable implements Block,
29: BodyPageElement, RenderCommand {
30: // We could lazily create this, but for <t:block> and <t:parameter>, the case
31: // for an empty block is extremely rare.
32:
33: private final List<PageElement> _elements = newList();
34:
35: public BlockImpl(Location location) {
36: super (location);
37: }
38:
39: public void addToBody(PageElement element) {
40: _elements.add(element);
41: }
42:
43: /**
44: * Pushes all the elements of the body of this block onto the queue in appropriate order.
45: */
46: public void render(MarkupWriter writer, RenderQueue queue) {
47: int count = _elements.size();
48: for (int i = count - 1; i >= 0; i--)
49: queue.push(_elements.get(i));
50: }
51:
52: }
|