1 20 package org.enhydra.barracuda.core.event.helper; 21 22 import java.util.*; 23 import org.w3c.dom.*; 24 import org.enhydra.barracuda.core.comp.*; 25 26 30 public abstract class AbstractBlockIterator implements BlockIterator { 31 protected BTemplate templateComp = null; 33 34 43 public void updateModelInTemplate(TemplateModel model) { 44 if (templateComp!=null) templateComp.addModel(model); 45 } 46 47 public void preIterate() { 49 } 51 52 public Node next(ViewContext vc, Node templateNode) throws RenderException { 53 try { 54 if (!loadNext()) return null; 56 57 BComponent broot = new BComponent(); 59 broot.setName("Root"); 60 61 templateComp = new BTemplate(); 63 Object o = getTemplateModels(); 64 if (o instanceof TemplateModel) templateComp.addModel((TemplateModel) o); 65 else if (o instanceof List) templateComp.addModels((List) o); 66 else throw new RuntimeException ("Fatal err: Model must return either TemplateModel or List"); 67 templateComp.setView(new DefaultTemplateView(templateNode)); 68 broot.addChild(templateComp); 69 70 broot.initCycle(); 72 73 broot.render(vc); 75 76 broot.destroyCycle(); 78 templateComp = null; 79 80 return templateNode; 82 } finally { 83 84 } 85 } 86 87 public abstract boolean loadNext(); 88 89 public abstract Object getTemplateModels(); 90 91 public void postIterate() { 93 } 95 } 96 | Popular Tags |