> Would you agree that the ObjectFactory is the preferred means of
> constructing the JaxbElement if needed rather than managing the QName and
> JAXBelement myself?

Yes.   Definitely.   

You could also try generating the code using XJC's simple binding by passing 
in a binding file that looks something like:


<jaxws:bindings wsdlLocation="jaxb_custom_extensors.wsdl"
    xmlns:jaxws="http://java.sun.com/xml/ns/jaxws"; 
    xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/";
    xmlns:xsd="http://www.w3.org/2001/XMLSchema";
    xmlns:jaxb="http://java.sun.com/xml/ns/jaxb";
    jaxb:extensionBindingPrefixes="xjc"
    xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc";>
    <jaxws:bindings node="wsdl:definitions/wsdl:types/xsd:schema">
            
        <jaxb:globalBindings 
                jaxb:version="2.0">
            <xjc:simple />
        </jaxb:globalBindings>
    </jaxws:bindings>
</jaxws:bindings>


In SOME cases (not sure about the nillable/minOccurs case), that will generate 
code that doesn't have the JAXBElements which can be simpler to use.   
However, you lose some of the capabilities to distinguish between various 
cases.


Dan






On Friday, January 20, 2012 9:34:06 AM surreption wrote:
> Thanks for the quick reply.
> 
> I do have the response construction set up with helper methods and classes
> to make it easier to maintain. I also have unit tests around the code doing
> the response construction.
> 
> I am using the ObjectFactory to construct the nodes that I need rather than
> building my own QName and JaxbElement. I am doing this so that a change to
> the WSDL will be caught immediately as a compilation error. For example, if
> an element gets renamed, the code will fail to compile rather than relying
> solely on the tests to detect an error in my QName.
> 
> I understand that the JaxbElement is only used when the XSD has two absent
> states (minOccurs="0" and nillable="true"). When the minOcurrs="1" or the
> nillable="false", the JaxbElement is not used and is not needed as the NULL
> check is sufficient to determine the absent state if the request is valid.
> From what I understand the use of the JaxbElement is needed if I need to
> differentiate between an optional element that was not provided, an optional
> element with a nilled value, and a user-provided value. Is this
> understanding correct?
> 
> Would you agree that the ObjectFactory is the preferred means of
> constructing the JaxbElement if needed rather than managing the QName and
> JAXBelement myself?
> 
> --
> View this message in context:
> http://cxf.547215.n5.nabble.com/working-with-optional-nillable-elements-com
> mon-to-request-and-response-tp5159623p5161187.html Sent from the cxf-user
> mailing list archive at Nabble.com.
-- 
Daniel Kulp
[email protected] - http://dankulp.com/blog
Talend Community Coder - http://coders.talend.com

Reply via email to