Sylvain Wallez wrote:
Marco Rolappe wrote:

these multi value problems seem to stem from the following code (which is not present in 2.1.6) in MultiValueJXPathBinding.doSave:

...
multiValueContext.setFactory( new AbstractFactory() {
public boolean createObject(JXPathContext context, Pointer pointer,
Object parent, String name, int index) {
final Object o = context.getValue(name);
if( Collection.class.isAssignableFrom( o.getClass() ) ) {
((Collection)context.getValue(name)).add(null);
} else if( o.getClass().isArray() ) {
// not yet supported
return false;
} else {
return false;
}
return true;
}
});
...



Giacomo, I started merging this with DOMFactory but cannot understand how this works. Can you explain?

AFAIK, JXPath calls the factory if the node at path "name" doesn't exist. So my understanding is that context.getValue(name) will *always* return null.

My debugging sessions showed that context.getValue(name) returs the "node" JXPath wanted to insert something. So in my debugging session it was (because I have bound to a Bean) the Collection holding the multi value items.

I saw you just added a test for this condition, but doesn't it have the effect of always failing by immediately returning false?

I've never had any NPEs during my tests and Marco was right that there is a potential NPE if context.getValue(name) returns a null value. Thus the test.

Also, what is the effect of ((Collection)context.getValue(name)).add(null)? How does adding a null value allow JXPath to continue further evaluation of the path?

JXPath will replace the null value with the value from the multi value item it wanted to store but had to call the factory first to create the slot.

Giacomo

--
Giacomo Pati
Otego AG, Switzerland - http://www.otego.com
Orixo, the XML business alliance - http://www.orixo.com

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature



Reply via email to