throw new IllegalArgumentException(messages.getMessage(
"missing.attribute", new Object[] { "var", "clayForEach" }));
}
// lookup the ConfigBean that handles the bodyJsfid
ConfigBean config = ConfigBeanFactory.findConfig(bodyJsfid);
if (config == null) {
throw new NullPointerException(messages
.getMessage("clay.config.notloaded"));
}
// make sure it's parsed and cached
ComponentBean b = config.getElement(bodyJsfid);
if (b == null) {
throw new NullPointerException(messages.getMessage(
"clay.jsfid.notfound", new Object[] { bodyJsfid }));
}
ValueBinding vb = context.getApplication().createValueBinding(value);
final Object valueList = vb.getValue(context);
Map beans = new TreeMap();
int i = 0;
Iterator vi = null;
if (valueList == null) {
vi = Collections.EMPTY_LIST.iterator();
} else if (valueList instanceof List) {
vi = ((List) valueList).iterator();
} else if (valueList instanceof Map) {
vi = ((Map) valueList).entrySet().iterator();
} else {
Object[] anArray = new Object[0];
if (anArray.getClass().isAssignableFrom(valueList.getClass())) {
vi = new Iterator() {
private int index = 0;
private final Object[] list = (Object[]) valueList;
public boolean hasNext() {
return (index < list.length);
}
public Object next() {
return list[index++];
}
public void remove() {
};
};
} else {
throw new IllegalArgumentException(messages.getMessage(
"invalid.collectiontype", new Object[] { value }));
}
}
if (vi != null) {
while (vi.hasNext()) {
// create a key for the beans map
StringBuffer id = new StringBuffer("bean" + ++i);
// add the subscripted bean to the beans map with the generated
// key
beans.put(id.toString(), vi.next());
// create a naming container to hold the row
ElementBean namingContainer = new ElementBean();
namingContainer.setRenderId(i);
namingContainer.setJsfid("namingContainer");
namingContainer.setComponentType("javax.faces.NamingContainer");
// create a new nested bean
ElementBean target = new ElementBean();
target.setJsfid(bodyJsfid);
target.setExtends(bodyJsfid);
target.setRenderId(i);
config.assignParent(target);
config.realizingInheritance(target);
// prepend the var to the generated key
id.insert(0, var + ".");
SymbolBean symbol = new SymbolBean();
symbol.setName(Globals.MANAGED_BEAN_MNEMONIC);