« blib/lib/blx/xsdsql/schema_repository/sql/generic/column.pm
↑ Summary
blib/lib/blx/xsdsql/schema_repository/catalog.pm »
| 1 | package blx::xsdsql::xsd_parser::node::complexType; | ||
| 2 | use strict; # use strict is for PBP | ||
| 3 | use Filter::Include; | ||
| 4 | include blx::xsdsql::include; | ||
| 5 | #line 6 | ||
| 6 | use blx::xsdsql::ut::ut qw(nvl); | ||
| 7 | use blx::xsdsql::schema_repository::sql::generic::table qw(:overload); | ||
| 8 | use blx::xsdsql::xsd_parser::type; | ||
| 9 | use blx::xsdsql::xsd_parser::type::complex; | ||
| 10 | use blx::xsdsql::xsd_parser::type::simple_content; | ||
| 11 | use blx::xsdsql::xsd_parser::type::simple; | ||
| 12 | use base qw(blx::xsdsql::xsd_parser::node); | ||
| 13 | |||
| 14 | |||
| 15 | sub adj_redefine_from_schema { | ||
| 16 | my ($self,%params)=@_; | ||
| 17 | my $child_schema=delete $self->{REDEFINE_FROM_SCHEMA}; | ||
| 18 | affirm { defined $child_schema } "redefine_from_schema not set"; | ||
| 19 | my $types=$child_schema->get_attrs_value(qw(TYPE_NODE_NAMES)); | ||
| 20 | my $name=nvl($self->get_attrs_value(qw(name))); | ||
| 21 | my $childs=$self->get_attrs_value(qw(CHILD)); | ||
| 22 | my $base=$childs->[0]->get_attrs_value(qw(CHILD))->[0]->get_attrs_value(qw(base)); | ||
| 23 | affirm { defined $name } "$name: not base defined for this simple type"; | ||
| 24 | my $t=$types->{$base}; | ||
| 25 | affirm { defined $t } "$base: no such type with this name"; | ||
| 26 | my $self_restrictions=$childs->[0]->get_attrs_value(qw(CHILD)); | ||
| 27 | my $old_restrictions=$t->get_attrs_value(qw(CHILD))->[0]->get_attrs_value(qw(CHILD)); | ||
| 28 | my %self_restrictions=map { (ref($_),$_); } @$self_restrictions; | ||
| 29 | my @new_restrictions=map { | ||
| 30 | my $r=$self_restrictions{ref($_)}; | ||
| 31 | defined $r ? $r : $_; | ||
| 32 | } @$old_restrictions; | ||
| 33 | $childs->[0]->set_attrs_value(CHILD => \@new_restrictions,base => $t->get_attrs_value(qw(CHILD))->[0]->get_attrs_value(qw(base))); | ||
| 34 | } | ||
| 35 | |||
| 36 | sub trigger_at_start_node { | ||
| 37 | my ($self,%params)=@_; | ||
| 38 | my $stackframe=$self->get_attrs_value(qw(STACK)); | ||
| 39 | my ($schema,$parent)=map { $stackframe->[$_] } (1,-1); | ||
| 40 | $self->set_attrs_value(REDEFINE_FROM_SCHEMA => $schema->get_attrs_value(qw(REDEFINE_FROM_SCHEMA))); | ||
| 41 | $self->set_attrs_value(MIXED => $self->_resolve_boolean($self->get_attrs_value(qw(mixed)))); | ||
| 42 | if (defined (my $name=$self->get_attrs_value(qw(name)))) { | ||
| 43 | my $table = $self->get_attrs_value(qw(TABLE_CLASS))->new ( | ||
| 44 | PATH => $self->_construct_path($name,PARENT => $parent) | ||
| 45 | ,XSD_TYPE => XSD_TYPE_COMPLEX | ||
| 46 | ,XSD_SEQ => 1 | ||
| 47 | ,DEBUG => $self->get_attrs_value(qw(DEBUG)) | ||
| 48 | ,MIXED => $self->get_attrs_value(qw(MIXED)) | ||
| 49 | ); | ||
| 50 | $schema->set_table_names($table); | ||
| 51 | |||
| 52 | $table->add_columns( | ||
| 53 | $schema->get_attrs_value(qw(EXTRA_TABLES))->factory_column(qw(ID)) | ||
| 54 | ,$schema->get_attrs_value(qw(EXTRA_TABLES))->factory_column(qw(SEQ)) | ||
| 55 | ); | ||
| 56 | $schema->add_types($self); | ||
| 57 | $self->set_attrs_value(TABLE => $table); | ||
| 58 | } | ||
| 59 | else { | ||
| 60 | my $parent_table=$parent->get_attrs_value(qw(TABLE)); | ||
| 61 | $parent_table->set_attrs_value(MIXED => $self->get_attrs_value(qw(MIXED))); | ||
| 62 | $self->set_attrs_value(TABLE => $parent_table); | ||
| 63 | } | ||
| 64 | return $self; | ||
| 65 | } | ||
| 66 | |||
| 67 | sub factory_type { | ||
| 68 | my ($self,$t,$types,%params)=@_; | ||
| 69 | my ($schema,$debug)=($t->get_attrs_value(qw(STACK))->[1],$self->get_attrs_value(qw(DEBUG))); | ||
| 70 | my $table=$t->get_attrs_value(qw(TABLE)); | ||
| 71 | if ($table->get_attrs_value(qw(XSD_TYPE) eq XSD_TYPE_SIMPLE_CONTENT)) { | ||
| 72 | return blx::xsdsql::xsd_parser::type::simple_content->_new(NAME => $t,SCHEMA => $schema,DEBUG => $debug); | ||
| 73 | } | ||
| 74 | my $out={}; | ||
| 75 | $self->_resolve_simple_type($t,$types,$out,%params,SCHEMA => $schema); | ||
| 76 | if (defined (my $base=$out->{base})) { #is simpleContent | ||
| 77 | my $ty_obj=blx::xsdsql::xsd_parser::type::simple->new(NAME => $out,DEBUG => $debug); | ||
| 78 | my $value_col=$schema->get_attrs_value(qw(EXTRA_TABLES))->factory_column(qw(VALUE_COL))->set_attrs_value(TYPE => $ty_obj); | ||
| 79 | $table->add_columns($value_col); | ||
| 80 | $table->set_attrs_value(XSD_TYPE => XSD_TYPE_SIMPLE_CONTENT,INTERNAL_REFERENCE => 1); | ||
| 81 | return blx::xsdsql::xsd_parser::type::simple_content->new(NAME => $t,SCHEMA => $schema,DEBUG => $debug); | ||
| 82 | } | ||
| 83 | return blx::xsdsql::xsd_parser::type::complex->new(NAME => $t,SCHEMA => $schema,DEBUG => $debug); | ||
| 84 | } | ||
| 85 | |||
| 86 | |||
| 87 | sub trigger_at_end_node { | ||
| 88 | my ($self,%params)=@_; | ||
| 89 | if ($self->get_attrs_value(qw(MIXED))) { | ||
| 90 | my $table=$self->get_attrs_value(qw(TABLE)); | ||
| 91 | affirm { defined $table } "TABLE attributed not set"; | ||
| 92 | my $isparent_choice=$table->get_attrs_value(qw(CHOICE)); | ||
| 93 | my $column = $self->get_attrs_value(qw(COLUMN_CLASS))->new( | ||
| 94 | MINOCCURS => 1 | ||
| 95 | ,MAXOCCURS => 1 | ||
| 96 | ,CHOICE => $isparent_choice | ||
| 97 | ,DEBUG => $self->get_attrs_value(qw(DEBUG)) | ||
| 98 | ,MIXED => 1 | ||
| 99 | ,TYPE => blx::xsdsql::xsd_parser::type::simple->new(NAME => 'string') | ||
| 100 | ); | ||
| 101 | if (defined $table->get_xsd_seq) { #the table is a sequence or choice | ||
| 102 | $column->set_attrs_value(XSD_SEQ => $table->get_xsd_seq); | ||
| 103 | $table->inc_xsd_seq unless $isparent_choice; #the columns of a choice have the same xsd_seq | ||
| 104 | } | ||
| 105 | $table->add_columns($column); | ||
| 106 | } | ||
| 107 | return $self; | ||
| 108 | } | ||
| 109 | |||
| 110 | 1; | ||
| 111 | |||
| 112 | __END__ |