01: package freemarker.ext.beans;
02:
03: import java.util.AbstractList;
04:
05: import freemarker.template.TemplateModel;
06: import freemarker.template.TemplateModelAdapter;
07: import freemarker.template.TemplateModelException;
08: import freemarker.template.TemplateSequenceModel;
09: 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 implements
16: TemplateModelAdapter {
17: private final BeansWrapper wrapper;
18: private final TemplateSequenceModel model;
19:
20: SequenceAdapter(TemplateSequenceModel model, BeansWrapper wrapper) {
21: this .model = model;
22: this .wrapper = wrapper;
23: }
24:
25: public TemplateModel getTemplateModel() {
26: return model;
27: }
28:
29: public int size() {
30: try {
31: return model.size();
32: } catch (TemplateModelException e) {
33: throw new UndeclaredThrowableException(e);
34: }
35: }
36:
37: public Object get(int index) {
38: try {
39: return wrapper.unwrap(model.get(index));
40: } catch (TemplateModelException e) {
41: throw new UndeclaredThrowableException(e);
42: }
43: }
44: }
|