Fixed so null return won't create exception for child binding.

This commit is contained in:
Willem Cazander 2013-09-10 23:32:36 +02:00
parent d15d963aa3
commit 380b829fcb

View file

@ -62,7 +62,6 @@ public class ElementRefectionBindingHandler extends AbstractElementBindingHandle
* @see org.x4o.xml.element.AbstractElementBindingHandler#bindChild(org.x4o.xml.element.Element, java.lang.Object, java.lang.Object)
*/
public void bindChild(Element childElement, Object parentObject, Object childObject) throws ElementBindingHandlerException {
if (parentClass==null | childClass==null | addMethod==null) {
throw new IllegalStateException("Missing property: parentClass="+parentClass+" childClass="+childClass+" addMethod="+addMethod+".");
}
@ -114,7 +113,7 @@ public class ElementRefectionBindingHandler extends AbstractElementBindingHandle
throw new ElementBindingHandlerException("Invoke error: "+e.getMessage()+" from: "+getMethod+" on: "+parentObject+" id:"+getId(),e);
}
if (result==null) {
break;
return; // null is no childeren
}
if (result instanceof List) {
for (Object o:(List)result) {
@ -135,13 +134,17 @@ public class ElementRefectionBindingHandler extends AbstractElementBindingHandle
createSafeChild(parentElement, result);
return;
} else {
throw new ElementBindingHandlerException("Unsuported return type: "+result.getClass()+" need: "+childClass+" from: "+getMethod+" on: "+parentObject+" id:"+getId());
throw new ElementBindingHandlerException("Unsupported return type: "+result.getClass()+" need: "+childClass+" from: "+getMethod+" on: "+parentObject+" id:"+getId());
}
}
throw new ElementBindingHandlerException("Could not find method: "+getMethod+" on: "+parentObject+" id:"+getId());
}
/**
* Only create child when class matches and regex doesn't exclude it.
* @param parentElement The element to create childeren for.
* @param childObject The childObject.
*/
protected void createSafeChild(Element parentElement,Object childObject) {
if (childClass.isAssignableFrom(childObject.getClass())==false) {
return;
@ -152,7 +155,6 @@ public class ElementRefectionBindingHandler extends AbstractElementBindingHandle
createChild(parentElement,childObject);
}
/**
* @return the parentClass
*/