001: /*
002: * Created on 8 Nov 2006
003: */
004: package uk.org.ponder.rsf.builtin;
005:
006: import java.util.ArrayList;
007: import java.util.HashMap;
008: import java.util.List;
009: import java.util.Map;
010:
011: import uk.org.ponder.conversion.StaticLeafParser;
012: import uk.org.ponder.messageutil.MessageLocator;
013: import uk.org.ponder.messageutil.TargettedMessage;
014: import uk.org.ponder.messageutil.TargettedMessageList;
015: import uk.org.ponder.rsf.components.UIContainer;
016: import uk.org.ponder.rsf.components.UIOutput;
017: import uk.org.ponder.rsf.components.decorators.DecoratorList;
018: import uk.org.ponder.rsf.components.decorators.UIFreeAttributeDecorator;
019: import uk.org.ponder.rsf.components.decorators.UIIDStrategyDecorator;
020: import uk.org.ponder.rsf.content.ContentTypeInfoRegistry;
021: import uk.org.ponder.rsf.content.ContentTypeReporter;
022: import uk.org.ponder.rsf.flow.ARIResult;
023: import uk.org.ponder.rsf.flow.jsfnav.NavigationCase;
024: import uk.org.ponder.rsf.flow.jsfnav.NavigationCaseReporter;
025: import uk.org.ponder.rsf.view.ComponentChecker;
026: import uk.org.ponder.rsf.view.ViewComponentProducer;
027: import uk.org.ponder.rsf.viewstate.SimpleViewParameters;
028: import uk.org.ponder.rsf.viewstate.ViewParameters;
029:
030: public class UVBProducer implements ViewComponentProducer,
031: ContentTypeReporter, NavigationCaseReporter {
032: public static final String VIEW_ID = "UVBview";
033: /** The View Parameters that address this view, held as a static variable for
034: * convenience.
035: */
036: public static final ViewParameters PARAMS = new SimpleViewParameters(
037: VIEW_ID);
038: // private BeanDestroyer beanDestroyer;
039: private StaticLeafParser leafparser;
040: private UVBBean uvbbean;
041: private TargettedMessageList tml;
042: private MessageLocator messageLocator;
043:
044: public void setLeafParser(StaticLeafParser leafparser) {
045: this .leafparser = leafparser;
046: }
047:
048: public void setMessageLocator(MessageLocator messageLocator) {
049: this .messageLocator = messageLocator;
050: }
051:
052: /**
053: public void setBeanDestroyer(BeanDestroyer beanDestroyer) {
054: this.beanDestroyer = beanDestroyer;
055: }
056: **/
057: public String getViewID() {
058: return VIEW_ID;
059: }
060:
061: public void setUVBBean(UVBBean uvbbean) {
062: this .uvbbean = uvbbean;
063: }
064:
065: public void setTargettedMessageList(TargettedMessageList tml) {
066: this .tml = tml;
067: }
068:
069: public void fillComponents(UIContainer tofill,
070: ViewParameters viewparamso, ComponentChecker checker) {
071: if (uvbbean.paths != null && uvbbean.values != null) {
072: for (int i = 0; i < uvbbean.paths.length; ++i) {
073: String path = uvbbean.paths[i];
074: Object bean = uvbbean.values[i];
075: UIOutput out = UIOutput.make(tofill, ":" + i,
076: bean == null ? "" : leafparser.render(bean));
077: out.decorators = new DecoratorList(
078: new UIIDStrategyDecorator(path));
079: }
080: }
081: for (int i = 0; i < tml.size(); ++i) {
082: TargettedMessage message = tml.messageAt(i);
083: String rendered = messageLocator.getMessage(
084: message.messagecodes, message.args);
085: UIOutput out = UIOutput.make(tofill, "tml:" + i, rendered);
086: Map attrmap = new HashMap();
087: attrmap.put("target", message.targetid);
088: attrmap
089: .put(
090: "severity",
091: message.severity == TargettedMessage.SEVERITY_ERROR ? "error"
092: : "info");
093: out.decorators = new DecoratorList(
094: new UIFreeAttributeDecorator(attrmap));
095: out.decorators.add(UIIDStrategyDecorator.ID_FULL);
096: }
097: // beanDestroyer.destroy();
098: }
099:
100: public String getContentType() {
101: return ContentTypeInfoRegistry.AJAX;
102: }
103:
104: public List reportNavigationCases() {
105: List togo = new ArrayList();
106: togo.add(new NavigationCase(null, PARAMS,
107: ARIResult.FLOW_ONESTEP));
108: return togo;
109: }
110:
111: }
|