" and " + COLLECTION_STOREMETHOD +
" attributes cannot be used together");
}
// set defaults based on collection type
ClassFile cf = ClassCache.requireClassFile
(prop.getTypeName());
if (cf.isSuperclass("java.util.Vector")||
cf.isSuperclass("java.util.ArrayList")) {
if (stname == null && aname == null) {
aname = "add";
}
if (iname == null && lname == null) {
lname = "get";
szname = "size";
}
} else if (cf.isImplements("Ljava/util/Collection;")) {
if (stname == null && aname == null) {
aname = "add";
}
if (iname == null && lname == null) {
iname = "iterator";
}
} else if (cf.isArray()) {
String ptype = prop.getTypeName();
itype = ptype.substring(0, ptype.length()-2);
}
// check binding direction(s)
BindingDefinition bdef = contain.getBindingRoot();
boolean isdoub =
"long".equals(itype) || "double".equals(itype);
if (bdef.isInput()) {
// define strategy for adding items to collection
if (aname != null) {
ClassItem meth = cf.getBestMethod(aname,
null, new String[] { itype });
if (meth == null) {
ctx.throwStartTagException
("Add method " + aname +
" not found in collection type " +
cf.getName());
}
boolean hasval =
!"void".equals(meth.getTypeName());
store = new NestedCollection.AddStore(meth,
isdoub, hasval);
} else if (stname != null) {
ClassItem meth = cf.getBestMethod(stname,
null, new String[] { "int", itype });
if (meth == null) {
ctx.throwStartTagException
("Indexed store method " + stname +
" not found in collection type " +
cf.getName());
}
boolean hasval =
!"void".equals(meth.getTypeName());
store = new NestedCollection.IndexedStore(meth,
isdoub, hasval);
} else if (cf.isArray()) {
store = new NestedCollection.ArrayStore(itype,
isdoub);
} else {
ctx.throwStartTagException
("Unknown collection " +
"type with no add or store method defined");
}
}
if (bdef.isOutput()) {
// define strategy for loading items from collection
if (lname != null) {
ClassItem smeth = cf.getMethod(szname, "()I");
if (smeth == null) {
ctx.throwStartTagException
("Size method " + szname +
" not found in collection type " +
cf.getName());
}
ClassItem lmeth = cf.getBestMethod(lname,
itype, new String[] { "int" });
if (lmeth == null) {
ctx.throwStartTagException
("Load method " + lname +
" not found in collection type " +
cf.getName());
}
load = new NestedCollection.
IndexedLoad(smeth, isdoub, lmeth);
} else if (iname != null) {
String mname = "hasNext";
String nname = "next";
ClassItem meth = cf.getMethod(iname,
"()Ljava/util/Iterator;");
if (meth == null) {
mname = "hasMoreElements";
nname = "nextElement";
meth = cf.getMethod(iname,
"()Ljava/util/Enumeration;");
if (meth == null) {
ctx.throwStartTagException
("Iterator method " + iname +
" not found in collection type " +
cf.getName());
}
}
load = new NestedCollection.
IteratorLoad(meth, isdoub,
"java.util.Iterator." + mname,
"java.util.Iterator." + nname);
} else if (cf.isArray()) {
load = new NestedCollection.ArrayLoad(itype,
isdoub);
} else {
ctx.throwStartTagException
("Unknown collection " +