CORBA-JAVA

 view release on metacpan or  search on metacpan

lib/CORBA/JAVA/ClassVisitor.pm  view on Meta::CPAN


sub visitSpecification {
    my $self = shift;
    my ($node) = @_;
    foreach (@{$node->{list_decl}}) {
        $self->_get_defn($_)->visit($self);
    }
}

#
#   3.7     Module Declaration
#

sub visitModules {
    my $self = shift;
    my ($node) = @_;
    unless (exists $node->{$self->{num_key}}) {
        $node->{$self->{num_key}} = 0;
    }
    my $module = ${$node->{list_decl}}[$node->{$self->{num_key}}];
    $module->visit($self);
    $node->{$self->{num_key}} ++;
}

sub visitModule {
    my $self = shift;
    my ($node) = @_;
    foreach (@{$node->{list_decl}}) {
        $self->_get_defn($_)->visit($self);
    }
}

#
#   3.8     Interface Declaration
#

sub _interface_helper {
    my ($self, $node) = @_;

    $self->open_stream($node, 'Helper.java');
    my $FH = $self->{out};
    print $FH "abstract public class ",$node->{java_helper},"Helper\n";
    print $FH "{\n";
    print $FH "  private static java.lang.String _id = \"",$node->{repos_id},"\";\n";
    print $FH "\n";
    print $FH "  public static void insert (org.omg.CORBA.Any a, ",$node->{java_Name}," that)\n";
    print $FH "  {\n";
    print $FH "    org.omg.CORBA.portable.OutputStream out = a.create_output_stream ();\n";
    print $FH "    a.type (type ());\n";
    print $FH "    write (out, that);\n";
    print $FH "    a.read_value (out.create_input_stream (), type ());\n";
    print $FH "  }\n";
    print $FH "\n";
    print $FH "  public static ",$node->{java_Name}," extract (org.omg.CORBA.Any a)\n";
    print $FH "  {\n";
    print $FH "    return read (a.create_input_stream ());\n";
    print $FH "  }\n";
    print $FH "\n";
    print $FH "  private static org.omg.CORBA.TypeCode __typeCode = null;\n";
    print $FH "  private static boolean __active = false;\n";
    print $FH "  synchronized public static org.omg.CORBA.TypeCode type ()\n";
    print $FH "  {\n";
    print $FH "    if (__typeCode == null)\n";
    print $FH "    {\n";
    print $FH "      synchronized (org.omg.CORBA.TypeCode.class)\n";
    print $FH "      {\n";
    print $FH "        if (__typeCode == null)\n";
    print $FH "        {\n";
    print $FH "          if (__active)\n";
    print $FH "          {\n";
    print $FH "            return org.omg.CORBA.ORB.init().create_recursive_tc ( ",$node->{java_Helper},".id () );\n";
    print $FH "          }\n";
    print $FH "          __active = true;\n";
    print $FH "          __typeCode = org.omg.CORBA.ORB.init ().create_interface_tc (_id, \"",$node->{java_name},"\");\n";
    print $FH "          __active = false;\n";
    print $FH "        }\n";
    print $FH "      }\n";
    print $FH "    }\n";
    print $FH "    return __typeCode;\n";
    print $FH "  }\n";
    print $FH "\n";
    print $FH "  public static java.lang.String id ()\n";
    print $FH "  {\n";
    print $FH "    return _id;\n";
    print $FH "  }\n";
    print $FH "\n";
    print $FH "  public static ",$node->{java_Name}," read (org.omg.CORBA.portable.InputStream \$is)\n";
    print $FH "  {\n";
    if ($node->isa('AbstractInterface')) {
        print $FH "    return narrow (((org.omg.CORBA_2_3.portable.InputStream)\$is).read_abstract_interface (_",$node->{java_name},"Stub.class));\n";
    }
    else {
        print $FH "    return narrow (\$is.read_Object (_",$node->{java_name},"Stub.class));\n";
    }
    print $FH "  }\n";
    print $FH "\n";
    print $FH "  public static void write (org.omg.CORBA.portable.OutputStream \$os, ",$node->{java_Name}," value)\n";
    print $FH "  {\n";
    if ($node->isa('AbstractInterface')) {
        print $FH "    ((org.omg.CORBA_2_3.portable.OutputStream)\$os).write_abstract_interface ((java.lang.Object)value);\n";
    }
    else {
        print $FH "    \$os.write_Object ((org.omg.CORBA.Object)value);\n";
    }
    print $FH "  }\n";
    print $FH "\n";
    if ($node->isa('RegularInterface') and exists $node->{inheritance} and exists $node->{inheritance}->{list_interface}) {
        my $has_abstract = 0;
        foreach (@{$node->{inheritance}->{list_interface}}) {
            my $base = $self->_get_defn($_);
            $has_abstract = 1 if ($base->isa('AbstractInterface'));
        }
        if ($has_abstract) {
            print $FH "  public static ",$node->{java_Name}," narrow (java.lang.Object obj)\n";
            print $FH "  {\n";
            print $FH "    if (obj == null)\n";
            print $FH "      return null;\n";
            print $FH "    else if (obj instanceof org.omg.CORBA.Object)\n";
            print $FH "      return _narrow ((org.omg.CORBA.Object)obj, false);\n";
            print $FH "    throw new org.omg.CORBA.BAD_PARAM ();\n";
            print $FH "  }\n";
            print $FH "\n";
            print $FH "  public static ",$node->{java_Name}," unchecked_narrow (java.lang.Object obj)\n";
            print $FH "  {\n";
            print $FH "    if (obj == null)\n";

lib/CORBA/JAVA/ClassVisitor.pm  view on Meta::CPAN


sub visitAbstractInterface {
    my $self = shift;
    my ($node) = @_;
    return unless ($self->{srcname} eq $node->{filename});

    $self->_holder($node);
    $self->_interface_helper($node);
    $self->_interface($node);
    $self->_interface_stub($node);
    $self->_interface_helperXML($node) if ($self->can('_interface_helperXML'));
    $self->_interface_stubXML($node) if ($self->can('_interface_stubXML'));
}

sub visitLocalInterface {
    my $self = shift;
    my ($node) = @_;
    return unless ($self->{srcname} eq $node->{filename});

    $self->_holder($node);
    $self->_interface_helper($node);
    $self->_interface($node);
    $self->_interface_operations($node);
    $self->_interface_stub($node);
}

sub visitForwardBaseInterface {
    # empty
}

#
#   3.9     Value Declaration
#
#   3.9.1   Regular Value Type
#

sub _value_helper {
    my ($self, $node) = @_;

    $self->open_stream($node, 'Helper.java');
    my $FH = $self->{out};
    print $FH "abstract public class ",$node->{java_helper},"Helper\n";
    print $FH "{\n";
    print $FH "  private static java.lang.String _id = \"",$node->{repos_id},"\";\n";
    print $FH "\n";
    print $FH "  public static void insert (org.omg.CORBA.Any a, ",$node->{java_Name}," that)\n";
    print $FH "  {\n";
    print $FH "    org.omg.CORBA.portable.OutputStream out = a.create_output_stream ();\n";
    print $FH "    a.type (type ());\n";
    print $FH "    write (out, that);\n";
    print $FH "    a.read_value (out.create_input_stream (), type ());\n";
    print $FH "  }\n";
    print $FH "\n";
    print $FH "  public static ",$node->{java_Name}," extract (org.omg.CORBA.Any a)\n";
    print $FH "  {\n";
    print $FH "    return read (a.create_input_stream ());\n";
    print $FH "  }\n";
    print $FH "\n";
    print $FH "  private static org.omg.CORBA.TypeCode __typeCode = null;\n";
    print $FH "  private static boolean __active = false;\n";
    print $FH "  synchronized public static org.omg.CORBA.TypeCode type ()\n";
    print $FH "  {\n";
    print $FH "    if (__typeCode == null)\n";
    print $FH "    {\n";
    print $FH "      synchronized (org.omg.CORBA.TypeCode.class)\n";
    print $FH "      {\n";
    print $FH "        if (__typeCode == null)\n";
    print $FH "        {\n";
    print $FH "          if (__active)\n";
    print $FH "          {\n";
    print $FH "            return org.omg.CORBA.ORB.init().create_recursive_tc ( ",$node->{java_Helper},".id () );\n";
    print $FH "          }\n";
    print $FH "          __active = true;\n";
    if (exists $node->{list_member}) {
        print $FH "          org.omg.CORBA.ValueMember[] _members0 = new org.omg.CORBA.ValueMember [",scalar(@{$node->{list_member}}),"];\n";
        print $FH "          org.omg.CORBA.TypeCode _tcOf_members0 = null;\n";
        my $i = 0;
        foreach (@{$node->{list_member}}) {     # StateMember
            my $member = $self->_get_defn($_);
            print $FH "          // ValueMember instance for ",$member->{java_name},"\n";
            $self->_member_helper_type($member, $node, $i);
            $i ++;
        }
    }
    else {
        print $FH "          org.omg.CORBA.ValueMember[] _members0 = new org.omg.CORBA.ValueMember [0];\n";
        print $FH "          org.omg.CORBA.TypeCode _tcOf_members0 = null;\n";
    }
    if ($node->isa('AbstractValue')) {
        print $FH "          __typeCode = org.omg.CORBA.ORB.init ().create_value_tc (_id, \"",$node->{java_name},"\", org.omg.CORBA.VM_ABSTRACT.value, null, _members0);\n";
    }
    else {
        print $FH "          __typeCode = org.omg.CORBA.ORB.init ().create_value_tc (_id, \"",$node->{java_name},"\", org.omg.CORBA.VM_NONE.value, null, _members0);\n";
    }
    print $FH "          __active = false;\n";
    print $FH "        }\n";
    print $FH "      }\n";
    print $FH "    }\n";
    print $FH "    return __typeCode;\n";
    print $FH "  }\n";
    print $FH "\n";
    print $FH "  public static java.lang.String id ()\n";
    print $FH "  {\n";
    print $FH "    return _id;\n";
    print $FH "  }\n";
    print $FH "\n";
    print $FH "  public static ",$node->{java_Name}," read (org.omg.CORBA.portable.InputStream \$is)\n";
    print $FH "  {\n";
    print $FH "    return (",$node->{java_Name},")((org.omg.CORBA_2_3.portable.InputStream)\$is).read_value (id ());\n";
    print $FH "  }\n";
    print $FH "\n";
    print $FH "  public static void write (org.omg.CORBA.portable.OutputStream \$os, ",$node->{java_Name}," value)\n";
    print $FH "  {\n";
    print $FH "    ((org.omg.CORBA_2_3.portable.OutputStream)\$os).write_value (value, id ());\n";
    print $FH "  }\n";
    print $FH "\n";
    print $FH $self->{factory};
    print $FH "}\n";
    close $FH;
}

sub _value {
    my ($self, $node) = @_;

    $self->open_stream($node, '.java');

lib/CORBA/JAVA/ClassVisitor.pm  view on Meta::CPAN

    print $FH "  public void _read (org.omg.CORBA.portable.InputStream \$is)\n";
    print $FH "  {\n";
    print $FH "    value = ",$node->{java_read},".value;\n";
    print $FH "  }\n";
    print $FH "\n";
    print $FH "  public void _write (org.omg.CORBA.portable.OutputStream \$os)\n";
    print $FH "  {\n";
    print $FH "    ",$node->{java_helper}," vb = new ",$node->{java_helper}," (value);\n";
    print $FH "    ",$node->{java_write},"vb);\n";
    print $FH "  }\n";
    print $FH "\n";
    print $FH "  public org.omg.CORBA.TypeCode _type ()\n";
    print $FH "  {\n";
    print $FH "    return ",$node->{java_Helper},".type ();\n";
    print $FH "  }\n";
    print $FH "\n";
    print $FH "}\n";
    close $FH;
}

sub _boxed_helper {
    my ($self, $node, $type, $array, $type2, $array_max) = @_;

    $self->open_stream($node, 'Helper.java');
    my $FH = $self->{out};
    print $FH "public final class ",$node->{java_helper},"Helper implements org.omg.CORBA.portable.BoxedValueHelper\n";
    print $FH "{\n";
    print $FH "  private static java.lang.String _id = \"",$node->{repos_id},"\";\n";
    print $FH "\n";
    print $FH "  private static ",$node->{java_helper},"Helper _instance = new ",$node->{java_helper},"Helper ();\n";
    print $FH "\n";
    print $FH "  public ",$node->{java_helper},"Helper()\n";
    print $FH "  {\n";
    print $FH "  }\n";
    print $FH "\n";
    if (exists $node->{java_primitive}) {
        print $FH "  public static void insert (org.omg.CORBA.Any a, ",$node->{java_Name}," that)\n";
    }
    else {
        print $FH "  public static void insert (org.omg.CORBA.Any a, ",$type->{java_Name},@{$array}," that)\n";
    }
    print $FH "  {\n";
    print $FH "    org.omg.CORBA.portable.OutputStream out = a.create_output_stream ();\n";
    print $FH "    a.type (type ());\n";
    print $FH "    write (out, that);\n";
    print $FH "    a.read_value (out.create_input_stream (), type ());\n";
    print $FH "  }\n";
    print $FH "\n";
    if (exists $node->{java_primitive}) {
        print $FH "  public static ",$node->{java_Name}," extract (org.omg.CORBA.Any a)\n";
    }
    else {
        print $FH "  public static ",$type->{java_Name},@{$array}," extract (org.omg.CORBA.Any a)\n";
    }
    print $FH "  {\n";
    print $FH "    return read (a.create_input_stream ());\n";
    print $FH "  }\n";
    print $FH "\n";
    print $FH "  private static org.omg.CORBA.TypeCode __typeCode = null;\n";
    print $FH "  private static boolean __active = false;\n";
    print $FH "  synchronized public static org.omg.CORBA.TypeCode type ()\n";
    print $FH "  {\n";
    print $FH "    if (__typeCode == null)\n";
    print $FH "    {\n";
    print $FH "      synchronized (org.omg.CORBA.TypeCode.class)\n";
    print $FH "      {\n";
    print $FH "        if (__typeCode == null)\n";
    print $FH "        {\n";
    print $FH "          if (__active)\n";
    print $FH "          {\n";
    print $FH "            return org.omg.CORBA.ORB.init().create_recursive_tc ( ",$node->{java_Helper},".id () );\n";
    print $FH "          }\n";
    print $FH "          __active = true;\n";
    print $FH "          __typeCode = ",$type->{java_type_code},";\n";
    foreach (reverse @{$array_max}) {
        if (defined $_) {
            print $FH "          __typeCode = org.omg.CORBA.ORB.init ().create_sequence_tc (",$_->{java_literal},", __typeCode);\n";
        }
        else {
            print $FH "          __typeCode = org.omg.CORBA.ORB.init ().create_sequence_tc (0, __typeCode);\n";
        }
    }
    print $FH "          __typeCode = org.omg.CORBA.ORB.init ().create_value_box_tc (_id, \"",$node->{java_helper},"\", __typeCode);\n";
    print $FH "          __active = false;\n";
    print $FH "        }\n";
    print $FH "      }\n";
    print $FH "    }\n";
    print $FH "    return __typeCode;\n";
    print $FH "  }\n";
    print $FH "\n";
    print $FH "  public static java.lang.String id ()\n";
    print $FH "  {\n";
    print $FH "    return _id;\n";
    print $FH "  }\n";
    print $FH "\n";
    if (exists $node->{java_primitive}) {
        print $FH "  public static ",$node->{java_Name}," read (org.omg.CORBA.portable.InputStream \$is)\n";
    }
    else {
        print $FH "  public static ",$type->{java_Name},@{$array}," read (org.omg.CORBA.portable.InputStream \$is)\n";
    }
    print $FH "  {\n";
    print $FH "    if (\$is instanceof org.omg.CORBA_2_3.portable.InputStream)\n";
    if (exists $node->{java_primitive}) {
        print $FH "      return (",$node->{java_Name},")((org.omg.CORBA_2_3.portable.InputStream)\$is).read_value (_instance);\n";
    }
    else {
        print $FH "      return (",$type->{java_Name},@{$array},")((org.omg.CORBA_2_3.portable.InputStream)\$is).read_value (_instance);\n";
    }
    print $FH "    else\n";
    print $FH "      throw new org.omg.CORBA.BAD_PARAM ();\n";
    print $FH "  }\n";
    print $FH "\n";
    print $FH "  public java.io.Serializable read_value (org.omg.CORBA.portable.InputStream \$is)\n";
    print $FH "  {\n";
    print $FH "    ",$type->{java_Name},@{$array}," value;\n";
    my @tab = (q{ } x 4);
    my $i = 0;
    my $idx = q{};
    my @array1= @{$array};
    if (exists $node->{array_size}) {
        foreach (@{$node->{array_size}}) {
            pop @array1;
            print $FH @tab,"value",$idx," = new ",$type->{java_Name}," [",$_->{java_literal},"]",@array1,";\n";
            print $FH @tab,"for (int _o",$i," = 0; _o",$i," < (",$_->{java_literal},"); _o",$i,"++)\n";

lib/CORBA/JAVA/ClassVisitor.pm  view on Meta::CPAN

        print $FH $self->_format_javadoc($node);
        print $FH "public interface ",$node->{java_name},"\n";
        print $FH "{\n";
        print $FH "  public static final ",$type->{java_Name}," value = ";
        if (       $type->isa('FloatingPtType')
                or $type->isa('IntegerType')
                or $type->isa('CharType')
                or $type->isa('WideCharType')
                or $type->isa('StringType')
                or $type->isa('WideStringType')
                or $type->isa('BooleanType')
                or $type->isa('OctetType')
                or $type->isa('EnumType') ) {
            print $FH $value->{java_literal},";\n";
        }
        else {
            print $FH "new ",$type->{java_Name}," (",$value->{java_literal},");\n";
        }
        print $FH "}\n";
        close $FH;
    }
}

#
#   3.11    Type Declaration
#

sub visitTypeDeclarators {
    my $self = shift;
    my ($node) = @_;
    foreach (@{$node->{list_decl}}) {
        $self->_get_defn($_)->visit($self);
    }
}

sub _typedeclarator_helper {
    my ($self, $node, $type, $array, $type2, $array_max) = @_;

    $self->open_stream($node, 'Helper.java');
    my $FH = $self->{out};
    print $FH $self->_format_javadoc($node);
    print $FH "abstract public class ",$node->{java_helper},"Helper\n";
    print $FH "{\n";
    print $FH "  private static java.lang.String _id = \"",$node->{repos_id},"\";\n";
    print $FH "\n";
    print $FH "  public static void insert (org.omg.CORBA.Any a, ",$type->{java_Name},@{$array}," that)\n";
    print $FH "  {\n";
    print $FH "    org.omg.CORBA.portable.OutputStream out = a.create_output_stream ();\n";
    print $FH "    a.type (type ());\n";
    print $FH "    write (out, that);\n";
    print $FH "    a.read_value (out.create_input_stream (), type ());\n";
    print $FH "  }\n";
    print $FH "\n";
    print $FH "  public static ",$type->{java_Name},@{$array}," extract (org.omg.CORBA.Any a)\n";
    print $FH "  {\n";
    print $FH "    return read (a.create_input_stream ());\n";
    print $FH "  }\n";
    print $FH "\n";
    print $FH "  private static org.omg.CORBA.TypeCode __typeCode = null;\n";
##  print $FH "  private static boolean __active = false;\n";
    print $FH "  synchronized public static org.omg.CORBA.TypeCode type ()\n";
    print $FH "  {\n";
    print $FH "    if (__typeCode == null)\n";
    print $FH "    {\n";
##  print $FH "      synchronized (org.omg.CORBA.TypeCode.class)\n";
##  print $FH "      {\n";
##  print $FH "        if (__typeCode == null)\n";
##  print $FH "        {\n";
##  print $FH "          if (__active)\n";
##  print $FH "          {\n";
##  print $FH "            return org.omg.CORBA.ORB.init().create_recursive_tc ( ",$node->{java_Helper},".id () );\n";
##  print $FH "          }\n";
##  print $FH "          __active = true;\n";
    print $FH "          __typeCode = ",$type->{java_type_code},";\n";
    foreach (reverse @{$array_max}) {
        if (defined $_) {
            print $FH "          __typeCode = org.omg.CORBA.ORB.init ().create_sequence_tc (",$_->{java_literal},", __typeCode);\n";
        }
        else {
            print $FH "          __typeCode = org.omg.CORBA.ORB.init ().create_sequence_tc (0, __typeCode);\n";
        }
    }
    if (exists $node->{array_size}) {
        foreach (@{$node->{array_size}}) {
            print $FH "          __typeCode = org.omg.CORBA.ORB.init ().create_array_tc (",$_->{java_literal},", __typeCode );\n";
        }
    }
    print $FH "          __typeCode = org.omg.CORBA.ORB.init ().create_alias_tc (",$node->{java_Helper},".id (), \"",$node->{java_helper},"\", __typeCode);\n";
##  print $FH "          __active = false;\n";
##  print $FH "        }\n";
##  print $FH "      }\n";
    print $FH "    }\n";
    print $FH "    return __typeCode;\n";
    print $FH "  }\n";
    print $FH "\n";
    print $FH "  public static java.lang.String id ()\n";
    print $FH "  {\n";
    print $FH "    return _id;\n";
    print $FH "  }\n";
    print $FH "\n";
    print $FH "  public static ",$type->{java_Name},@{$array}," read (org.omg.CORBA.portable.InputStream \$is)\n";
    print $FH "  {\n";
    if (scalar(@{$array})) {
        print $FH "    ",$type->{java_Name}," value",@{$array}," = null;\n";
    }
    else {
        print $FH "    ",$type->{java_Name}," value = ",$type->{java_init},";\n";
    }
    my @tab = (q{ } x 4);
    my $i = 0;
    my $idx = q{};
    my @array1= @{$array};
    if (exists $node->{array_size}) {
        foreach (@{$node->{array_size}}) {
            pop @array1;
            print $FH @tab,"value",$idx," = new ",$type->{java_Name}," [",$_->{java_literal},"]",@array1,";\n";
            print $FH @tab,"for (int _o",$i," = 0; _o",$i," < (",$_->{java_literal},"); _o",$i,"++)\n";
            print $FH @tab,"{\n";
            $idx .= '[_o' . $i . ']';
            $i ++;
            push @tab, q{ } x 2;
        }
    }
    foreach (@{$array_max}) {
        pop @array1;

lib/CORBA/JAVA/ClassVisitor.pm  view on Meta::CPAN

        }
    }
    my $type2 = $type;

    if (exists $node->{array_size} or exists $type->{array_size} or scalar(@array)) {
        if (exists $node->{array_size}) {
            foreach (@{$node->{array_size}}) {
                push @array, '[]';
            }
        }
        while ($type->isa('TypeDeclarator')) {
            foreach (@{$type->{array_size}}) {
                push @array, '[]';
            }
            $type = $self->_get_defn($type->{type});
        }
        while ($type->isa('SequenceType')) {
            push @array, '[]';
            $type = $self->_get_defn($type->{type});
            while (     $type->isa('TypeDeclarator')
                    and ! exists $type->{array_size} ) {
                $type = $self->_get_defn($type->{type});
            }
        }
        $self->_holder($node, $type, @array);
        $self->_typedeclarator_helper($node, $type, \@array, $type2, \@array_max);
        $self->_typedeclarator_helperXML($node, $type, \@array, $type2, \@array_max)
                if ($self->can('_typedeclarator_helperXML'));
    }
    else {
        while (     $type->isa('TypeDeclarator')
                and ! exists $type->{array_size} ) {
            $type = $self->_get_defn($type->{type});
        }
        $self->_typedeclarator_helper($node, $type, \@array, $type2, \@array_max);
        $self->_typedeclarator_helperXML($node, $type, \@array, $type2, \@array_max)
                if ($self->can('_typedeclarator_helperXML'));
    }
}

sub _native_helper {
    my ($self, $node) = @_;

    $self->open_stream($node, 'Helper.java');
    my $FH = $self->{out};
    print $FH "abstract public class ",$node->{java_helper},"Helper\n";
    print $FH "{\n";
    print $FH "  private static java.lang.String _id = \"",$node->{repos_id},"\";\n";
    print $FH "\n";
    print $FH "  public static void insert (org.omg.CORBA.Any a, ",$node->{java_Name}," that)\n";
    print $FH "  {\n";
    print $FH "    throw new org.omg.CORBA.MARSHAL();\n";
    print $FH "  }\n";
    print $FH "\n";
    print $FH "  public static ",$node->{java_Name}," extract (org.omg.CORBA.Any a)\n";
    print $FH "  {\n";
    print $FH "    throw new org.omg.CORBA.MARSHAL();\n";
    print $FH "  }\n";
    print $FH "\n";
    print $FH "  private static org.omg.CORBA.TypeCode __typeCode = null;\n";
    print $FH "  synchronized public static org.omg.CORBA.TypeCode type ()\n";
    print $FH "  {\n";
    print $FH "    if (__typeCode == null)\n";
    print $FH "    {\n";
    print $FH "      __typeCode = org.omg.CORBA.ORB.init ().get_primitive_tc (org.omg.CORBA.TCKind.tk_objref);\n";
    print $FH "      __typeCode = org.omg.CORBA.ORB.init ().create_alias_tc (",$node->{java_Helper},".id (), \"",$node->{java_helper},"\", __typeCode);\n";
    print $FH "    }\n";
    print $FH "    return __typeCode;\n";
    print $FH "  }\n";
    print $FH "\n";
    print $FH "  public static java.lang.String id ()\n";
    print $FH "  {\n";
    print $FH "    return _id;\n";
    print $FH "  }\n";
    print $FH "\n";
    print $FH "  public static ",$node->{java_Name}," read (org.omg.CORBA.portable.InputStream \$is)\n";
    print $FH "  {\n";
    print $FH "    throw new org.omg.CORBA.MARSHAL();\n";
    print $FH "  }\n";
    print $FH "\n";
    print $FH "  public static void write (org.omg.CORBA.portable.OutputStream \$os, ",$node->{java_Name}," value)\n";
    print $FH "  {\n";
    print $FH "    throw new org.omg.CORBA.MARSHAL();\n";
    print $FH "  }\n";
    print $FH "\n";
    print $FH "}\n";
    close $FH;
}

sub visitNativeType {
    my $self = shift;
    my ($node) = @_;
    return unless ($self->{srcname} eq $node->{filename});
    $self->_native_helper($node);
}

#
#   3.11.2  Constructed Types
#
#   3.11.2.1    Structures
#

sub _struct_helper {
    my ($self, $node) = @_;

    $self->open_stream($node, 'Helper.java');
    my $FH = $self->{out};
    print $FH "abstract public class ",$node->{java_helper},"Helper\n";
    print $FH "{\n";
    print $FH "  private static java.lang.String _id = \"",$node->{repos_id},"\";\n";
    print $FH "\n";
    print $FH "  public static void insert (org.omg.CORBA.Any a, ",$node->{java_Name}," that)\n";
    print $FH "  {\n";
    print $FH "    org.omg.CORBA.portable.OutputStream out = a.create_output_stream ();\n";
    print $FH "    a.type (type ());\n";
    print $FH "    write (out, that);\n";
    print $FH "    a.read_value (out.create_input_stream (), type ());\n";
    print $FH "  }\n";
    print $FH "\n";
    print $FH "  public static ",$node->{java_Name}," extract (org.omg.CORBA.Any a)\n";
    print $FH "  {\n";
    print $FH "    return read (a.create_input_stream ());\n";
    print $FH "  }\n";
    print $FH "\n";
    print $FH "  private static org.omg.CORBA.TypeCode __typeCode = null;\n";
    print $FH "  private static boolean __active = false;\n";
    print $FH "  synchronized public static org.omg.CORBA.TypeCode type ()\n";
    print $FH "  {\n";
    print $FH "    if (__typeCode == null)\n";
    print $FH "    {\n";
    print $FH "      synchronized (org.omg.CORBA.TypeCode.class)\n";
    print $FH "      {\n";
    print $FH "        if (__typeCode == null)\n";
    print $FH "        {\n";
    print $FH "          if (__active)\n";
    print $FH "          {\n";
    print $FH "            return org.omg.CORBA.ORB.init().create_recursive_tc ( ",$node->{java_Helper},".id () );\n";
    print $FH "          }\n";
    print $FH "          __active = true;\n";
    print $FH "          org.omg.CORBA.StructMember[] _members0 = new org.omg.CORBA.StructMember [",scalar(@{$node->{list_member}}),"];\n";
    print $FH "          org.omg.CORBA.TypeCode _tcOf_members0 = null;\n";
    my $i = 0;
    foreach (@{$node->{list_member}}) {
        my $member = $self->_get_defn($_);
        $self->_member_helper_type($member, $node, $i);
        $i ++;
    }
    print $FH "          __typeCode = org.omg.CORBA.ORB.init ().create_struct_tc (_id, \"",$node->{java_name},"\", _members0);\n";
    print $FH "          __active = false;\n";
    print $FH "        }\n";
    print $FH "      }\n";
    print $FH "    }\n";
    print $FH "    return __typeCode;\n";
    print $FH "  }\n";
    print $FH "\n";
    print $FH "  public static java.lang.String id ()\n";
    print $FH "  {\n";
    print $FH "    return _id;\n";
    print $FH "  }\n";
    print $FH "\n";
    print $FH "  public static ",$node->{java_Name}," read (org.omg.CORBA.portable.InputStream \$is)\n";
    print $FH "  {\n";
    print $FH "    ",$node->{java_Name}," value = new ",$node->{java_Name}," ();\n";
    my $idx = 0;
    foreach (@{$node->{list_member}}) {
        my $member = $self->_get_defn($_);
        $self->_member_helper_read($member, $node, \$idx);
    }
    print $FH "    return value;\n";
    print $FH "  }\n";
    print $FH "\n";
    print $FH "  public static void write (org.omg.CORBA.portable.OutputStream \$os, ",$node->{java_Name}," value)\n";
    print $FH "  {\n";
    $idx = 0;
    foreach (@{$node->{list_member}}) {
        my $member = $self->_get_defn($_);
        $self->_member_helper_write($member, $node, \$idx);
    }
    print $FH "  }\n";
    print $FH "\n";
    print $FH "}\n";
    close $FH;
}

sub _struct {
    my ($self, $node) = @_;

    $self->open_stream($node, '.java');
    my $FH = $self->{out};
    print $FH $self->_format_javadoc($node);
    print $FH "public final class ",$node->{java_name}," implements org.omg.CORBA.portable.IDLEntity\n";

lib/CORBA/JAVA/ClassVisitor.pm  view on Meta::CPAN


    my $FH = $self->{out};
    my $name = $member->{java_name};
    my $label = q{};
    my @tab = (q{ } x 6);
    my $idx = q{};
    foreach (my $a = 0; $a < length($member->{java_array})/2; $a ++) {
        print $FH @tab,"if (res = (this.",$label,$name,$idx,".length == obj.",$label,$name,$idx,".length))\n";
        print $FH @tab,"{\n";
        print $FH @tab,"  for (int _i",$$r_idx," = 0; res && _i",$$r_idx," < this.",$label,$name,$idx,".length; _i",$$r_idx,"++)\n";
        print $FH @tab,"  {\n";
        $idx .= '[_i' . $$r_idx . ']';
        $$r_idx ++;
        push @tab, q{ } x 4;
    }
    if (       $member->{type_java}->isa('StringType')
            or $member->{type_java}->isa('WideStringType')
            or $member->{type_java}->isa('StructType')
            or $member->{type_java}->isa('UnionType')
            or $member->{type_java}->isa('Interface')
            or $member->{type_java}->isa('Value') ) {
        print $FH @tab,"res = (this.",$label,$name,$idx," == null && obj.",$label,$name,$idx," == null) || (this.",$label,$name,$idx," != null && this.",$member->{java_name},".equals(obj.",$label,$name,$idx,"));\n";
    }
    else {
        print $FH @tab,"res = (this.",$label,$name,$idx," == obj.",$label,$name,$idx,");\n";
    }
    foreach (my $a = 0; $a < length($member->{java_array})/2; $a ++) {
        pop @tab;
        print $FH @tab,"  }\n";
        print $FH @tab,"}\n";
    }
}

#   3.11.2.2    Discriminated Unions
#

sub _union_helper {
    my ($self, $node, $dis, $effective_dis) = @_;

    $self->open_stream($node, 'Helper.java');
    my $FH = $self->{out};
    print $FH "abstract public class ",$node->{java_helper},"Helper\n";
    print $FH "{\n";
    print $FH "  private static java.lang.String _id = \"",$node->{repos_id},"\";\n";
    print $FH "\n";
    print $FH "  public static void insert (org.omg.CORBA.Any a, ",$node->{java_Name}," that)\n";
    print $FH "  {\n";
    print $FH "    org.omg.CORBA.portable.OutputStream out = a.create_output_stream ();\n";
    print $FH "    a.type (type ());\n";
    print $FH "    write (out, that);\n";
    print $FH "    a.read_value (out.create_input_stream (), type ());\n";
    print $FH "  }\n";
    print $FH "\n";
    print $FH "  public static ",$node->{java_Name}," extract (org.omg.CORBA.Any a)\n";
    print $FH "  {\n";
    print $FH "    return read (a.create_input_stream ());\n";
    print $FH "  }\n";
    print $FH "\n";
    print $FH "  private static org.omg.CORBA.TypeCode __typeCode = null;\n";
    print $FH "  private static boolean __active = false;\n";
    print $FH "  synchronized public static org.omg.CORBA.TypeCode type ()\n";
    print $FH "  {\n";
    print $FH "    if (__typeCode == null)\n";
    print $FH "    {\n";
    print $FH "      synchronized (org.omg.CORBA.TypeCode.class)\n";
    print $FH "      {\n";
    print $FH "        if (__typeCode == null)\n";
    print $FH "        {\n";
    print $FH "          if (__active)\n";
    print $FH "          {\n";
    print $FH "            return org.omg.CORBA.ORB.init().create_recursive_tc ( ",$node->{java_Helper},".id () );\n";
    print $FH "          }\n";
    print $FH "          __active = true;\n";
    print $FH "          org.omg.CORBA.TypeCode _disTypeCode0;\n";
    if ($effective_dis->isa('EnumType')) {
        print $FH "          _disTypeCode0 = ",$dis->{java_Name},"Helper.type ();\n";
    }
    else {
        print $FH "          _disTypeCode0 = org.omg.CORBA.ORB.init ().get_primitive_tc (org.omg.CORBA.TCKind.tk_",$dis->{java_tk},");\n";
    }
    print $FH "          org.omg.CORBA.UnionMember[] _members0 = new org.omg.CORBA.UnionMember [",scalar(keys %{$node->{hash_member}}),"];\n";
    print $FH "          org.omg.CORBA.TypeCode _tcOf_members0;\n";
    print $FH "          org.omg.CORBA.Any _anyOf_members0;\n";
    my $i = 0;
    foreach my $case (@{$node->{list_expr}}) {
        my $elt = $case->{element};
        my $value = $self->_get_defn($elt->{value});
        foreach (@{$case->{list_label}}) {  # default or expression
            print $FH "\n";
            if ($_->isa('Default')) {
                print $FH "          // Branch for ",$value->{java_name}," (Default case)\n";
                print $FH "          _anyOf_members0 = org.omg.CORBA.ORB.init ().create_any ();\n";
                print $FH "          _anyOf_members0.insert_octet ((byte)0); // default member label\n";
            }
            else {
                print $FH "          // Branch for ",$value->{java_name}," (case label ",$_->{java_literal},")\n";
                print $FH "          _anyOf_members0 = org.omg.CORBA.ORB.init ().create_any ();\n";
                if ($effective_dis->isa('EnumType')) {
                    print $FH "          ",$dis->{java_Name},"Helper.insert (_anyOf_members0, ",$_->{value}->{java_literal},");\n";
                }
                else {
                    print $FH "          _anyOf_members0.insert_",$dis->{java_tk}," (",$_->{java_literal},");\n";
                    # TODO
                }
            }
            $self->_member_helper_type($value, $node, $i);
            $i ++;
        }
    }
    print $FH "          __typeCode = org.omg.CORBA.ORB.init ().create_union_tc (_id, \"",$node->{java_name},"\", _disTypeCode0, _members0);\n";
    print $FH "          __active = false;\n";
    print $FH "        }\n";
    print $FH "      }\n";
    print $FH "    }\n";
    print $FH "    return __typeCode;\n";
    print $FH "  }\n";
    print $FH "\n";
    print $FH "  public static java.lang.String id ()\n";
    print $FH "  {\n";
    print $FH "    return _id;\n";
    print $FH "  }\n";
    print $FH "\n";
    print $FH "  public static ",$node->{java_Name}," read (org.omg.CORBA.portable.InputStream \$is)\n";
    print $FH "  {\n";
    print $FH "    ",$node->{java_Name}," value = new ",$node->{java_Name}," ();\n";

lib/CORBA/JAVA/ClassVisitor.pm  view on Meta::CPAN

        my $type = $self->_get_defn($_->{element}->{type});
        if (       $type->isa('StructType')
                or $type->isa('UnionType')
                or $type->isa('EnumType') ) {
            $type->visit($self);
        }
    }
    my $dis = $self->_get_defn($node->{type});
    my $effective_dis = $dis;
    while (     $effective_dis->isa('TypeDeclarator')
           and ! exists $effective_dis->{array_size} ) {
        $effective_dis = $self->_get_defn($effective_dis->{type});
    }

    $dis->visit($self) if ($effective_dis->isa('EnumType'));

    $self->_holder($node);
    $self->_union_helper($node, $dis, $effective_dis);
    $self->_union($node, $dis, $effective_dis);
    $self->_union_helperXML($node, $dis, $effective_dis) if ($self->can('_union_helperXML'));
}

#   3.11.2.3    Constructed Recursive Types and Forward Declarations
#

sub visitForwardStructType {
    # empty
}

sub visitForwardUnionType {
    # empty
}

#   3.11.2.4    Enumerations
#

sub _enum_helper {
    my ($self, $node) = @_;

    $self->open_stream($node, 'Helper.java');
    my $FH = $self->{out};
    print $FH "abstract public class ",$node->{java_helper},"Helper\n";
    print $FH "{\n";
    print $FH "  private static java.lang.String _id = \"",$node->{repos_id},"\";\n";
    print $FH "\n";
    print $FH "  public static void insert (org.omg.CORBA.Any a, ",$node->{java_Name}," that)\n";
    print $FH "  {\n";
    print $FH "    org.omg.CORBA.portable.OutputStream out = a.create_output_stream ();\n";
    print $FH "    a.type (type ());\n";
    print $FH "    write (out, that);\n";
    print $FH "    a.read_value (out.create_input_stream (), type ());\n";
    print $FH "  }\n";
    print $FH "\n";
    print $FH "  public static ",$node->{java_Name}," extract (org.omg.CORBA.Any a)\n";
    print $FH "  {\n";
    print $FH "    return read (a.create_input_stream ());\n";
    print $FH "  }\n";
    print $FH "\n";
    print $FH "  private static org.omg.CORBA.TypeCode __typeCode = null;\n";
    print $FH "  private static boolean __active = false;\n";
    print $FH "  synchronized public static org.omg.CORBA.TypeCode type ()\n";
    print $FH "  {\n";
    print $FH "    if (__typeCode == null)\n";
    print $FH "    {\n";
    print $FH "      synchronized (org.omg.CORBA.TypeCode.class)\n";
    print $FH "      {\n";
    print $FH "        if (__typeCode == null)\n";
    print $FH "        {\n";
    print $FH "          if (__active)\n";
    print $FH "          {\n";
    print $FH "            return org.omg.CORBA.ORB.init().create_recursive_tc ( ",$node->{java_Helper},".id () );\n";
    print $FH "          }\n";
    print $FH "          __active = true;\n";
    print $FH "          __typeCode = org.omg.CORBA.ORB.init ().create_enum_tc (_id, \"",$node->{java_name},"\", new java.lang.String [] { ";
        my $first = 1;
        foreach (@{$node->{list_expr}}) {
            print $FH ", " unless ($first);
            print $FH "\"",$_->{java_name},"\"";
            $first = 0;
        }
        print $FH "} );\n";
    print $FH "          __active = false;\n";
    print $FH "        }\n";
    print $FH "      }\n";
    print $FH "    }\n";
    print $FH "    return __typeCode;\n";
    print $FH "  }\n";
    print $FH "\n";
    print $FH "  public static java.lang.String id ()\n";
    print $FH "  {\n";
    print $FH "    return _id;\n";
    print $FH "  }\n";
    print $FH "\n";
    print $FH "  public static ",$node->{java_Name}," read (org.omg.CORBA.portable.InputStream \$is)\n";
    print $FH "  {\n";
    print $FH "    return ",$node->{java_Name},".from_int (\$is.read_long ());\n";
    print $FH "  }\n";
    print $FH "\n";
    print $FH "  public static void write (org.omg.CORBA.portable.OutputStream \$os, ",$node->{java_Name}," value)\n";
    print $FH "  {\n";
    print $FH "    \$os.write_long (value.value ());\n";
    print $FH "  }\n";
    print $FH "\n";
    print $FH "}\n";
    close $FH;
}

sub _enum {
    my ($self, $node) = @_;

    $self->open_stream($node, '.java');
    my $FH = $self->{out};
    print $FH $self->_format_javadoc($node);
    print $FH "public class ",$node->{java_name}," implements org.omg.CORBA.portable.IDLEntity\n";
    print $FH "{\n";
    if (exists $node->{serial_uid}) {
        print $FH "  private static final long serialVersionUID = 0x",$node->{serial_uid},"L;\n";
    }
    else {
        print $FH "  private static final long serialVersionUID = 0x",$node->{java_uid},"L;\n";
    }
    print $FH "\n";
    print $FH "  private        int __value;\n";
    print $FH "\n";
    foreach (@{$node->{list_expr}}) {

lib/CORBA/JAVA/ClassVisitor.pm  view on Meta::CPAN

        print $FH "  public boolean equals (java.lang.Object o)\n";
        print $FH "  {\n";
        print $FH "    if (this == o) return true;\n";
        print $FH "    if (o == null) return false;\n";
        print $FH "\n";
        print $FH "    if (o instanceof ",$node->{java_name},")\n";
        print $FH "      return (this.__value == ((",$node->{java_name},")o).__value);\n";
        print $FH "    return false;\n";
        print $FH "  }\n";
        print $FH "\n";
        print $FH "  public int hashCode ()\n";
        print $FH "  {\n";
        print $FH "    // this method returns always the same value, to force equals() to be called.\n";
        print $FH "    return 0;\n";
        print $FH "  }\n";
        print $FH "\n";
    }
    print $FH "} // class ",$node->{java_name},"\n";
    close $FH;
}

sub visitEnumType {
    my $self = shift;
    my ($node) = @_;
    return unless ($self->{srcname} eq $node->{filename});

    $self->_holder($node);
    $self->_enum_helper($node);
    $self->_enum($node);
    $self->_enum_helperXML($node) if ($self->can('_enum_helperXML'));
}

#
#   3.12    Exception Declaration
#

sub _exception_helper {
    my ($self, $node) = @_;

    $self->open_stream($node, 'Helper.java');
    my $FH = $self->{out};
    print $FH "abstract public class ",$node->{java_helper},"Helper\n";
    print $FH "{\n";
    print $FH "  private static java.lang.String _id = \"",$node->{repos_id},"\";\n";
    print $FH "\n";
    print $FH "  public static void insert (org.omg.CORBA.Any a, ",$node->{java_Name}," that)\n";
    print $FH "  {\n";
    print $FH "    org.omg.CORBA.portable.OutputStream out = a.create_output_stream ();\n";
    print $FH "    a.type (type ());\n";
    print $FH "    write (out, that);\n";
    print $FH "    a.read_value (out.create_input_stream (), type ());\n";
    print $FH "  }\n";
    print $FH "\n";
    print $FH "  public static ",$node->{java_Name}," extract (org.omg.CORBA.Any a)\n";
    print $FH "  {\n";
    print $FH "    return read (a.create_input_stream ());\n";
    print $FH "  }\n";
    print $FH "\n";
    print $FH "  private static org.omg.CORBA.TypeCode __typeCode = null;\n";
    print $FH "  private static boolean __active = false;\n";
    print $FH "  synchronized public static org.omg.CORBA.TypeCode type ()\n";
    print $FH "  {\n";
    print $FH "    if (__typeCode == null)\n";
    print $FH "    {\n";
    print $FH "      synchronized (org.omg.CORBA.TypeCode.class)\n";
    print $FH "      {\n";
    print $FH "        if (__typeCode == null)\n";
    print $FH "        {\n";
    print $FH "          if (__active)\n";
    print $FH "          {\n";
    print $FH "            return org.omg.CORBA.ORB.init().create_recursive_tc ( ",$node->{java_Helper},".id () );\n";
    print $FH "          }\n";
    print $FH "          __active = true;\n";
    print $FH "          org.omg.CORBA.StructMember[] _members0 = new org.omg.CORBA.StructMember [",scalar(@{$node->{list_member}}),"];\n";
    print $FH "          org.omg.CORBA.TypeCode _tcOf_members0 = null;\n";
    my $i = 0;
    foreach (@{$node->{list_member}}) {
        my $member = $self->_get_defn($_);
        $self->_member_helper_type($member, $node, $i);
        $i ++;
    }
    print $FH "          __typeCode = org.omg.CORBA.ORB.init ().create_exception_tc (_id, \"",$node->{java_name},"\", _members0);\n";
    print $FH "          __active = false;\n";
    print $FH "        }\n";
    print $FH "      }\n";
    print $FH "    }\n";
    print $FH "    return __typeCode;\n";
    print $FH "  }\n";
    print $FH "\n";
    print $FH "  public static java.lang.String id ()\n";
    print $FH "  {\n";
    print $FH "    return _id;\n";
    print $FH "  }\n";
    print $FH "\n";
    print $FH "  public static ",$node->{java_Name}," read (org.omg.CORBA.portable.InputStream \$is)\n";
    print $FH "  {\n";
    print $FH "    ",$node->{java_Name}," value = new ",$node->{java_Name}," ();\n";
    print $FH "    // read and discard the repository ID\n";
    print $FH "    \$is.read_string ();\n";
    my $idx = 0;
    foreach (@{$node->{list_member}}) {
        my $member = $self->_get_defn($_);
        $self->_member_helper_read($member, $node, \$idx);
    }
    print $FH "    return value;\n";
    print $FH "  }\n";
    print $FH "\n";
    print $FH "  public static void write (org.omg.CORBA.portable.OutputStream \$os, ",$node->{java_Name}," value)\n";
    print $FH "  {\n";
    print $FH "    // write the repository ID\n";
    print $FH "    \$os.write_string (id ());\n";
    $idx = 0;
    foreach (@{$node->{list_member}}) {
        my $member = $self->_get_defn($_);
        $self->_member_helper_write($member, $node, \$idx);
    }
    print $FH "  }\n";
    print $FH "\n";
    print $FH "}\n";
    close $FH;
}

sub _exception {
    my ($self, $node) = @_;



( run in 1.522 second using v1.01-cache-2.11-cpan-9581c071862 )