1 16 package org.apache.cocoon.forms.util; 17 18 import java.util.AbstractList ; 19 import java.util.Map ; 20 21 import org.apache.cocoon.forms.formmodel.AbstractContainerWidget; 22 import org.apache.cocoon.forms.formmodel.Repeater; 23 import org.apache.cocoon.forms.formmodel.Widget; 24 25 40 public class RepeaterAsList extends AbstractList { 41 42 private Repeater repeater; 43 private boolean lowerCase; 44 45 53 public RepeaterAsList(Repeater repeater, boolean keysToLowerCase) { 54 this.repeater = repeater; 55 this.lowerCase = keysToLowerCase; 56 } 57 58 61 public RepeaterAsList(Repeater repeater) { 62 this(repeater, false); 63 } 64 65 70 public Repeater getWidget() { 71 return this.repeater; 72 } 73 74 81 public Widget getWidget(String path) { 82 return this.repeater.lookupWidget(path); 83 } 84 85 public Object get(int index) { 86 return new ContainerWidgetAsMap(repeater.getRow(index), lowerCase); 87 } 88 89 public int size() { 90 return repeater.getSize(); 91 } 92 93 public Object set(int index, Object o) { 94 if (o == null) { 95 throw new NullPointerException ("Cannot set null to a repeater"); 96 } 97 if (!(o instanceof Map )) { 98 throw new IllegalArgumentException ("Cannot set a '" + o.getClass().toString() + "' to a repeater"); 99 } 100 Map result = new ContainerWidgetAsMap(repeater.getRow(index)); 101 result.putAll((Map )o); 102 return result; 103 } 104 105 public void add(int index, Object o) { 106 if (o == null) { 107 throw new NullPointerException ("Cannot add null to a repeater"); 108 } 109 if (!(o instanceof Map )) { 110 throw new IllegalArgumentException ("Cannot add a '" + o.getClass().toString() + "' to a repeater"); 111 } 112 Repeater.RepeaterRow row = repeater.addRow(index); 113 new ContainerWidgetAsMap(row).putAll((Map )o); 114 } 115 116 public Object remove(int index) { 117 Map result = new ContainerWidgetAsMap(repeater.getRow(index)); 118 repeater.removeRow(index); 119 return result; 120 } 121 122 public void clear() { 124 repeater.clear(); 125 } 126 } | Popular Tags |