#!/bin/perl

my $axistest = shift || "TestDeser.java";

my $java;
open(IN,$axistest)|| die "No Java src found named: $axistest";
while(<IN>){$java.=$_;}
close IN;

my $output=".";

my $NS_CSI="...";
my $NS_XSD="---"; 
my $header =
            "<?xml version=\"1.0\"?>\n" .
            "<soap:Envelope " .
              "xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" " .
              "xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\" " .
              "xmlns:me=\"urn:me\" " .
              "xmlns:xsi=\"" . $NS_XSI . "\" " .
              "xmlns:xsd=\"" . $NS_XSD . "\">\n" .
              "<soap:Body>\n" .
                "<methodResult xmlns=\"http://tempuri.org/\">\n\n\n";

  my $footer =
                "\n\n</methodResult>\n" .
              "</soap:Body>\n" .
            "</soap:Envelope>\n\n";



my @tests; 

$java =~ s/\n//g;
$java =~ s/"\s+\+\s+"/ /g;
#print "testing...\n$java\n\n";
$java =~ s/\s+/ /g;

while ($java =~ s/deserialize\s*\(([^)]+)\s*",\s+/deser($1)/gise ) {;}
sub deser {
  my $t = shift;
  $t =~ s/\\"/"/g;
  $t =~ s/^"//;
  push (@tests, $header . $t . $footer);
}


my $n=1;
foreach my $test (@tests) {
  my $file = "$output/t$n.xml";
  open (OUT,">$file")|| die "Can't write $! file=$file\n";
  print OUT $test;
  close OUT;
  $n += 1;
}
