KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > barracuda > core > event > helper > AbstractBlockIterator


1 /*
2  * Copyright (C) 2003 Christian Cryder [christianc@granitepeaks.com]
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * $Id: AbstractBlockIterator.java,v 1.6 2004/02/01 05:16:28 christianc Exp $
19  */

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 /**
27  * This class provides the abstract implementation of a BlockIterator. Basically,
28  * it will
29  */

30 public abstract class AbstractBlockIterator implements BlockIterator {
31 // protected Node templateNode = null;
32
protected BTemplate templateComp = null;
33   
34 /*
35     public void setTemplateNode(Node inode) {
36         templateNode = inode;
37     }
38
39     public Node getTemplateNode() {
40         return templateNode;
41     }
42 */

43     public void updateModelInTemplate(TemplateModel model) {
44         if (templateComp!=null) templateComp.addModel(model);
45     }
46     
47     //csc_111003_1 - added
48
public void preIterate() {
49         //nop
50
}
51
52     public Node next(ViewContext vc, Node templateNode) throws RenderException {
53         try {
54             //allow the developer to load the next record
55
if (!loadNext()) return null;
56     
57             //create our root component
58
BComponent broot = new BComponent();
59             broot.setName("Root");
60
61             //create a template component and bind it to the views
62
templateComp = new BTemplate();
63             Object JavaDoc 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 JavaDoc("Fatal err: Model must return either TemplateModel or List");
67             templateComp.setView(new DefaultTemplateView(templateNode));
68             broot.addChild(templateComp);
69         
70             //now init the component
71
broot.initCycle();
72
73             //now render the component
74
broot.render(vc);
75
76             //now destroy the component
77
broot.destroyCycle();
78             templateComp = null;
79         
80             //now return the rendered node
81
return templateNode;
82         } finally {
83         
84         }
85     }
86
87     public abstract boolean loadNext();
88
89     public abstract Object JavaDoc getTemplateModels();
90
91     //csc_111003_1 - added
92
public void postIterate() {
93         //nop
94
}
95 }
96
Popular Tags