| 1 | |||
| 2 | # | ||
| 3 | # Interface Definition Language (OMG IDL CORBA v3.0) | ||
| 4 | # | ||
| 5 | |||
| 6 | package CORBA::JAVA::ClassXmlVisitor; | ||
| 7 | |||
| 8 | use strict; | ||
| 9 | use warnings; | ||
| 10 | |||
| 11 | our $VERSION = '2.63'; | ||
| 12 | |||
| 13 | use CORBA::JAVA::ClassVisitor; | ||
| 14 | use base qw(CORBA::JAVA::ClassVisitor); | ||
| 15 | |||
| 16 | sub new { | ||
| 17 | my $proto = shift; | ||
| 18 | my $class = ref($proto) || $proto; | ||
| 19 | my $self = {}; | ||
| 20 | bless $self, $class; | ||
| 21 | my ($parser) = @_; | ||
| 22 | $self->{srcname} = $parser->YYData->{srcname}; | ||
| 23 | $self->{srcname_size} = $parser->YYData->{srcname_size}; | ||
| 24 | $self->{srcname_mtime} = $parser->YYData->{srcname_mtime}; | ||
| 25 | $self->{symbtab} = $parser->YYData->{symbtab}; | ||
| 26 | $self->{done_hash} = {}; | ||
| 27 | $self->{num_key} = 'num_javaxml'; | ||
| 28 | $self->{toString} = 1; | ||
| 29 | $self->{equals} = 1; | ||
| 30 | $self->{xml_pkg} = 'org.omg.CORBA.portable.XML'; | ||
| 31 | return $self; | ||
| 32 | } | ||
| 33 | |||
| 34 | # | ||
| 35 | # 3.8 Interface Declaration | ||
| 36 | # | ||
| 37 | |||
| 38 | sub _interface_helperXML { | ||
| 39 | my ($self, $node) = @_; | ||
| 40 | |||
| 41 | $self->open_stream($node, 'HelperXML.java'); | ||
| 42 | my $FH = $self->{out}; | ||
| 43 | print $FH "abstract public class ",$node->{java_helper},"HelperXML\n"; | ||
| 44 | print $FH "{\n"; | ||
| 45 | print $FH "\n"; | ||
| 46 | print $FH " public static ",$node->{java_Name}," read (",$self->{xml_pkg},"InputStream \$is)\n"; | ||
| 47 | print $FH " {\n"; | ||
| 48 | print $FH " return read (\$is, \"",$node->{xsd_name},"\");\n"; | ||
| 49 | print $FH " }\n"; | ||
| 50 | print $FH "\n"; | ||
| 51 | print $FH " public static ",$node->{java_Name}," read (",$self->{xml_pkg},"InputStream \$is, java.lang.String tag)\n"; | ||
| 52 | print $FH " {\n"; | ||
| 53 | print $FH " // TODO\n"; | ||
| 54 | print $FH " return null;\n"; | ||
| 55 | print $FH " }\n"; | ||
| 56 | print $FH "\n"; | ||
| 57 | print $FH " public static void write (",$self->{xml_pkg},"OutputStream \$os, ",$node->{java_Name}," value)\n"; | ||
| 58 | print $FH " {\n"; | ||
| 59 | print $FH " write (\$os, value, \"",$node->{xsd_name},"\");\n"; | ||
| 60 | print $FH " }\n"; | ||
| 61 | print $FH "\n"; | ||
| 62 | print $FH " public static void write (",$self->{xml_pkg},"OutputStream \$os, ",$node->{java_Name}," value, java.lang.String tag)\n"; | ||
| 63 | print $FH " {\n"; | ||
| 64 | print $FH " \$os.write_Object ((org.omg.CORBA.Object) value, tag);\n"; | ||
| 65 | print $FH " }\n"; | ||
| 66 | print $FH "\n"; | ||
| 67 | print $FH "}\n"; | ||
| 68 | close $FH; | ||
| 69 | } | ||
| 70 | |||
| 71 | # | ||
| 72 | # 3.9 Value Declaration | ||
| 73 | # | ||
| 74 | # 3.9.1 Regular Value Type | ||
| 75 | # | ||
| 76 | |||
| 77 | sub _value_helperXML { | ||
| 78 | my ($self, $node) = @_; | ||
| 79 | |||
| 80 | $self->open_stream($node, 'HelperXML.java'); | ||
| 81 | my $FH = $self->{out}; | ||
| 82 | print $FH "abstract public class ",$node->{java_helper},"HelperXML\n"; | ||
| 83 | print $FH "{\n"; | ||
| 84 | print $FH "\n"; | ||
| 85 | print $FH " public static ",$node->{java_Name}," read (",$self->{xml_pkg},"InputStream \$is)\n"; | ||
| 86 | print $FH " {\n"; | ||
| 87 | print $FH " return read (\$is, \"",$node->{xsd_name},"\");\n"; | ||
| 88 | print $FH " }\n"; | ||
| 89 | print $FH "\n"; | ||
| 90 | print $FH " public static ",$node->{java_Name}," read (",$self->{xml_pkg},"InputStream \$is, java.lang.String tag)\n"; | ||
| 91 | print $FH " {\n"; | ||
| 92 | print $FH " // TODO (Pb with instanciation)\n"; | ||
| 93 | print $FH " return null;\n"; | ||
| 94 | # print $FH " ",$node->{java_Name}," value = new ",$node->{java_Name}," ();\n"; | ||
| 95 | # print $FH " \$is.read_open_tag (tag);\n"; | ||
| 96 | my $idx = 0; | ||
| 97 | # foreach (@{$node->{list_member}}) { # StateMember | ||
| 98 | # my $member = $self->_get_defn($_); | ||
| 99 | # $self->_member_helperXML_read($member, $node, \$idx); | ||
| 100 | # } | ||
| 101 | # print $FH " \$is.read_close_tag (tag);\n"; | ||
| 102 | # print $FH " return value;\n"; | ||
| 103 | print $FH " }\n"; | ||
| 104 | print $FH "\n"; | ||
| 105 | print $FH " public static void write (",$self->{xml_pkg},"OutputStream \$os, ",$node->{java_Name}," value)\n"; | ||
| 106 | print $FH " {\n"; | ||
| 107 | print $FH " write (\$os, value, \"",$node->{xsd_name},"\");\n"; | ||
| 108 | print $FH " }\n"; | ||
| 109 | print $FH "\n"; | ||
| 110 | print $FH " public static void write (",$self->{xml_pkg},"OutputStream \$os, ",$node->{java_Name}," value, java.lang.String tag)\n"; | ||
| 111 | print $FH " {\n"; | ||
| 112 | print $FH " \$os.write_open_tag (tag);\n"; | ||
| 113 | $idx = 0; | ||
| 114 | foreach (@{$node->{list_member}}) { # StateMember | ||
| 115 | my $member = $self->_get_defn($_); | ||
| 116 | $self->_member_helperXML_write($member, $node, \$idx); | ||
| 117 | } | ||
| 118 | print $FH " \$os.write_close_tag (tag);\n"; | ||
| 119 | print $FH " }\n"; | ||
| 120 | print $FH "\n"; | ||
| 121 | print $FH "}\n"; | ||
| 122 | close $FH; | ||
| 123 | } | ||
| 124 | |||
| 125 | # 3.9.2 Boxed Value Type | ||
| 126 | # | ||
| 127 | |||
| 128 | sub _boxed_helperXML { | ||
| 129 | my ($self, $node, $type, $array, $type2, $array_max) = @_; | ||
| 130 | |||
| 131 | $self->open_stream($node, 'HelperXML.java'); | ||
| 132 | my $FH = $self->{out}; | ||
| 133 | # print $FH "public final class ",$node->{java_helper},"HelperXML implements org.omg.CORBA.portable.BoxedValueHelperXML\n"; | ||
| 134 | print $FH "public final class ",$node->{java_helper},"HelperXML\n"; | ||
| 135 | print $FH "{\n"; | ||
| 136 | print $FH "\n"; | ||
| 137 | if (exists $node->{java_primitive}) { | ||
| 138 | print $FH " public static ",$node->{java_Name}," read (",$self->{xml_pkg},"InputStream \$is)\n"; | ||
| 139 | } | ||
| 140 | else { | ||
| 141 | print $FH " public static ",$type->{java_Name},@{$array}," read (",$self->{xml_pkg},"InputStream \$is)\n"; | ||
| 142 | } | ||
| 143 | print $FH " {\n"; | ||
| 144 | print $FH " // TODO (PB instanciation)\n"; | ||
| 145 | print $FH " return null;\n"; | ||
| 146 | print $FH " }\n"; | ||
| 147 | print $FH "\n"; | ||
| 148 | if (exists $node->{java_primitive}) { | ||
| 149 | print $FH " public static void write (",$self->{xml_pkg},"OutputStream \$os, ",$node->{java_Name}," value)\n"; | ||
| 150 | } | ||
| 151 | else { | ||
| 152 | print $FH " public static void write (",$self->{xml_pkg},"OutputStream \$os, ",$type->{java_Name},@{$array}," value)\n"; | ||
| 153 | } | ||
| 154 | print $FH " {\n"; | ||
| 155 | print $FH " write (\$os, value, \"",$node->{xsd_name},"\");\n"; | ||
| 156 | print $FH " }\n"; | ||
| 157 | print $FH "\n"; | ||
| 158 | if (exists $node->{java_primitive}) { | ||
| 159 | print $FH " public static void write (",$self->{xml_pkg},"OutputStream \$os, ",$node->{java_Name}," value, java.lang.String tag)\n"; | ||
| 160 | } | ||
| 161 | else { | ||
| 162 | print $FH " public static void write (",$self->{xml_pkg},"OutputStream \$os, ",$type->{java_Name},@{$array}," value, java.lang.String tag)\n"; | ||
| 163 | } | ||
| 164 | print $FH " {\n"; | ||
| 165 | print $FH " \$os.write_open_tag (tag);\n"; | ||
| 166 | if (exists $node->{java_primitive}) { | ||
| 167 | print $FH " ",$type->{java_write_xml},"value.value, \"value\");\n"; | ||
| 168 | } | ||
| 169 | else { | ||
| 170 | my @tab = (q{ } x 4); | ||
| 171 | my $i = 0; | ||
| 172 | my $idx = q{}; | ||
| 173 | my $tag; | ||
| 174 | my $nb_item = scalar(@{$array}); | ||
| 175 | if (exists $node->{array_size}) { | ||
| 176 | foreach (@{$node->{array_size}}) { | ||
| 177 | $tag = $i ? "\"item" . ($nb_item - $i) . "\"" : "\"value\""; | ||
| 178 | print $FH @tab,"\$os.write_open_tag (",$tag,");\n"; | ||
| 179 | print $FH @tab,"if (value",$idx,".length != (",$_->{java_literal},"))\n"; | ||
| 180 | print $FH @tab," throw new org.omg.CORBA.MARSHAL (0, org.omg.CORBA.CompletionStatus.COMPLETED_MAYBE);\n"; | ||
| 181 | print $FH @tab,"for (int _i",$i," = 0; _i",$i," < (",$_->{java_literal},"); _i",$i,"++)\n"; | ||
| 182 | print $FH @tab,"{\n"; | ||
| 183 | $idx .= '[_i' . $i . ']'; | ||
| 184 | $i ++; | ||
| 185 | push @tab, q{ } x 2; | ||
| 186 | } | ||
| 187 | } | ||
| 188 | foreach (@{$array_max}) { | ||
| 189 | $tag = $i ? "\"item" . ($nb_item - $i) . "\"" : "\"value\""; | ||
| 190 | print $FH @tab,"\$os.write_open_tag (",$tag,");\n"; | ||
| 191 | if (defined $_) { | ||
| 192 | print $FH @tab,"if (value",$idx,".length > (",$_->{java_literal},"))\n"; | ||
| 193 | print $FH @tab," throw new org.omg.CORBA.MARSHAL (0, org.omg.CORBA.CompletionStatus.COMPLETED_MAYBE);\n"; | ||
| 194 | } | ||
| 195 | print $FH @tab,"for (int _i",$i," = 0; _i",$i," < value",$idx,".length; _i",$i,"++)\n"; | ||
| 196 | print $FH @tab,"{\n"; | ||
| 197 | $idx .= '[_i' . $i . ']'; | ||
| 198 | $i ++; | ||
| 199 | push @tab, q{ } x 2; | ||
| 200 | } | ||
| 201 | if (($type2->isa('StringType') or $type2->isa('WideStringType')) and exists $type2->{max}) { | ||
| 202 | print $FH @tab,"if (value",$idx,".length () > (",$type2->{max}->{java_literal},"))\n"; | ||
| 203 | print $FH @tab," throw new org.omg.CORBA.MARSHAL (0, org.omg.CORBA.CompletionStatus.COMPLETED_MAYBE);\n"; | ||
| 204 | } | ||
| 205 | $tag = $i ? "\"item\"" : "\"value\""; | ||
| 206 | print $FH @tab,$type2->{java_write_xml},"value",$idx,", ",$tag,");\n"; | ||
| 207 | foreach (@{$array_max}) { | ||
| 208 | pop @tab; | ||
| 209 | $i --; | ||
| 210 | $tag = $i ? "\"item" . ($nb_item - $i) . "\"" : "\"value\""; | ||
| 211 | print $FH @tab,"}\n"; | ||
| 212 | print $FH @tab,"\$os.write_close_tag (",$tag,");\n"; | ||
| 213 | } | ||
| 214 | if (exists $node->{array_size}) { | ||
| 215 | foreach (@{$node->{array_size}}) { | ||
| 216 | pop @tab; | ||
| 217 | $i --; | ||
| 218 | $tag = $i ? "\"item" . ($nb_item - $i) . "\"" : "\"value\""; | ||
| 219 | print $FH @tab,"}\n"; | ||
| 220 | print $FH @tab,"\$os.write_close_tag (",$tag,");\n"; | ||
| 221 | } | ||
| 222 | } | ||
| 223 | } | ||
| 224 | print $FH " \$os.write_close_tag (tag);\n"; | ||
| 225 | print $FH " }\n"; | ||
| 226 | print $FH "\n"; | ||
| 227 | print $FH "}\n"; | ||
| 228 | close $FH; | ||
| 229 | } | ||
| 230 | |||
| 231 | # | ||
| 232 | # 3.11 Type Declaration | ||
| 233 | # | ||
| 234 | |||
| 235 | sub _typedeclarator_helperXML { | ||
| 236 | my ($self, $node, $type, $array, $type2, $array_max) = @_; | ||
| 237 | |||
| 238 | $self->open_stream($node, 'HelperXML.java'); | ||
| 239 | my $FH = $self->{out}; | ||
| 240 | print $FH "abstract public class ",$node->{java_helper},"HelperXML\n"; | ||
| 241 | print $FH "{\n"; | ||
| 242 | print $FH "\n"; | ||
| 243 | print $FH " public static ",$type->{java_Name},@{$array}," read (",$self->{xml_pkg},"InputStream \$is)\n"; | ||
| 244 | print $FH " {\n"; | ||
| 245 | print $FH " return read (\$is, \"",$node->{xsd_name},"\");\n"; | ||
| 246 | print $FH " }\n"; | ||
| 247 | print $FH "\n"; | ||
| 248 | print $FH " public static ",$type->{java_Name},@{$array}," read (",$self->{xml_pkg},"InputStream \$is, java.lang.String tag)\n"; | ||
| 249 | print $FH " {\n"; | ||
| 250 | if (scalar(@{$array})) { | ||
| 251 | print $FH " ",$type->{java_Name}," value",@{$array}," = null;\n"; | ||
| 252 | } | ||
| 253 | else { | ||
| 254 | print $FH " ",$type->{java_Name}," value = ",$type->{java_init},";\n"; | ||
| 255 | } | ||
| 256 | my @tab = (q{ } x 4); | ||
| 257 | my $i = 0; | ||
| 258 | my $idx = q{}; | ||
| 259 | my @array1= @{$array}; | ||
| 260 | my $tag; | ||
| 261 | my $nb_item = scalar(@{$array}); | ||
| 262 | if (exists $node->{array_size}) { | ||
| 263 | foreach (@{$node->{array_size}}) { | ||
| 264 | $tag = $i ? "\"item" . ($nb_item - $i) . "\"" : "tag"; | ||
| 265 | pop @array1; | ||
| 266 | print $FH @tab,"\$is.read_open_tag (",$tag,");\n"; | ||
| 267 | print $FH @tab,"value",$idx," = new ",$type->{java_Name}," [",$_->{java_literal},"]",@array1,";\n"; | ||
| 268 | print $FH @tab,"for (int _o",$i," = 0; _o",$i," < (",$_->{java_literal},"); _o",$i,"++)\n"; | ||
| 269 | print $FH @tab,"{\n"; | ||
| 270 | $idx .= '[_o' . $i . ']'; | ||
| 271 | $i ++; | ||
| 272 | push @tab, q{ } x 2; | ||
| 273 | } | ||
| 274 | } | ||
| 275 | foreach (@{$array_max}) { | ||
| 276 | $tag = $i ? "\"item" . ($nb_item - $i) . "\"" : "tag"; | ||
| 277 | pop @array1; | ||
| 278 | print $FH @tab,"\$is.read_open_tag (",$tag,");\n"; | ||
| 279 | print $FH @tab,"value",$idx," = new ",$type->{java_Name}," [0]",@array1,";\n"; | ||
| 280 | print $FH @tab,"for (int _o",$i," = 0; true; _o",$i,"++)\n"; | ||
| 281 | print $FH @tab,"{\n"; | ||
| 282 | print $FH @tab," try {\n"; | ||
| 283 | $idx .= '[_o' . $i . ']'; | ||
| 284 | $i ++; | ||
| 285 | push @tab, q{ } x 4; | ||
| 286 | } | ||
| 287 | $tag = $i ? "\"item\"" : "tag"; | ||
| 288 | print $FH @tab,"value",$idx," = ",$type2->{java_read_xml},$tag,");\n"; | ||
| 289 | if (($type2->isa('StringType') or $type2->isa('WideStringType')) and exists $type2->{max}) { | ||
| 290 | print $FH @tab,"if (value",$idx,".length () > (",$type2->{max}->{java_literal},"))\n"; | ||
| 291 | print $FH @tab," throw new org.omg.CORBA.MARSHAL (0, org.omg.CORBA.CompletionStatus.COMPLETED_MAYBE);\n"; | ||
| 292 | } | ||
| 293 | foreach (@{$array_max}) { | ||
| 294 | pop @tab; | ||
| 295 | $i --; | ||
| 296 | $tag = $i ? "\"item" . ($nb_item - $i) . "\"" : "tag"; | ||
| 297 | $idx =~ s/\[[^\]]+\]$//; | ||
| 298 | print $FH @tab," }\n"; | ||
| 299 | print $FH @tab," catch (Exception \$ex) {\n"; | ||
| 300 | print $FH @tab," break;\n"; | ||
| 301 | print $FH @tab," }\n"; | ||
| 302 | print $FH @tab,"}\n"; | ||
| 303 | if (defined $_) { | ||
| 304 | print $FH @tab,"if (value",$idx,".length > (",$_->{java_literal},"))\n"; | ||
| 305 | print $FH @tab," throw new org.omg.CORBA.MARSHAL (0, org.omg.CORBA.CompletionStatus.COMPLETED_MAYBE);\n"; | ||
| 306 | } | ||
| 307 | print $FH @tab,"\$is.read_close_tag (",$tag,");\n"; | ||
| 308 | } | ||
| 309 | if (exists $node->{array_size}) { | ||
| 310 | foreach (@{$node->{array_size}}) { | ||
| 311 | pop @tab; | ||
| 312 | $i --; | ||
| 313 | $tag = $i ? "\"item" . ($nb_item - $i) . "\"" : "tag"; | ||
| 314 | print $FH @tab,"}\n"; | ||
| 315 | print $FH @tab,"\$is.read_close_tag (",$tag,");\n"; | ||
| 316 | } | ||
| 317 | } | ||
| 318 | print $FH " return value;\n"; | ||
| 319 | print $FH " }\n"; | ||
| 320 | print $FH "\n"; | ||
| 321 | print $FH " public static void write (",$self->{xml_pkg},"OutputStream \$os, ",$type->{java_Name},@{$array}," value)\n"; | ||
| 322 | print $FH " {\n"; | ||
| 323 | print $FH " write (\$os, value, \"",$node->{xsd_name},"\");\n"; | ||
| 324 | print $FH " }\n"; | ||
| 325 | print $FH "\n"; | ||
| 326 | print $FH " public static void write (",$self->{xml_pkg},"OutputStream \$os, ",$type->{java_Name},@{$array}," value, java.lang.String tag)\n"; | ||
| 327 | print $FH " {\n"; | ||
| 328 | @tab = (q{ } x 4); | ||
| 329 | $i = 0; | ||
| 330 | $idx = q{}; | ||
| 331 | if (exists $node->{array_size}) { | ||
| 332 | foreach (@{$node->{array_size}}) { | ||
| 333 | $tag = $i ? "\"item" . ($nb_item - $i) . "\"" : "tag"; | ||
| 334 | print $FH @tab,"\$os.write_open_tag (",$tag,");\n"; | ||
| 335 | print $FH @tab,"if (value",$idx,".length != (",$_->{java_literal},"))\n"; | ||
| 336 | print $FH @tab," throw new org.omg.CORBA.MARSHAL (0, org.omg.CORBA.CompletionStatus.COMPLETED_MAYBE);\n"; | ||
| 337 | print $FH @tab,"for (int _i",$i," = 0; _i",$i," < (",$_->{java_literal},"); _i",$i,"++)\n"; | ||
| 338 | print $FH @tab,"{\n"; | ||
| 339 | $idx .= '[_i' . $i . ']'; | ||
| 340 | $i ++; | ||
| 341 | push @tab, q{ } x 2; | ||
| 342 | } | ||
| 343 | } | ||
| 344 | foreach (@{$array_max}) { | ||
| 345 | $tag = $i ? "\"item" . ($nb_item - $i) . "\"" : "tag"; | ||
| 346 | print $FH @tab,"\$os.write_open_tag (",$tag,");\n"; | ||
| 347 | if (defined $_) { | ||
| 348 | print $FH @tab,"if (value",$idx,".length > (",$_->{java_literal},"))\n"; | ||
| 349 | print $FH @tab," throw new org.omg.CORBA.MARSHAL (0, org.omg.CORBA.CompletionStatus.COMPLETED_MAYBE);\n"; | ||
| 350 | } | ||
| 351 | print $FH @tab,"for (int _i",$i," = 0; _i",$i," < value",$idx,".length; _i",$i,"++)\n"; | ||
| 352 | print $FH @tab,"{\n"; | ||
| 353 | $idx .= '[_i' . $i . ']'; | ||
| 354 | $i ++; | ||
| 355 | push @tab, q{ } x 2; | ||
| 356 | } | ||
| 357 | if (($type2->isa('StringType') or $type2->isa('WideStringType')) and exists $type2->{max}) { | ||
| 358 | print $FH @tab,"if (value",$idx,".length () > (",$type2->{max}->{java_literal},"))\n"; | ||
| 359 | print $FH @tab," throw new org.omg.CORBA.MARSHAL (0, org.omg.CORBA.CompletionStatus.COMPLETED_MAYBE);\n"; | ||
| 360 | } | ||
| 361 | $tag = $i ? "\"item\"" : "tag"; | ||
| 362 | print $FH @tab,$type2->{java_write_xml},"value",$idx,", ",$tag,");\n"; | ||
| 363 | foreach (@{$array_max}) { | ||
| 364 | pop @tab; | ||
| 365 | $i --; | ||
| 366 | $tag = $i ? "\"item" . ($nb_item - $i) . "\"" : "tag"; | ||
| 367 | print $FH @tab,"}\n"; | ||
| 368 | print $FH @tab,"\$os.write_close_tag (",$tag,");\n"; | ||
| 369 | } | ||
| 370 | if (exists $node->{array_size}) { | ||
| 371 | foreach (@{$node->{array_size}}) { | ||
| 372 | pop @tab; | ||
| 373 | $i --; | ||
| 374 | $tag = $i ? "\"item" . ($nb_item - $i) . "\"" : "tag"; | ||
| 375 | print $FH @tab,"}\n"; | ||
| 376 | print $FH @tab,"\$os.write_close_tag (",$tag,");\n"; | ||
| 377 | } | ||
| 378 | } | ||
| 379 | print $FH " }\n"; | ||
| 380 | print $FH "\n"; | ||
| 381 | print $FH "}\n"; | ||
| 382 | close $FH; | ||
| 383 | } | ||
| 384 | |||
| 385 | # | ||
| 386 | # 3.11.2 Constructed Types | ||
| 387 | # | ||
| 388 | # 3.11.2.1 Structures | ||
| 389 | # | ||
| 390 | |||
| 391 | sub _struct_helperXML { | ||
| 392 | my ($self, $node) = @_; | ||
| 393 | |||
| 394 | $self->open_stream($node, 'HelperXML.java'); | ||
| 395 | my $FH = $self->{out}; | ||
| 396 | print $FH "abstract public class ",$node->{java_name},"HelperXML\n"; | ||
| 397 | print $FH "{\n"; | ||
| 398 | print $FH "\n"; | ||
| 399 | print $FH " public static ",$node->{java_Name}," read (",$self->{xml_pkg},"InputStream \$is)\n"; | ||
| 400 | print $FH " {\n"; | ||
| 401 | print $FH " return read (\$is, \"",$node->{xsd_name},"\");\n"; | ||
| 402 | print $FH " }\n"; | ||
| 403 | print $FH "\n"; | ||
| 404 | print $FH " public static ",$node->{java_Name}," read (",$self->{xml_pkg},"InputStream \$is, java.lang.String tag)\n"; | ||
| 405 | print $FH " {\n"; | ||
| 406 | print $FH " ",$node->{java_Name}," value = new ",$node->{java_Name}," ();\n"; | ||
| 407 | print $FH " \$is.read_open_tag (tag);\n"; | ||
| 408 | my $idx = 0; | ||
| 409 | foreach (@{$node->{list_member}}) { | ||
| 410 | my $member = $self->_get_defn($_); | ||
| 411 | $self->_member_helperXML_read($member, $node, \$idx); | ||
| 412 | } | ||
| 413 | print $FH " \$is.read_close_tag (tag);\n"; | ||
| 414 | print $FH " return value;\n"; | ||
| 415 | print $FH " }\n"; | ||
| 416 | print $FH "\n"; | ||
| 417 | print $FH " public static void write (",$self->{xml_pkg},"OutputStream \$os, ",$node->{java_Name}," value)\n"; | ||
| 418 | print $FH " {\n"; | ||
| 419 | print $FH " write (\$os, value, \"",$node->{xsd_name},"\");\n"; | ||
| 420 | print $FH " }\n"; | ||
| 421 | print $FH "\n"; | ||
| 422 | print $FH " public static void write (",$self->{xml_pkg},"OutputStream \$os, ",$node->{java_Name}," value, java.lang.String tag)\n"; | ||
| 423 | print $FH " {\n"; | ||
| 424 | print $FH " \$os.write_open_tag (tag);\n"; | ||
| 425 | $idx = 0; | ||
| 426 | foreach (@{$node->{list_member}}) { | ||
| 427 | my $member = $self->_get_defn($_); | ||
| 428 | $self->_member_helperXML_write($member, $node, \$idx); | ||
| 429 | } | ||
| 430 | print $FH " \$os.write_close_tag (tag);\n"; | ||
| 431 | print $FH " }\n"; | ||
| 432 | print $FH "\n"; | ||
| 433 | print $FH "}\n"; | ||
| 434 | close $FH; | ||
| 435 | } | ||
| 436 | |||
| 437 | sub _member_helperXML_read { | ||
| 438 | my $self = shift; | ||
| 439 | my ($member, $parent, $r_idx) = @_; | ||
| 440 | |||
| 441 | my $FH = $self->{out}; | ||
| 442 | my $label = q{}; | ||
| 443 | # unless ($member->isa('StateMember')) { | ||
| 444 | if ($parent->isa('UnionType')) { | ||
| 445 | $label = '_'; | ||
| 446 | } | ||
| 447 | else { # StructType or ExceptionType | ||
| 448 | $label = 'value.'; | ||
| 449 | } | ||
| 450 | # } | ||
| 451 | my $type = $self->_get_defn($member->{type}); | ||
| 452 | my $name = $member->{java_name}; | ||
| 453 | my @tab = (q{ } x 4); | ||
| 454 | push @tab, q{ } x 4 if ($parent->isa('UnionType')); | ||
| 455 | my $idx = q{}; | ||
| 456 | my $i = 0; | ||
| 457 | my $tag; | ||
| 458 | my @array1 = (); | ||
| 459 | if (exists $member->{array_size}) { | ||
| 460 | foreach (@{$member->{array_size}}) { | ||
| 461 | push @array1, '[]'; | ||
| 462 | } | ||
| 463 | } | ||
| 464 | my @array_max = (); | ||
| 465 | while ($type->isa('SequenceType')) { | ||
| 466 | if (exists $type->{max}) { | ||
| 467 | push @array_max, $type->{max}; | ||
| 468 | } | ||
| 469 | else { | ||
| 470 | push @array_max, undef; | ||
| 471 | } | ||
| 472 | push @array1, '[]'; | ||
| 473 | $type = $self->_get_defn($type->{type}); | ||
| 474 | } | ||
| 475 | my $nb_item = scalar(@array_max); | ||
| 476 | $nb_item += scalar(@{$member->{array_size}}) if (exists $member->{array_size}); | ||
| 477 | if ($parent->isa('UnionType')) { | ||
| 478 | print $FH @tab," ",$member->{java_type}," _",$member->{java_name}," = ",$member->{java_init},";\n"; | ||
| 479 | } | ||
| 480 | if (exists $member->{array_size}) { | ||
| 481 | foreach (@{$member->{array_size}}) { | ||
| 482 | $tag = $i ? "\"item" . ($nb_item - $i) . "\"" : "\"" . $member->{xsd_name} . "\""; | ||
| 483 | pop @array1; | ||
| 484 | print $FH @tab,"\$is.read_open_tag (",$tag,");\n"; | ||
| 485 | if ($parent->isa('UnionType')) { | ||
| 486 | print $FH @tab,"_",$name,$idx," = new ",$type->{java_Name}," [",$_->{java_literal},"]",@array1,";\n"; | ||
| 487 | } | ||
| 488 | else { # StructType or ExceptionType | ||
| 489 | print $FH @tab,"value.",$name,$idx," = new ",$type->{java_Name}," [",$_->{java_literal},"]",@array1,";\n"; | ||
| 490 | } | ||
| 491 | print $FH @tab,"for (int _o",$$r_idx," = 0; _o",$$r_idx," < (",$_->{java_literal},"); _o",$$r_idx,"++)\n"; | ||
| 492 | print $FH @tab,"{\n"; | ||
| 493 | $idx .= '[_o' . $$r_idx . ']'; | ||
| 494 | $$r_idx ++; | ||
| 495 | $i ++; | ||
| 496 | push @tab, q{ } x 2; | ||
| 497 | } | ||
| 498 | } | ||
| 499 | foreach (@array_max) { | ||
| 500 | $tag = $i ? "\"item" . ($nb_item - $i) . "\"" : "\"" . $member->{xsd_name} . "\""; | ||
| 501 | pop @array1; | ||
| 502 | print $FH @tab,"\$is.read_open_tag (",$tag,");\n"; | ||
| 503 | if ($parent->isa('UnionType')) { | ||
| 504 | print $FH @tab,"_",$name,$idx," = new ",$type->{java_Name}," [0]",@array1,";\n"; | ||
| 505 | } | ||
| 506 | else { # StructType or ExceptionType | ||
| 507 | print $FH @tab,"value.",$name,$idx," = new ",$type->{java_Name}," [0]",@array1,";\n"; | ||
| 508 | } | ||
| 509 | print $FH @tab,"for (int _o",$$r_idx," = 0; true; _o",$$r_idx,"++)\n"; | ||
| 510 | print $FH @tab,"{\n"; | ||
| 511 | print $FH @tab," try {\n"; | ||
| 512 | $idx .= '[_o' . $$r_idx . ']'; | ||
| 513 | $$r_idx ++; | ||
| 514 | $i ++; | ||
| 515 | push @tab, q{ } x 4; | ||
| 516 | } | ||
| 517 | $tag = $i ? "\"item\"" : "\"" . $member->{xsd_name} . "\""; | ||
| 518 | if ($parent->isa('UnionType')) { | ||
| 519 | print $FH @tab,"_",$name,$idx," = ",$type->{java_read_xml},$tag,");\n"; | ||
| 520 | } | ||
| 521 | else { # StructType or ExceptionType | ||
| 522 | print $FH @tab,"value.",$name,$idx," = ",$type->{java_read_xml},$tag,");\n"; | ||
| 523 | } | ||
| 524 | if (($type->isa('StringType') or $type->isa('WideStringType')) and exists $type->{max}) { | ||
| 525 | print $FH @tab,"if (",$label,$name,$idx,".length () > (",$type->{max}->{java_literal},"))\n"; | ||
| 526 | print $FH @tab," throw new org.omg.CORBA.MARSHAL (0, org.omg.CORBA.CompletionStatus.COMPLETED_MAYBE);\n"; | ||
| 527 | } | ||
| 528 | foreach (@array_max) { | ||
| 529 | pop @tab; | ||
| 530 | $i --; | ||
| 531 | $tag = $i ? "\"item" . ($nb_item - $i) . "\"" : "\"" . $member->{xsd_name} . "\""; | ||
| 532 | $idx =~ s/\[[^\]]+\]$//; | ||
| 533 | print $FH @tab," }\n"; | ||
| 534 | print $FH @tab," catch (Exception \$ex) {\n"; | ||
| 535 | print $FH @tab," break;\n"; | ||
| 536 | print $FH @tab," }\n"; | ||
| 537 | print $FH @tab,"}\n"; | ||
| 538 | if (defined $_) { | ||
| 539 | print $FH @tab,"if (value",$idx,".length > (",$_->{java_literal},"))\n"; | ||
| 540 | print $FH @tab," throw new org.omg.CORBA.MARSHAL (0, org.omg.CORBA.CompletionStatus.COMPLETED_MAYBE);\n"; | ||
| 541 | } | ||
| 542 | print $FH @tab,"\$is.read_close_tag (",$tag,");\n"; | ||
| 543 | } | ||
| 544 | if (exists $member->{array_size}) { | ||
| 545 | foreach (@{$member->{array_size}}) { | ||
| 546 | pop @tab; | ||
| 547 | $i --; | ||
| 548 | $tag = $i ? "\"item" . ($nb_item - $i) . "\"" : "\"" . $member->{xsd_name} . "\""; | ||
| 549 | print $FH @tab,"}\n"; | ||
| 550 | print $FH @tab,"\$is.read_close_tag (",$tag,");\n"; | ||
| 551 | pop @tab; | ||
| 552 | } | ||
| 553 | } | ||
| 554 | } | ||
| 555 | |||
| 556 | sub _member_helperXML_write { | ||
| 557 | my $self = shift; | ||
| 558 | my ($member, $parent, $r_idx) = @_; | ||
| 559 | |||
| 560 | my $FH = $self->{out}; | ||
| 561 | # my $label = ($member->isa('StateMember')) ? q{} : 'value.'; | ||
| 562 | my $label = 'value.'; | ||
| 563 | my $type = $self->_get_defn($member->{type}); | ||
| 564 | my $name = $member->{java_name}; | ||
| 565 | my @tab = (q{ } x 4); | ||
| 566 | push @tab, q{ } x 4 if ($parent->isa('UnionType')); | ||
| 567 | my $idx = q{}; | ||
| 568 | my $i = 0; | ||
| 569 | my $tag; | ||
| 570 | my @array_max = (); | ||
| 571 | while ($type->isa('SequenceType')) { | ||
| 572 | if (exists $type->{max}) { | ||
| 573 | push @array_max, $type->{max}; | ||
| 574 | } | ||
| 575 | else { | ||
| 576 | push @array_max, undef; | ||
| 577 | } | ||
| 578 | $type = $self->_get_defn($type->{type}); | ||
| 579 | } | ||
| 580 | my $nb_item = scalar(@array_max); | ||
| 581 | $nb_item += scalar(@{$member->{array_size}}) if (exists $member->{array_size}); | ||
| 582 | if (exists $member->{array_size}) { | ||
| 583 | foreach (@{$member->{array_size}}) { | ||
| 584 | $tag = $i ? "\"item" . ($nb_item - $i) . "\"" : "\"" . $member->{xsd_name} . "\""; | ||
| 585 | print $FH @tab,"\$os.write_open_tag (",$tag,");\n"; | ||
| 586 | print $FH @tab,"if (value.",$name,$idx,".length != (",$_->{java_literal},"))\n"; | ||
| 587 | print $FH @tab," throw new org.omg.CORBA.MARSHAL (0, org.omg.CORBA.CompletionStatus.COMPLETED_MAYBE);\n"; | ||
| 588 | print $FH @tab,"for (int _i",$$r_idx," = 0; _i",$$r_idx," < (",$_->{java_literal},"); _i",$$r_idx,"++)\n"; | ||
| 589 | print $FH @tab,"{\n"; | ||
| 590 | $idx .= '[_i' . $$r_idx . ']'; | ||
| 591 | $$r_idx ++; | ||
| 592 | $i ++; | ||
| 593 | push @tab, q{ } x 2; | ||
| 594 | } | ||
| 595 | } | ||
| 596 | foreach (@array_max) { | ||
| 597 | $tag = $i ? "\"item" . ($nb_item - $i) . "\"" : "\"" . $member->{xsd_name} . "\""; | ||
| 598 | print $FH @tab,"\$os.write_open_tag (",$tag,");\n"; | ||
| 599 | if (defined $_) { | ||
| 600 | print $FH @tab,"if (value.",$name,$idx,".length > (",$_->{java_literal},"))\n"; | ||
| 601 | print $FH @tab," throw new org.omg.CORBA.MARSHAL (0, org.omg.CORBA.CompletionStatus.COMPLETED_MAYBE);\n"; | ||
| 602 | } | ||
| 603 | print $FH @tab,"for (int _i",$$r_idx," = 0; _i",$$r_idx," < value.",$name,$idx,".length; _i",$$r_idx,"++)\n"; | ||
| 604 | print $FH @tab,"{\n"; | ||
| 605 | $idx .= '[_i' . $$r_idx . ']'; | ||
| 606 | $$r_idx ++; | ||
| 607 | $i ++; | ||
| 608 | push @tab, q{ } x 2; | ||
| 609 | } | ||
| 610 | if (($type->isa('StringType') or $type->isa('WideStringType')) and exists $type->{max}) { | ||
| 611 | if ($parent->isa('UnionType')) { | ||
| 612 | print $FH @tab,"if (",$label,$name,$idx," ().length () > (",$type->{max}->{java_literal},"))\n"; | ||
| 613 | } | ||
| 614 | else { # StructType or ExceptionType | ||
| 615 | print $FH @tab,"if (",$label,$name,$idx,".length () > (",$type->{max}->{java_literal},"))\n"; | ||
| 616 | } | ||
| 617 | print $FH @tab," throw new org.omg.CORBA.MARSHAL (0, org.omg.CORBA.CompletionStatus.COMPLETED_MAYBE);\n"; | ||
| 618 | } | ||
| 619 | $tag = $i ? "\"item\"" : "\"" . $member->{xsd_name} . "\""; | ||
| 620 | if ($parent->isa('UnionType')) { | ||
| 621 | print $FH @tab,$type->{java_write_xml},"value.",$name," ()",$idx,", ",$tag,");\n"; | ||
| 622 | } | ||
| 623 | else { # StructType or ExceptionType | ||
| 624 | print $FH @tab,$type->{java_write_xml},"value.",$name,$idx,", ",$tag,");\n"; | ||
| 625 | } | ||
| 626 | foreach (@array_max) { | ||
| 627 | pop @tab; | ||
| 628 | $i --; | ||
| 629 | $tag = $i ? "\"item" . ($nb_item - $i) . "\"" : "\"" . $member->{xsd_name} . "\""; | ||
| 630 | print $FH @tab,"}\n"; | ||
| 631 | print $FH @tab,"\$os.write_close_tag (",$tag,");\n"; | ||
| 632 | } | ||
| 633 | if (exists $member->{array_size}) { | ||
| 634 | foreach (@{$member->{array_size}}) { | ||
| 635 | pop @tab; | ||
| 636 | $i --; | ||
| 637 | $tag = $i ? "\"item" . ($nb_item - $i) . "\"" : "\"" . $member->{xsd_name} . "\""; | ||
| 638 | print $FH @tab,"}\n"; | ||
| 639 | print $FH @tab,"\$os.write_close_tag (",$tag,");\n"; | ||
| 640 | } | ||
| 641 | } | ||
| 642 | } | ||
| 643 | |||
| 644 | # 3.11.2.2 Discriminated Unions | ||
| 645 | # | ||
| 646 | |||
| 647 | sub _union_helperXML { | ||
| 648 | my ($self, $node, $dis, $effective_dis) = @_; | ||
| 649 | |||
| 650 | $self->open_stream($node, 'HelperXML.java'); | ||
| 651 | my $FH = $self->{out}; | ||
| 652 | print $FH "abstract public class ",$node->{java_name},"HelperXML\n"; | ||
| 653 | print $FH "{\n"; | ||
| 654 | print $FH "\n"; | ||
| 655 | print $FH " public static ",$node->{java_Name}," read (",$self->{xml_pkg},"InputStream \$is)\n"; | ||
| 656 | print $FH " {\n"; | ||
| 657 | print $FH " return read (\$is, \"",$node->{xsd_name},"\");\n"; | ||
| 658 | print $FH " }\n"; | ||
| 659 | print $FH "\n"; | ||
| 660 | print $FH " public static ",$node->{java_Name}," read (",$self->{xml_pkg},"InputStream \$is, java.lang.String tag)\n"; | ||
| 661 | print $FH " {\n"; | ||
| 662 | print $FH " ",$node->{java_Name}," value = new ",$node->{java_Name}," ();\n"; | ||
| 663 | print $FH " ",$effective_dis->{java_Name}," _dis0 = ",$effective_dis->{java_init},";\n"; | ||
| 664 | print $FH " \$is.read_open_tag (tag);\n"; | ||
| 665 | print $FH " _dis0 = ",$dis->{java_read_xml},"\"discriminator\");\n"; | ||
| 666 | if ($effective_dis->isa('EnumType')) { | ||
| 667 | print $FH " switch (_dis0.value ())\n"; | ||
| 668 | } | ||
| 669 | else { | ||
| 670 | print $FH " switch (_dis0)\n"; | ||
| 671 | } | ||
| 672 | print $FH " {\n"; | ||
| 673 | my $idx = 0; | ||
| 674 | foreach my $case (@{$node->{list_expr}}) { | ||
| 675 | my $flag_default = 0; | ||
| 676 | foreach (@{$case->{list_label}}) { # default or expression | ||
| 677 | if ($_->isa('Default')) { | ||
| 678 | print $FH " default:\n"; | ||
| 679 | $flag_default = 1; | ||
| 680 | } | ||
| 681 | else { | ||
| 682 | print $FH " case ",$_->{java_literal},":\n"; | ||
| 683 | } | ||
| 684 | } | ||
| 685 | my $elt = $case->{element}; | ||
| 686 | my $value = $self->_get_defn($elt->{value}); | ||
| 687 | $self->_member_helperXML_read($value, $node, \$idx); | ||
| 688 | if (scalar(@{$case->{list_label}}) > 1 || $flag_default) { | ||
| 689 | if ($effective_dis->isa('EnumType')) { | ||
| 690 | print $FH " value.",$value->{java_name}," (_dis0.value (), _",$value->{java_name},");\n"; | ||
| 691 | } | ||
| 692 | else { | ||
| 693 | print $FH " value.",$value->{java_name}," (_dis0, _",$value->{java_name},");\n"; | ||
| 694 | } | ||
| 695 | } | ||
| 696 | else { | ||
| 697 | print $FH " value.",$value->{java_name}," (_",$value->{java_name},");\n"; | ||
| 698 | } | ||
| 699 | print $FH " break;\n"; | ||
| 700 | } | ||
| 701 | if (exists $node->{need_default}) { | ||
| 702 | print $FH " default:\n"; | ||
| 703 | print $FH " throw new org.omg.CORBA.BAD_OPERATION ();\n"; | ||
| 704 | } | ||
| 705 | print $FH " }\n"; | ||
| 706 | print $FH " \$is.read_close_tag (tag);\n"; | ||
| 707 | print $FH " return value;\n"; | ||
| 708 | print $FH " }\n"; | ||
| 709 | print $FH "\n"; | ||
| 710 | print $FH " public static void write (",$self->{xml_pkg},"OutputStream \$os, ",$node->{java_Name}," value)\n"; | ||
| 711 | print $FH " {\n"; | ||
| 712 | print $FH " write (\$os, value, \"",$node->{xsd_name},"\");\n"; | ||
| 713 | print $FH " }\n"; | ||
| 714 | print $FH "\n"; | ||
| 715 | print $FH " public static void write (",$self->{xml_pkg},"OutputStream \$os, ",$node->{java_Name}," value, java.lang.String tag)\n"; | ||
| 716 | print $FH " {\n"; | ||
| 717 | print $FH " \$os.write_open_tag (tag);\n"; | ||
| 718 | print $FH " ",$dis->{java_write_xml},"value.discriminator (), \"discriminator\");\n"; | ||
| 719 | if ($effective_dis->isa('EnumType')) { | ||
| 720 | print $FH " switch (value.discriminator ().value ())\n"; | ||
| 721 | } | ||
| 722 | else { | ||
| 723 | print $FH " switch (value.discriminator ())\n"; | ||
| 724 | } | ||
| 725 | print $FH " {\n"; | ||
| 726 | $idx = 0; | ||
| 727 | foreach my $case (@{$node->{list_expr}}) { | ||
| 728 | foreach (@{$case->{list_label}}) { # default or expression | ||
| 729 | if ($_->isa('Default')) { | ||
| 730 | print $FH " default:\n"; | ||
| 731 | } | ||
| 732 | else { | ||
| 733 | print $FH " case ",$_->{java_literal},":\n"; | ||
| 734 | } | ||
| 735 | } | ||
| 736 | my $elt = $case->{element}; | ||
| 737 | my $value = $self->_get_defn($elt->{value}); | ||
| 738 | $self->_member_helperXML_write($value, $node, \$idx); | ||
| 739 | print $FH " break;\n"; | ||
| 740 | } | ||
| 741 | if (exists $node->{need_default}) { | ||
| 742 | print $FH " default:\n"; | ||
| 743 | print $FH " throw new org.omg.CORBA.BAD_OPERATION ();\n"; | ||
| 744 | } | ||
| 745 | print $FH " }\n"; | ||
| 746 | print $FH " \$os.write_close_tag (tag);\n"; | ||
| 747 | print $FH " }\n"; | ||
| 748 | print $FH "\n"; | ||
| 749 | print $FH "}\n"; | ||
| 750 | close $FH; | ||
| 751 | } | ||
| 752 | |||
| 753 | # 3.11.2.4 Enumerations | ||
| 754 | # | ||
| 755 | |||
| 756 | sub _enum_helperXML { | ||
| 757 | my ($self, $node) = @_; | ||
| 758 | |||
| 759 | $self->open_stream($node, 'HelperXML.java'); | ||
| 760 | my $FH = $self->{out}; | ||
| 761 | print $FH "abstract public class ",$node->{java_name},"HelperXML\n"; | ||
| 762 | print $FH "{\n"; | ||
| 763 | print $FH "\n"; | ||
| 764 | print $FH " public static ",$node->{java_Name}," read (",$self->{xml_pkg},"InputStream \$is)\n"; | ||
| 765 | print $FH " {\n"; | ||
| 766 | print $FH " return read (\$is, \"",$node->{xsd_name},"\");\n"; | ||
| 767 | print $FH " }\n"; | ||
| 768 | print $FH "\n"; | ||
| 769 | print $FH " public static ",$node->{java_Name}," read (",$self->{xml_pkg},"InputStream \$is, java.lang.String tag)\n"; | ||
| 770 | print $FH " {\n"; | ||
| 771 | print $FH " \$is.read_open_tag (tag);\n"; | ||
| 772 | print $FH " java.lang.String str = \$is.read_pcdata ();\n"; | ||
| 773 | print $FH " \$is.read_close_tag (tag);\n"; | ||
| 774 | foreach (@{$node->{list_expr}}) { | ||
| 775 | print $FH " if (str.equals (\"",$_->{java_name},"\"))\n"; | ||
| 776 | print $FH " return ",$_->{java_Name},";\n"; | ||
| 777 | } | ||
| 778 | print $FH " throw new org.omg.CORBA.BAD_PARAM ();\n"; | ||
| 779 | print $FH " }\n"; | ||
| 780 | print $FH "\n"; | ||
| 781 | print $FH " public static void write (",$self->{xml_pkg},"OutputStream \$os, ",$node->{java_Name}," value)\n"; | ||
| 782 | print $FH " {\n"; | ||
| 783 | print $FH " write (\$os, value, \"",$node->{xsd_name},"\");\n"; | ||
| 784 | print $FH " }\n"; | ||
| 785 | print $FH "\n"; | ||
| 786 | print $FH " public static void write (",$self->{xml_pkg},"OutputStream \$os, ",$node->{java_Name}," value, java.lang.String tag)\n"; | ||
| 787 | print $FH " {\n"; | ||
| 788 | print $FH " \$os.write_open_tag (tag);\n"; | ||
| 789 | print $FH " \$os.write_pcdata (value.toString ());\n"; | ||
| 790 | print $FH " \$os.write_close_tag (tag);\n"; | ||
| 791 | print $FH " }\n"; | ||
| 792 | print $FH "\n"; | ||
| 793 | print $FH "}\n"; | ||
| 794 | close $FH; | ||
| 795 | } | ||
| 796 | |||
| 797 | # | ||
| 798 | # 3.12 Exception Declaration | ||
| 799 | # | ||
| 800 | |||
| 801 | sub _exception_helperXML { | ||
| 802 | my ($self, $node) = @_; | ||
| 803 | |||
| 804 | $self->open_stream($node, 'HelperXML.java'); | ||
| 805 | my $FH = $self->{out}; | ||
| 806 | print $FH "abstract public class ",$node->{java_name},"HelperXML\n"; | ||
| 807 | print $FH "{\n"; | ||
| 808 | print $FH "\n"; | ||
| 809 | print $FH " public static ",$node->{java_Name}," read (",$self->{xml_pkg},"InputStream \$is)\n"; | ||
| 810 | print $FH " {\n"; | ||
| 811 | print $FH " return read (\$is, \"",$node->{xsd_name},"\");\n"; | ||
| 812 | print $FH " }\n"; | ||
| 813 | print $FH "\n"; | ||
| 814 | print $FH " public static ",$node->{java_Name}," read (",$self->{xml_pkg},"InputStream \$is, java.lang.String tag)\n"; | ||
| 815 | print $FH " {\n"; | ||
| 816 | print $FH " ",$node->{java_Name}," value = new ",$node->{java_Name}," ();\n"; | ||
| 817 | print $FH " \$is.read_open_tag (tag);\n"; | ||
| 818 | my $idx = 0; | ||
| 819 | foreach (@{$node->{list_member}}) { | ||
| 820 | my $member = $self->_get_defn($_); | ||
| 821 | $self->_member_helperXML_read($member, $node, \$idx); | ||
| 822 | } | ||
| 823 | print $FH " \$is.read_close_tag (tag);\n"; | ||
| 824 | print $FH " return value;\n"; | ||
| 825 | print $FH " }\n"; | ||
| 826 | print $FH "\n"; | ||
| 827 | print $FH " public static void write (",$self->{xml_pkg},"OutputStream \$os, ",$node->{java_Name}," value)\n"; | ||
| 828 | print $FH " {\n"; | ||
| 829 | print $FH " write (\$os, value, \"",$node->{xsd_name},"\");\n"; | ||
| 830 | print $FH " }\n"; | ||
| 831 | print $FH "\n"; | ||
| 832 | print $FH " public static void write (",$self->{xml_pkg},"OutputStream \$os, ",$node->{java_Name}," value, java.lang.String tag)\n"; | ||
| 833 | print $FH " {\n"; | ||
| 834 | print $FH " \$os.write_open_tag (tag);\n"; | ||
| 835 | $idx = 0; | ||
| 836 | foreach (@{$node->{list_member}}) { | ||
| 837 | my $member = $self->_get_defn($_); | ||
| 838 | $self->_member_helperXML_write($member, $node, \$idx); | ||
| 839 | } | ||
| 840 | print $FH " \$os.write_close_tag (tag);\n"; | ||
| 841 | print $FH " }\n"; | ||
| 842 | print $FH "\n"; | ||
| 843 | print $FH "}\n"; | ||
| 844 | close $FH; | ||
| 845 | } | ||
| 846 | |||
| 847 | 1; | ||
| 848 |