1
|
|
/*
|
2
|
|
* Angkor Web Framework
|
3
|
|
*
|
4
|
|
* Distributable under LGPL license.
|
5
|
|
* See terms of license at gnu.org.
|
6
|
|
*/
|
7
|
|
|
8
|
|
package com.tirsen.angkor.process;
|
9
|
|
|
10
|
|
import com.tirsen.angkor.Debug;
|
11
|
|
import com.tirsen.angkor.RenderContext;
|
12
|
|
import com.tirsen.angkor.View;
|
13
|
|
import com.tirsen.angkor.ViewFactory;
|
14
|
|
import org.apache.log4j.Category;
|
15
|
|
|
16
|
|
/**
|
17
|
|
* <!-- $Id: RenderValve.java,v 1.3 2002/10/09 21:37:37 tirsen Exp $ -->
|
18
|
|
* <!-- $Author: tirsen $ -->
|
19
|
|
*
|
20
|
|
* @author Jon Tirs´n (tirsen@users.sourceforge.net)
|
21
|
|
* @version $Revision: 1.3 $
|
22
|
|
*/
|
23
|
|
public abstract class RenderValve implements Valve
|
24
|
|
{
|
25
|
|
public static final ExecuteContext.Attribute ViewFactoryAttribute = new ExecuteContext.Attribute("ViewFactory");
|
26
|
|
|
27
|
|
/**
|
28
|
|
* Create a sub-pipeline which is executed for each view factory to render.
|
29
|
|
* In this abstract class no actual render valve is added but subclasses must add it's own variety to the end.
|
30
|
|
*/
|
31
|
8
|
protected Pipeline createRenderPipeline()
|
32
|
|
{
|
33
|
8
|
Pipeline pipeline = new DefaultPipeline();
|
34
|
8
|
pipeline.addValve(new CreateViewValve());
|
35
|
8
|
return pipeline;
|
36
|
|
}
|
37
|
|
|
38
|
|
public static class CreateViewValve implements Valve
|
39
|
|
{
|
40
|
|
private static final Category logger = Debug.getCategory();
|
41
|
|
|
42
|
8
|
public void execute(ExecuteContext exec) throws Exception
|
43
|
|
{
|
44
|
8
|
ViewFactory factory = (ViewFactory) exec.getAttribute(ViewFactoryAttribute);
|
45
|
8
|
if (factory != null)
|
46
|
|
{
|
47
|
|
//logger.debug("NOT preparing " + factory + " for render");
|
48
|
|
//factory.prepare();
|
49
|
8
|
logger.debug("creating view for " + factory);
|
50
|
8
|
View view = factory.getView();
|
51
|
8
|
exec.setAttribute(ExecuteContext.CurrentViewAttribute, view);
|
52
|
|
}
|
53
|
8
|
exec.executeNext();
|
54
|
|
}
|
55
|
|
}
|
56
|
|
|
57
|
|
public static class DoRenderValve implements Valve
|
58
|
|
{
|
59
|
8
|
public void execute(ExecuteContext exec) throws Exception
|
60
|
|
{
|
61
|
8
|
View view = (View) exec.getAttribute(ExecuteContext.CurrentViewAttribute);
|
62
|
8
|
RenderContext renderContext = (RenderContext) exec.getAttribute(ExecuteContext.RenderContextAttribute);
|
63
|
8
|
view.render(renderContext);
|
64
|
8
|
exec.executeNext();
|
65
|
|
}
|
66
|
|
}
|
67
|
|
|
68
|
|
public abstract void execute(ExecuteContext exec) throws Exception;
|
69
|
|
}
|
70
|
|
|