01: package freemarker.ext.beans;
02:
03: import java.util.AbstractCollection;
04: import java.util.Iterator;
05:
06: import freemarker.template.TemplateCollectionModel;
07: import freemarker.template.TemplateModel;
08: import freemarker.template.TemplateModelAdapter;
09: import freemarker.template.TemplateModelException;
10: import freemarker.template.TemplateModelIterator;
11: import freemarker.template.utility.UndeclaredThrowableException;
12:
13: /**
14: * @author Attila Szegedi
15: * @version $Id: CollectionAdapter.java,v 1.2 2005/06/12 19:03:04 szegedia Exp $
16: */
17: class CollectionAdapter extends AbstractCollection implements
18: TemplateModelAdapter {
19: private final BeansWrapper wrapper;
20: private final TemplateCollectionModel model;
21:
22: CollectionAdapter(TemplateCollectionModel model,
23: BeansWrapper wrapper) {
24: this .model = model;
25: this .wrapper = wrapper;
26: }
27:
28: public TemplateModel getTemplateModel() {
29: return model;
30: }
31:
32: public int size() {
33: throw new UnsupportedOperationException();
34: }
35:
36: public Iterator iterator() {
37: try {
38: return new Iterator() {
39: final TemplateModelIterator i = model.iterator();
40:
41: public boolean hasNext() {
42: try {
43: return i.hasNext();
44: } catch (TemplateModelException e) {
45: throw new UndeclaredThrowableException(e);
46: }
47: }
48:
49: public Object next() {
50: try {
51: return wrapper.unwrap(i.next());
52: } catch (TemplateModelException e) {
53: throw new UndeclaredThrowableException(e);
54: }
55: }
56:
57: public void remove() {
58: throw new UnsupportedOperationException();
59: }
60: };
61: } catch (TemplateModelException e) {
62: throw new UndeclaredThrowableException(e);
63: }
64: }
65: }
|