Fixed so null return won't create exception for child binding.
This commit is contained in:
parent
d15d963aa3
commit
380b829fcb
|
@ -50,19 +50,18 @@ public class ElementRefectionBindingHandler extends AbstractElementBindingHandle
|
||||||
public Class<?> getBindParentClass() {
|
public Class<?> getBindParentClass() {
|
||||||
return parentClass;
|
return parentClass;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.x4o.xml.element.ElementBindingHandler#getBindChildClasses()
|
* @see org.x4o.xml.element.ElementBindingHandler#getBindChildClasses()
|
||||||
*/
|
*/
|
||||||
public Class<?>[] getBindChildClasses() {
|
public Class<?>[] getBindChildClasses() {
|
||||||
return new Class[] {childClass};
|
return new Class[] {childClass};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.x4o.xml.element.AbstractElementBindingHandler#bindChild(org.x4o.xml.element.Element, java.lang.Object, java.lang.Object)
|
* @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 {
|
public void bindChild(Element childElement, Object parentObject, Object childObject) throws ElementBindingHandlerException {
|
||||||
|
|
||||||
if (parentClass==null | childClass==null | addMethod==null) {
|
if (parentClass==null | childClass==null | addMethod==null) {
|
||||||
throw new IllegalStateException("Missing property: parentClass="+parentClass+" childClass="+childClass+" addMethod="+addMethod+".");
|
throw new IllegalStateException("Missing property: parentClass="+parentClass+" childClass="+childClass+" addMethod="+addMethod+".");
|
||||||
}
|
}
|
||||||
|
@ -89,7 +88,7 @@ public class ElementRefectionBindingHandler extends AbstractElementBindingHandle
|
||||||
}
|
}
|
||||||
throw new ElementBindingHandlerException("Could not find method: "+addMethod+" on: "+childClass+" id:"+getId());
|
throw new ElementBindingHandlerException("Could not find method: "+addMethod+" on: "+childClass+" id:"+getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.x4o.xml.element.AbstractElementBindingHandler#createChilderen(org.x4o.xml.element.Element, java.lang.Object)
|
* @see org.x4o.xml.element.AbstractElementBindingHandler#createChilderen(org.x4o.xml.element.Element, java.lang.Object)
|
||||||
*/
|
*/
|
||||||
|
@ -114,7 +113,7 @@ public class ElementRefectionBindingHandler extends AbstractElementBindingHandle
|
||||||
throw new ElementBindingHandlerException("Invoke error: "+e.getMessage()+" from: "+getMethod+" on: "+parentObject+" id:"+getId(),e);
|
throw new ElementBindingHandlerException("Invoke error: "+e.getMessage()+" from: "+getMethod+" on: "+parentObject+" id:"+getId(),e);
|
||||||
}
|
}
|
||||||
if (result==null) {
|
if (result==null) {
|
||||||
break;
|
return; // null is no childeren
|
||||||
}
|
}
|
||||||
if (result instanceof List) {
|
if (result instanceof List) {
|
||||||
for (Object o:(List)result) {
|
for (Object o:(List)result) {
|
||||||
|
@ -135,13 +134,17 @@ public class ElementRefectionBindingHandler extends AbstractElementBindingHandle
|
||||||
createSafeChild(parentElement, result);
|
createSafeChild(parentElement, result);
|
||||||
return;
|
return;
|
||||||
} else {
|
} 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());
|
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) {
|
protected void createSafeChild(Element parentElement,Object childObject) {
|
||||||
if (childClass.isAssignableFrom(childObject.getClass())==false) {
|
if (childClass.isAssignableFrom(childObject.getClass())==false) {
|
||||||
return;
|
return;
|
||||||
|
@ -152,70 +155,69 @@ public class ElementRefectionBindingHandler extends AbstractElementBindingHandle
|
||||||
createChild(parentElement,childObject);
|
createChild(parentElement,childObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the parentClass
|
* @return the parentClass
|
||||||
*/
|
*/
|
||||||
public Class<?> getParentClass() {
|
public Class<?> getParentClass() {
|
||||||
return parentClass;
|
return parentClass;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param parentClass the parentClass to set
|
* @param parentClass the parentClass to set
|
||||||
*/
|
*/
|
||||||
public void setParentClass(Class<?> parentClass) {
|
public void setParentClass(Class<?> parentClass) {
|
||||||
this.parentClass = parentClass;
|
this.parentClass = parentClass;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the childClass
|
* @return the childClass
|
||||||
*/
|
*/
|
||||||
public Class<?> getChildClass() {
|
public Class<?> getChildClass() {
|
||||||
return childClass;
|
return childClass;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param childClass the childClass to set
|
* @param childClass the childClass to set
|
||||||
*/
|
*/
|
||||||
public void setChildClass(Class<?> childClass) {
|
public void setChildClass(Class<?> childClass) {
|
||||||
this.childClass = childClass;
|
this.childClass = childClass;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the addMethod
|
* @return the addMethod
|
||||||
*/
|
*/
|
||||||
public String getAddMethod() {
|
public String getAddMethod() {
|
||||||
return addMethod;
|
return addMethod;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param addMethod the addMethod to set
|
* @param addMethod the addMethod to set
|
||||||
*/
|
*/
|
||||||
public void setAddMethod(String addMethod) {
|
public void setAddMethod(String addMethod) {
|
||||||
this.addMethod = addMethod;
|
this.addMethod = addMethod;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the getMethod
|
* @return the getMethod
|
||||||
*/
|
*/
|
||||||
public String getGetMethod() {
|
public String getGetMethod() {
|
||||||
return getMethod;
|
return getMethod;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param getMethod the getMethod to set
|
* @param getMethod the getMethod to set
|
||||||
*/
|
*/
|
||||||
public void setGetMethod(String getMethod) {
|
public void setGetMethod(String getMethod) {
|
||||||
this.getMethod = getMethod;
|
this.getMethod = getMethod;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the skipChilderenClassRegex
|
* @return the skipChilderenClassRegex
|
||||||
*/
|
*/
|
||||||
public String getSkipChilderenClassRegex() {
|
public String getSkipChilderenClassRegex() {
|
||||||
return skipChilderenClassRegex;
|
return skipChilderenClassRegex;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param skipChilderenClassRegex the skipChilderenClassRegex to set
|
* @param skipChilderenClassRegex the skipChilderenClassRegex to set
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in a new issue