Re: How to assign to an "any" element

Robert Dodier <[email protected]>
Newsgroups gmane.text.xml.axis.user
Message-ID <CAAsY_sTTgXb=jEBA13r2pjW3mGhoEpPuAcw7M9w2Ro5aBr448w@mail.gmail.com>
To follow up, in case someone else bumps into this.

PayloadType PT = ...;
Foo foo = ...; // This is the thing I want to attach to PT

OMElement [] A = new OMElement [1];

A [0] = foo.getOMElement (Foo.MY_QNAME, OMAbstractFactory.getOMFactory ());

PT.setExtraElement (A);

OMElement, Foo.MY_QNAME, and the factory stuff are all
automatically generated by wsdl2java; only Foo and
PayloadType are application-specific.

Hope this helps someone who runs into a similar problem.

Robert Dodier


On Fri, Dec 20, 2013 at 5:27 PM, Robert Dodier <[email protected]> wrote:
> Hello,
>
> I am working with Axis2 1.6.1. I have used wsdl2java to generate
> Java code from a WSDL. The WSDL for a certain type, named
> Payload, includes an "any" element, which in practice might be any
> of several types. (A third party constructed the WSDL and dictates
> conventional usage; I cannot change anything.) I want to construct
> a Payload object which contains a particular type of object, let's
> say Foo. I can construct a Foo object without any trouble. But the
> generated code for Payload doesn't have a setFoo method (not
> surprising, since Foo isn't specified in the description of Payload),
> and the only method for specifying a contained object takes an
> instance of a different interface (not any superinterface of Foo), so
> it seems I cannot specify Foo as an argument for it. How can I
> specify Foo as the contained object?
>
> For the record, here is the relevant snippet of WSDL and the
> corresponding declaration in the code generated by wsdl2java.
> Foo is not a subinterface of the declared type OMElement.
>
> Thanks in advance for any advice.
>
> Robert Dodier
>
> PS.
> WSDL snippet:
>
>             <xs:complexType name="PayloadType">
>                 <xs:sequence>
>                     <xs:any maxOccurs="unbounded" minOccurs="0"
> processContents="skip"/>
>                 </xs:sequence>
>             </xs:complexType>
>
> Generated code:
>
>     protected org.apache.axiom.om.OMElement[] localExtraElement ;
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.