KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > freemarker > ext > beans > SequenceAdapter


1 package freemarker.ext.beans;
2
3 import java.util.AbstractList JavaDoc;
4
5 import freemarker.template.TemplateModel;
6 import freemarker.template.TemplateModelAdapter;
7 import freemarker.template.TemplateModelException;
8 import freemarker.template.TemplateSequenceModel;
9 import freemarker.template.utility.UndeclaredThrowableException;
10
11 /**
12  * @author Attila Szegedi
13  * @version $Id: SequenceAdapter.java,v 1.2 2005/06/12 19:03:04 szegedia Exp $
14  */

15 class SequenceAdapter extends AbstractList JavaDoc implements TemplateModelAdapter {
16     private final BeansWrapper wrapper;
17     private final TemplateSequenceModel model;
18     
19     SequenceAdapter(TemplateSequenceModel model, BeansWrapper wrapper) {
20         this.model = model;
21         this.wrapper = wrapper;
22     }
23     
24     public TemplateModel getTemplateModel() {
25         return model;
26     }
27     
28     public int size() {
29         try {
30             return model.size();
31         }
32         catch(TemplateModelException e) {
33             throw new UndeclaredThrowableException(e);
34         }
35     }
36     
37     public Object JavaDoc get(int index) {
38         try {
39             return wrapper.unwrap(model.get(index));
40         }
41         catch(TemplateModelException e) {
42             throw new UndeclaredThrowableException(e);
43         }
44     }
45 }
46
Popular Tags