You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by Robert Dodier <ro...@gmail.com> on 2013/12/21 02:27:04 UTC

How to assign to an "any" element

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 ;

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@axis.apache.org
For additional commands, e-mail: java-user-help@axis.apache.org


Re: How to assign to an "any" element

Posted by Robert Dodier <ro...@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 <ro...@gmail.com> 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 ;

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@axis.apache.org
For additional commands, e-mail: java-user-help@axis.apache.org