| 1 | package blx::xsdsql::xsd_parser::node::attribute; | ||
| 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::xsd_parser::type; | ||
| 8 | use base qw(blx::xsdsql::xsd_parser::node); | ||
| 9 | |||
| 10 | sub trigger_at_start_node { | ||
| 11 | my ($self,%params)=@_; | ||
| 12 | my $schema=$self->get_attrs_value(qw(STACK))->[1]; | ||
| 13 | |||
| 14 | if (defined (my $name=$self->get_attrs_value(qw(name)))) { | ||
| 15 | my $column = $self->get_attrs_value(qw(COLUMN_CLASS))->new( | ||
| 16 | NAME => $name | ||
| 17 | ,ATTRIBUTE => 1 | ||
| 18 | ,DEBUG => $self->get_attrs_value(qw(DEBUG)) | ||
| 19 | ,ELEMENT_FORM => $self->get_attrs_value(qw(form)) | ||
| 20 | ); | ||
| 21 | |||
| 22 | if (defined (my $type=$self->get_attrs_value(qw(type)))) { | ||
| 23 | my $ty_obj=blx::xsdsql::xsd_parser::type::factory( | ||
| 24 | $type | ||
| 25 | ,SCHEMA => $schema | ||
| 26 | ,DEBUG => $self->get_attrs_value(qw(DEBUG)) | ||
| 27 | ); | ||
| 28 | $column->set_attrs_value(TYPE => $ty_obj); | ||
| 29 | } | ||
| 30 | |||
| 31 | my $parent_table=$self->_get_parent_table; | ||
| 32 | if ($parent_table->is_root_table) { | ||
| 33 | $schema->add_attrs($column); | ||
| 34 | } | ||
| 35 | elsif ($parent_table->get_attrs_value(qw(ATTRIBUTE_GROUP))) { | ||
| 36 | $parent_table->add_columns($column); | ||
| 37 | } | ||
| 38 | else { | ||
| 39 | $parent_table->add_columns($column); | ||
| 40 | } | ||
| 41 | $self->set_attrs_value(TABLE => $parent_table); | ||
| 42 | } | ||
| 43 | elsif (defined (my $ref=$self->get_attrs_value(qw(ref)))) { | ||
| 44 | my ($ns,$base)=$ref=~/^([^:]+):(.*)$/; | ||
| 45 | if (defined $ns) { #search the namespace naame | ||
| 46 | $ref=$base; | ||
| 47 | my $namespace=$schema->find_namespace_from_abbr($ns); | ||
| 48 | affirm { defined $namespace } "$ns: not find URI from this namespace abbr"; | ||
| 49 | $ns=$namespace eq nvl($schema->get_attrs_value(qw(URI))) ? undef : $namespace; | ||
| 50 | } | ||
| 51 | |||
| 52 | my $column = $self->get_attrs_value(qw(COLUMN_CLASS))->new( | ||
| 53 | NAME => $ref | ||
| 54 | ,ATTRIBUTE => 1 | ||
| 55 | ,REF => 1 | ||
| 56 | ,URI => $ns | ||
| 57 | ,DEBUG => $self->get_attrs_value(qw(DEBUG)) | ||
| 58 | ); | ||
| 59 | my $parent_table=$self->_get_parent_table; | ||
| 60 | if ($parent_table->is_root_table) { | ||
| 61 | $schema->add_attrs($column); | ||
| 62 | } | ||
| 63 | elsif ($parent_table->get_attrs_value(qw(ATTRIBUTE_GROUP))) { | ||
| 64 | $parent_table->add_columns($column); | ||
| 65 | } | ||
| 66 | else { | ||
| 67 | $parent_table->add_columns($column); | ||
| 68 | } | ||
| 69 | $self->set_attrs_value(TABLE => $parent_table); | ||
| 70 | } else { | ||
| 71 | confess "internal error - attribute without name or ref is not implemented\n"; | ||
| 72 | } | ||
| 73 | return $self; | ||
| 74 | } | ||
| 75 | |||
| 76 | sub trigger_at_end_node { | ||
| 77 | my ($self,%params)=@_; | ||
| 78 | unless (defined $self->get_attrs_value(qw(type))) { | ||
| 79 | if (defined (my $childs=$self->get_attrs_value(qw(CHILD)))) { | ||
| 80 | my $child=$childs->[0]; | ||
| 81 | # $self->_debug(__LINE__,$child); | ||
| 82 | my $out={}; | ||
| 83 | my $table=$self->get_attrs_value(qw(TABLE)); | ||
| 84 | my ($schema,$col,$debug)=($self->get_attrs_value(qw(STACK))->[1],($table->get_columns)[-1],$self->get_attrs_value(qw(DEBUG))); | ||
| 85 | $self->_resolve_simple_type($child,undef,$out,%params,SCHEMA => $schema,DEBUG => $debug); | ||
| 86 | my $ty_obj=ref($out->{base}) eq '' | ||
| 87 | ? blx::xsdsql::xsd_parser::type::simple->_new(NAME => $out,SCHEMA => $schema,DEBUG => $debug) | ||
| 88 | : $out->{base}; | ||
| 89 | $col->set_attrs_value(TYPE => $ty_obj); | ||
| 90 | } | ||
| 91 | elsif (defined (my $ref=$self->get_attrs_value(qw(ref)))) { | ||
| 92 | #empty | ||
| 93 | } | ||
| 94 | else { | ||
| 95 | croak "attribute without type and childs\n"; | ||
| 96 | } | ||
| 97 | } | ||
| 98 | return $self; | ||
| 99 | } | ||
| 100 | |||
| 101 | |||
| 102 | |||
| 103 | 1; | ||
| 104 | |||
| 105 | __END__ |