#!/usr/bin/perl

use strict;
use warnings;

use CORBA::IDL      2.60;
use CORBA::JAVA;
# visitors
use CORBA::IDL::RepositoryIdVisitor;
use CORBA::JAVA::NameXmlVisitor;
use CORBA::JAVA::ClassXmlVisitor;
use CORBA::XMLSchemas::NameVisitor;

my $parser = CORBA::IDL::ParserFactory::create('3.0');
$parser->getopts('hi:p:t:vx');
if ($parser->YYData->{opt_v}) {
    print "CORBA::JAVA $CORBA::JAVA::VERSION\n";
    print "CORBA::IDL $CORBA::IDL::VERSION\n";
    print "IDL $CORBA::IDL::Parser::IDL_VERSION\n";
    print "$0\n";
    print "Perl $] on $^O\n";
    exit;
}
if ($parser->YYData->{opt_h}) {
    use Pod::Usage;
    pod2usage(-verbose => 1);
}

my $cflags = '-D__idl2javaxml';
if ($CORBA::IDL::Parser::IDL_VERSION lt '3.0') {
    $cflags .= ' -D_PRE_3_0_COMPILER_';
}
my $preprocessor;
if ($^O eq 'MSWin32') {
    $preprocessor = 'cpp -C ' . $cflags;
#    $preprocessor = 'CL /E /C /nologo ' . $cflags;      # Microsoft VC
}
else {
    $preprocessor = 'cpp -C ' . $cflags;
}
$parser->Configure(
        'forward_constructed_forbidden' => 1,
        'preprocessor'          => $preprocessor,
        'verbose_error'         => 1,   # 0, 1
        'verbose_warning'       => 1,   # 0, 1
        'verbose_info'          => 1,   # 0, 1
        'verbose_deprecated'    => 0,   # 0, 1 (concerns only version '2.4' and upper)
#        'collision_allowed'     => 1,
);
$parser->Run(@ARGV);
$parser->DisplayStatus();
my $root = $parser->getRoot();
if (defined $root) {
    $root->visit(new CORBA::IDL::RepositoryIdVisitor($parser));
    if ($parser->YYData->{opt_x}) {
        $parser->Export();
    }
    $root->visit(new CORBA::JAVA::NameVisitor($parser, $parser->YYData->{opt_p}, $parser->YYData->{opt_t}));
    $root->visit(new CORBA::JAVA::LiteralVisitor($parser));
    $root->visit(new CORBA::JAVA::Name2Visitor($parser));
    $root->visit(new CORBA::JAVA::NameXmlVisitor($parser));
    $root->visit(new CORBA::JAVA::UidVisitor($parser));
    $root->visit(new CORBA::XMLSchemas::NameVisitor($parser));
    $root->visit(new CORBA::JAVA::ClassXmlVisitor($parser));
}

__END__

=head1 NAME

idl2javaxml - IDL compiler to language Java mapping & XML binding

=head1 SYNOPSIS

idl2javaxml [options] I<spec>.idl

=head1 OPTIONS

All options are forwarded to C preprocessor, except -h -i -v -x.

With the GNU C Compatible Compiler Processor, useful options are :

=over 8

=item B<-D> I<name>

=item B<-D> I<name>=I<definition>

=item B<-I> I<directory>

=item B<-I->

=item B<-nostdinc>

=back

Specific options :

=over 8

=item B<-h>

Display help.

=item B<-i> I<directory>

Specify a path for import (only for IDL version 3.0).

=item B<-p> "I<m1>=I<prefix1>;..."

Specify a list of prefix (gives full qualified Java package names).

=item B<-t> "I<m1>=I<new.name1>;..."

Specify a list of name translation (gives  full qualified Java package names).

=item B<-v>

Display version.

=item B<-x>

Enable export (only for IDL version 3.0).

=back

=head1 DESCRIPTION

B<idl2javaxml> parses the given input file (IDL) and generates the same files
as B<idl2java> and a I<class>HelperXML.java file that contains
XML marshal/demarshal methods.
The XML binding follows the CORBA to WSDL/SOAP Interworking Specification (WS-I comformant soap binding).

B<idl2javaxml> is a Perl OO application what uses the visitor design pattern.
The parser is generated by Parse::Yapp.

B<idl2javaxml> needs a B<cpp> executable.

CORBA Specifications, including IDL (Interface Language Definition) ,
the JAVA Language Mapping and CORBA to WSDL/SOAP Interworking
are available on E<lt>http://www.omg.org/E<gt>.

=head1 EXAMPLE

 // IDL
 struct StructType {
     long    field1;
     string  field2;
 };

 // Java
 public class test
 {
   public static void main (String[] args) throws Exception
   {
     XMLOutputStreamImpl os = new XMLOutputStreamImpl (new FileOutputStream ("out.xml"));
     StructType obj = new StructType (1, "toto");
     StructTypeHelperXML.write (os, obj);
     os.close ();
   }
 }

The class StructType and StructTypeHelperXML are generated by B<idl2javaxml>.

The class XMLOutputStreamImpl and XMLInputStreamImpl are an example of the run-time support;
there derive from XMLOutputStream ans XMLInputStream that define the interface.

 // XML
 <StructType><field1>1</field1><field2>toto</field2></StructType>

This XML document is valid against the Schema generated by B<idl2xsd>
(Do you really want write by hand W3C Schema ?).

 // XSD
 <xs:schema targetNamespace="http://www.omg.org/IDL-Mapped/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://www.omg.org/IDL-Mapped/" elementFormDefault="qualified" attributeFormDefault="unqualified">
   <xs:complexType name="StructType">
     <xs:sequence>
       <xs:element name="field1" maxOccurs="1" minOccurs="1" type="xs:int"/>
       <xs:element name="field2" maxOccurs="1" minOccurs="1" type="xs:string"/>
     </xs:sequence>
   </xs:complexType>
 </xs:schema>

The class PYXOutputStreamImpl and PYXInputStreamImpl are an example of
the run-time support for Pyxie format (see E<lt>http://www.pyxie.org/E<gt>);
there derive from XMLOutputStream and XMLInputStream.

 // PYX
 (StructType
 (field1
 -1
 )field1
 (field2
 -toto
 )field2
 )StructType

=head1 SEE ALSO

cpp, idl2html, idl2java, idl2xsd, idl2rng

=head1 COPYRIGHT

(c) 2004-2007 Francois PERRAD, France. All rights reserved.

This program and all CORBA::JAVA modules and all Java class (run-time support)
are distributed under the terms of the Artistic Licence.

=head1 AUTHOR

Francois PERRAD, francois.perrad@gadz.org

=cut

