001: /*
002: * Created on Nov 20, 2005
003: */
004: package uk.org.ponder.rsf.processor;
005:
006: import uk.org.ponder.messageutil.TargettedMessageList;
007: import uk.org.ponder.rsf.componentprocessor.ViewProcessor;
008: import uk.org.ponder.rsf.preservation.StatePreservationManager;
009: import uk.org.ponder.rsf.renderer.ViewRender;
010: import uk.org.ponder.rsf.state.ErrorStateManager;
011: import uk.org.ponder.rsf.view.View;
012: import uk.org.ponder.rsf.view.support.ViewGenerator;
013: import uk.org.ponder.rsf.viewstate.ViewParameters;
014: import uk.org.ponder.streamutil.write.PrintOutputStream;
015: import uk.org.ponder.util.RunnableInvoker;
016:
017: /**
018: * Controls the operation of a "render cycle" of RSF. Locates component
019: * producers, generates the view, performs fixups, and invokes the renderer. Any
020: * errors through the construction of this bean are passed back through GetHandler.
021: *
022: * @author Antranig Basman (antranig@caret.cam.ac.uk)
023: *
024: */
025: public class RSFRenderHandler implements RenderHandler {
026: // all request-scope dependencies
027: private ViewGenerator viewgenerator;
028: private ErrorStateManager errorstatemanager;
029: private RunnableInvoker getwrapper;
030: private ViewProcessor viewprocessor;
031: private ViewParameters viewparams;
032:
033: private StatePreservationManager presmanager;
034: private ViewRender viewrender;
035: private TargettedMessageList targettedMessageList;
036: private boolean enableDebugRendering;
037:
038: public void setTargettedMessageList(
039: TargettedMessageList targettedMessageList) {
040: this .targettedMessageList = targettedMessageList;
041: }
042:
043: public void setViewGenerator(ViewGenerator viewgenerator) {
044: this .viewgenerator = viewgenerator;
045: }
046:
047: public void setErrorStateManager(ErrorStateManager errorstatemanager) {
048: this .errorstatemanager = errorstatemanager;
049: }
050:
051: public void setAlterationWrapper(RunnableInvoker getwrapper) {
052: this .getwrapper = getwrapper;
053: }
054:
055: public void setViewProcessor(ViewProcessor viewprocessor) {
056: this .viewprocessor = viewprocessor;
057: }
058:
059: public void setViewParameters(ViewParameters viewparams) {
060: this .viewparams = viewparams;
061: }
062:
063: public void setStatePreservationManager(
064: StatePreservationManager presmanager) {
065: this .presmanager = presmanager;
066: }
067:
068: public void setEnableDebugRendering(boolean enableDebugRendering) {
069: this .enableDebugRendering = enableDebugRendering;
070: }
071:
072: public void setViewRender(ViewRender viewrender) {
073: this .viewrender = viewrender;
074: }
075:
076: // Since this is a request-scope bean, there is no problem letting the
077: // returned view from the getwrapper escape into this member.
078: private View view;
079:
080: /**
081: * The beanlocator is passed in to allow the late location of the ViewRender
082: * bean which needs to occur in a controlled exception context.
083: */
084: public void handle(PrintOutputStream pos) {
085: // *outside* alteration wrapper so that AW may be BeanFetchBracketed.
086: presmanager.scopeRestore();
087: getwrapper.invokeRunnable(new Runnable() {
088: public void run() {
089: if (viewparams.flowtoken != null) {
090: presmanager.restore(viewparams.flowtoken,
091: viewparams.endflow != null);
092: }
093: // this must now be AFTER restoration since the templateexpander may
094: // access the model. Shucks!!
095: view = viewgenerator.generateView();
096: // even a "read" from the model may want to cause a scope to be allocated.
097: // it will have to be the user's responsibility not to violate idempotency.
098: presmanager.scopePreserve();
099: viewprocessor.setView(view);
100: view = viewprocessor.getProcessedView();
101: }
102: });
103: viewrender.setMessages(targettedMessageList);
104: // TODO: globaltargetid detection has not been investigated for a while
105: viewrender
106: .setGlobalMessageTarget(errorstatemanager.errorstate.globaltargetid);
107: viewrender.setView(view);
108: viewrender.setDebugRender(enableDebugRendering
109: && viewparams.debugrender != null);
110: viewrender.render(pos);
111: }
112:
113: }
|