Loading ...
Sorry, an error occurred while loading the content.

Re: [soaplite] Java Vectors

Expand Messages
  • Paul Kulchenko
    Hi, Ian! ... You re right. In the case of: you ll get Perl array with two element. In the case
    Message 1 of 3 , Jul 1, 2001
    • 0 Attachment
      Hi, Ian!

      > the individual beans in <item /> containers but if I call
      > SOAP::Lite's
      > ->result I just get the last one, not a list of them. I'm still
      You're right. In the case of:

      <array enc:arrayType="enc:string[2]">
      <item/>
      <item/>
      </array>

      you'll get Perl array with two element.

      In the case of

      <struct>
      <a>1</a>
      <b>2</b>
      </struct>

      you'll get hash with two key=>value pairs. However SOAP allows you to
      have:

      <something>
      <item>1</item>
      <item>2</item>
      <a>3</a>
      <b>4</b>
      </something>

      which SOAP::Lite will deserialize as hash and only second of <item>
      elements will be available (as you pointed). There are two problems.
      First, there is no datastructure in Perl to represent this
      construction properly. Second, since there is not much difference
      from usual struct, I need to look ahead during deserialization to
      check where there are some elements with duplicate names. yuck.

      However, SOAP::Lite allows you to navigate your structures and get
      access to all elements:

      my $response = SOAP::Lite
      -> proxy()
      -> uri()
      -> method();

      @array = $response->valueof('//something');
      # @array should have (1,2,3,4)

      -- OR --

      @array = $response->valueof('//parent/something');
      # @array should have (1,2,3,4)

      -- OR --

      @array = $response->dataof('//parent/something');
      # @array should have SOAP::Data objects that represent immediate
      # childs of <something> element, so you can get access to names,
      # values, and attributes of <item>, <a> and <b> elements

      dataof()/valueof() methods return array of matched elements in list
      context and first element in scalar context.
      they are basically shortcuts for
      ->match('//something')->valueof;
      and
      ->match('//something')->dataof;

      So, in your case:

      @objects = $response->valueof('//item');

      -- or, being more strict, because '//item' will match 'item' in ANY
      place of XML message:

      @object = $response->value('//result/item');

      or use whatever element name you have instead of 'result'.

      <result>
      <item>...</item>
      <item>...</item>
      <item>...</item>
      </result>

      Let me know if something is unclear. I would also appreciate if
      anybody has ideas on how to represent in Perl this datastructure:

      <something>
      <item>1</item>
      <item>2</item>
      <a>3</a>
      <b>4</b>
      </something>

      and esp. how to identify it. Thank you.

      Best wishes, Paul.

      --- Ian Kallen <spidaman@...> wrote:
      >
      > I'm accessing an Apache SOAP server with SOAP::Lite, getting a
      > serialized Java bean's data as a Perl object works great! However,
      > one of
      > the methods returns a java.util.Vector of beans. Apache SOAP
      > serializes
      > the individual beans in <item /> containers but if I call
      > SOAP::Lite's
      > ->result I just get the last one, not a list of them. I'm still
      > re-reading the SOAP::Lite pod but I haven't yet gathered how to get
      > the
      > Vector as a more "natural" returned state: a Perl array of objects
      > (it
      > really is the Perliest thing to do with it).
      >
      > BTW, I know the Vector is fully populated both by sniffing the SOAP
      > transactions and by calling Data::Dumper on the method call (ref
      > says it's
      > a SOAP::SOM object). Anyone have any light to shed on converting
      > Java
      > Vector's (which are basically a dynamic array of objects) into Perl
      > array of objects? Examples? Guidance on subclassing the
      > deserializer (if
      > indeed that's the best way to approach this)?
      >
      > thanks!
      > -Ian
      >
      > --
      > Ian Kallen <spidaman@...> | AIM: iankallen
      >
      >
      > To unsubscribe from this group, send an email to:
      > soaplite-unsubscribe@yahoogroups.com
      >
      >
      >
      > Your use of Yahoo! Groups is subject to
      > http://docs.yahoo.com/info/terms/
      >
      >


      __________________________________________________
      Do You Yahoo!?
      Get personalized email addresses from Yahoo! Mail
      http://personal.mail.yahoo.com/
    • igorp@photonet.com
      ... Less generic, but much more applicable case is deserialization of (Java) object like class Something { Vector vec; //say, java.lang.Vector of
      Message 2 of 3 , Jul 17, 2001
      • 0 Attachment
        --- Paul Kulchenko wrote:
        > I would also appreciate if
        > anybody has ideas on how to represent in Perl this datastructure:
        >
        > <something>
        > <item>1</item>
        > <item>2</item>
        > <a>3</a>
        > <b>4</b>
        > </something>
        >
        > and esp. how to identify it.
        Less generic, but much more applicable case is deserialization of
        (Java) object like
        class Something
        {
        Vector vec; //say, java.lang.Vector of java.lang.String
        int a;
        int b;
        ........
        }
        As alternative to looking ahead for duplicated names, I'd like to
        suggest to support xsi:type Vector explicitly. At least Apache SOAP
        uses that type to serialize java.lang.Vector (see
        org.apache.soap.encoding.soapenc.VectorSerializer).
        As obvious, Perl representation should have hash value per object's
        field - in our case, $obj->{vec} will be array reference.

        Igor Pechersky
        PictureVision, Inc.
      Your message has been successfully submitted and would be delivered to recipients shortly.