* @throws MapperException
*/
private Object makeObject(Object input, Map param)
throws InstantiationException, IllegalAccessException,
NamingException, MapperException {
TypeHelper th = TypeHelper.instance;
Object ret = klass.newInstance();
SearchResult res = (SearchResult) input;
Attributes attrs = res.getAttributes();
for (NamingEnumeration e = attrs.getAll(); e.hasMore();) {
Attribute attr = (Attribute) e.next();
String id = attr.getID();
String n = (String) outputMap.get(id);
if (n == null)
continue;
/* type of field */
Class fcls = th.getClass(ret, n);
if (fcls == null) {
continue;
}
/* handling of multiple values */
if (attr.size() > 1 || Collection.class.isAssignableFrom(fcls)) {
try {
Collection c = (Collection) th.get(ret, n);
if (c == null) {
throw new MapperException(getName()
+ ": collection field '" + n
+ "' is not initialized in " + klass);
}
/* corresponding field must be a collection */
for (NamingEnumeration ne = attr.getAll(); ne.hasMore();) {
c.add(ne.next());
}
} catch (ClassCastException ex) {
throw new MapperException(getName() + ": field " + n
+ " is not a collection in " + klass);
}
} else
th.setString(ret, n, (String) attr.get());
}
/* try to set the DN attribute if it exists */
String dn = (String) outputMap.get("__DN__");
if (dn != null) {
String rname = res.getName();
if (!"".equals(rname)) {
if(res.isRelative()) {
rname = rname + "," + param.get("root");
}
} else {
rname = param.get("root").toString();
}
th.set(ret, dn, rname);
}
return ret;
}