| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
package org.apache.tapestry5.internal.pageload; |
| 16 | |
|
| 17 | |
import org.apache.tapestry5.internal.parser.TemplateToken; |
| 18 | |
import org.apache.tapestry5.internal.parser.TokenType; |
| 19 | |
import org.apache.tapestry5.ioc.internal.util.CollectionFactory; |
| 20 | |
import org.apache.tapestry5.runtime.RenderCommand; |
| 21 | |
|
| 22 | |
import java.util.List; |
| 23 | |
|
| 24 | |
|
| 25 | |
|
| 26 | |
|
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | |
class AssemblerContext implements TokenStream |
| 32 | |
{ |
| 33 | |
final ComponentAssembler assembler; |
| 34 | |
|
| 35 | |
final TokenStream stream; |
| 36 | |
|
| 37 | 736 | private final List<RenderCommand> composable = CollectionFactory.newList(); |
| 38 | |
|
| 39 | |
AssemblerContext(ComponentAssembler assembler, TokenStream stream) |
| 40 | 736 | { |
| 41 | 736 | this.assembler = assembler; |
| 42 | 736 | this.stream = stream; |
| 43 | 736 | } |
| 44 | |
|
| 45 | |
public boolean more() |
| 46 | |
{ |
| 47 | 1018 | return stream.more(); |
| 48 | |
} |
| 49 | |
|
| 50 | |
public TemplateToken next() |
| 51 | |
{ |
| 52 | 4088 | return stream.next(); |
| 53 | |
} |
| 54 | |
|
| 55 | |
public <T extends TemplateToken> T next(Class<T> type) |
| 56 | |
{ |
| 57 | 11860 | return stream.next(type); |
| 58 | |
} |
| 59 | |
|
| 60 | |
public TokenType peekType() |
| 61 | |
{ |
| 62 | 25214 | return stream.peekType(); |
| 63 | |
} |
| 64 | |
|
| 65 | |
void addComposable(RenderCommand command) |
| 66 | |
{ |
| 67 | 10368 | composable.add(command); |
| 68 | 10368 | } |
| 69 | |
|
| 70 | |
void flushComposable() |
| 71 | |
{ |
| 72 | 6722 | switch (composable.size()) |
| 73 | |
{ |
| 74 | |
case 0: |
| 75 | 3890 | return; |
| 76 | |
|
| 77 | |
case 1: |
| 78 | 1292 | addRenderCommand(composable.get(0)); |
| 79 | 1292 | break; |
| 80 | |
|
| 81 | |
default: |
| 82 | 1540 | addRenderCommand(new CompositeRenderCommand(composable.toArray(new RenderCommand[composable.size()]))); |
| 83 | |
break; |
| 84 | |
} |
| 85 | |
|
| 86 | 2832 | composable.clear(); |
| 87 | 2832 | } |
| 88 | |
|
| 89 | |
void add(PageAssemblyAction action) |
| 90 | |
{ |
| 91 | 6264 | flushComposable(); |
| 92 | |
|
| 93 | 6264 | assembler.add(action); |
| 94 | 6264 | } |
| 95 | |
|
| 96 | |
private void addRenderCommand(final RenderCommand command) |
| 97 | |
{ |
| 98 | 2832 | assembler.add(new PageAssemblyAction() |
| 99 | |
{ |
| 100 | 2832 | public void execute(PageAssembly pageAssembly) |
| 101 | |
{ |
| 102 | 6865 | pageAssembly.addRenderCommand(command); |
| 103 | 6865 | } |
| 104 | |
}); |
| 105 | 2832 | } |
| 106 | |
} |