blib/lib/blx/xsdsql/xsd_parser/node/schema.pm untested

filter: Statementstmt 0.0% 0 / 111 Branchbran 0.0% 0 / 32 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 19 Podpod 0.0% 0 / 14 totaltotal 0.0% 0 / 176 CC 17 SCAR 31.0
CC
17
Cov
0%
_set_std_namespace
72.0
trigger_at_start_node
20.0
find_namespace_from_abbr
12.0
CRAP 22.2
1 package blx::xsdsql::xsd_parser::node::schema;
2  
3 use strict; # use strict is for PBP
4 use Filter::Include;
5 include blx::xsdsql::include;
6 #line 7
7  
8 use blx::xsdsql::ut::ut qw(nvl);
9 use base(qw(blx::xsdsql::xsd_parser::schema blx::xsdsql::xsd_parser::node));
10  
11 use constant {
12 STD_NAMESPACE => 'http://www.w3.org/2001/XMLSchema'
13 };
14  
15  
16 our %_ATTRS_R:Constant(
17 %blx::xsdsql::xsd_parser::schema::_ATTRS_R
18 ,ID_SQL_TYPE => sub {
19 return $_[0]->get_attrs_value(qw(EXTRA_TABLES))->get_predefined_type(qw(PK_ID_TYPE));
20 }
21 ,(
22 map { my $a=$_;($a,sub { croak $a.": this attribute is not readable"}) }
23 qw(
24 USER_NAMESPACE_ABBR
25 )
26 )
27 );
28  
29 our %_ATTRS_W:Constant(
30 %blx::xsdsql::xsd_parser::schema::_ATTRS_W
31 ,(
32 map { my $a=$_;($a,sub { croak $a.": this attribute is not writeable"}) }
33 qw(
34 ID_SQL_TYPE
35 PATH
36 STD_NAMESPACE_ABBR
37 USER_NAMESPACE_ABBR
38 DEFAULT_NAMESPACE
39 URI
40 )
41 )
42 );
43  
44 sub _get_attrs_w { return \%_ATTRS_W; }
45 sub _get_attrs_r { return \%_ATTRS_R; }
46  
47 sub _set_std_namespace {
48 my ($self,%params)=@_;
49 for my $k(keys %$self) {
50 if (nvl($self->{$k}) eq STD_NAMESPACE) {
51 if ($k=~/^xmlns:(\w+)$/) {
52 $self->{STD_NAMESPACE_ABBR}=$1;
53 delete $self->{$k};
54 }
55 else {
56 croak "$k: wrong abbr for standard namespace\n";
57 }
58 }
59 elsif ($k=~/^xmlns:(\w+)$/) {
60 $self->{USER_NAMESPACE_ABBR}->{$1}=delete $self->{$k};
61 }
62 elsif ($k eq 'xmlns') {
63 $self->{DEFAULT_NAMESPACE}=delete $self->{$k};
64 }
65 elsif ($k eq 'targetNamespace') {
66 $self->{URI}=delete $self->{$k};
67 }
68 }
69 affirm { defined $self->{STD_NAMESPACE_ABBR} } "not std namespace in schema";
70 if (defined (my $uri=$params{FORCE_NAMESPACE})) {
71 my $orig_uri=nvl($self->get_attrs_value(qw(URI)));
72 if (nvl($uri) ne $orig_uri) {
73 affirm { length($orig_uri) == 0 } "$orig_uri: for include the target namespace of the included schema must be on the global namespace or equal to the target namespace of the parent schema";
74 $self->{URI}=$self->{DEFAULT_NAMESPACE}=$uri;
75 }
76 }
77 return $self;
78 }
79  
80  
81 sub set_table_names {
82 my ($self,$table,%params)=@_;
83 my %p=%$self;
84 $table->set_sql_name(%p); #force the resolve of sql name
85 $table->set_constraint_name('pk',%p); #force the resolve of pk constraint
86 $table->set_view_sql_name(%p); #force the resolve of view sql name
87 $table->set_attrs_value(URI => $self->get_attrs_value(qw(URI))); #set the URI attribute
88 $table->add_columns(
89 $self->get_attrs_value(qw(EXTRA_TABLES))->factory_column(qw(SYS_ATTRIBUTES))
90 ) unless $params{NOT_ADD_SYS_COLUMNS};
91  
92 return $self;
93 }
94  
95 sub _set_root_table_before {
96 my ($self,%params)=@_;
97  
98 my $root=$self->get_attrs_value(qw(TABLE_CLASS))->new (
99 PATH => '/'
100 ,CHOICE => 1
101 ,DEBUG => $self->get_attrs_value(qw(DEBUG))
102 );
103  
104 $self->set_attrs_value(TABLENAME_LIST => $params{TABLENAME_LIST},CONSTRAINT_LIST => $params{CONSTRAINT_LIST});
105 $self->set_table_names($root,%params);
106 $root->add_columns($self->get_attrs_value(qw(EXTRA_TABLES))->factory_column(qw(ID)));
107 $self->set_attrs_value(TABLE => $root);
108 return $self;
109 }
110  
111  
112 sub _set_root_table_after {
113 my ($self,%params)=@_;
114 return $self;
115 my $t=$self->get_root_table;
116 $t->add_columns(
117 $self->get_attrs_value(qw(EXTRA_TABLES))->factory_column(qw(SYS_ATTRIBUTES))
118 );
119 return $self;
120 }
121  
122  
123  
124 sub _adj_redefine_types {
125 my ($self,%params)=@_;
126 my $types=$self->get_attrs_value(qw(TYPES));
127 for my $t(@$types) {
128 if (defined (my $child_schema=$t->get_attrs_value(qw(REDEFINE_FROM_SCHEMA)))) {
129 $t->adj_redefine_from_schema(%params);
130 }
131 }
132 return $self;
133 }
134  
135  
136 sub new {
137 my ($class,%params)=@_;
138 my $self=$class->blx::xsdsql::xsd_parser::schema::new(%params);
139 $self->{PATH}='/';
140 delete $params{NO_FLAT_GROUPS}; # set from the base class
141 return $self->set_attrs_value(%params);
142 }
143  
144 sub _new {
145 croak "illegal call\n";
146 }
147  
148  
149 sub trigger_at_start_node {
150 my ($self,%params)=@_;
151 my $encoding=$self->get_attrs_value(qw(STACK))->[0]->[1];
152 $encoding='UTF-8' unless defined $encoding;
153 $encoding='UTF-8' if $encoding=~/utf[\-]{0,1}8/i;
154 $self->{ENCODING}=$encoding;
155 $self->set_attrs_value(
156 ELEMENT_FORM_DEFAULT => delete $self->{elementFormDefault}
157 ,ATTRIBUTE_FORM_DEFAULT => delete $self->{attributeFormDefault}
158 );
159 $self->{SCHEMA_CODE}='ROOT_SCHEMA' unless defined $self->{SCHEMA_CODE};
160 $self->_set_std_namespace(%params);
161 $self->_set_root_table_before(%params);
162 return $self;
163 }
164  
165 sub trigger_at_end_node {
166 my ($self,%params)=@_;
167 $self->_set_root_table_after(%params);
168 $self->_adj_redefine_types;
169 $self->set_types;
170 return $self;
171 }
172  
173 sub get_std_namespace_attr {
174 my ($self,%params)=@_;
175 return $self->{STD_NAMESPACE_ABBR};
176 }
177  
178 sub find_namespace_from_abbr {
179 my ($self,$ns,%params)=@_;
180 return nvl($self->get_attrs_value(qw(URI))) unless length($ns);
181 if (defined (my $uri=$self->{USER_NAMESPACE_ABBR}->{$ns})) {
182 return $uri;
183 }
184 $self->_debug(__LINE__,"$ns: not find uri from this namespace abbr in schema ");
185 undef;
186 }
187  
188 sub find_schemas_from_namespace_abbr {
189 my ($self,$ns,%params)=@_;
190 if (defined (my $namespace=$self->find_namespace_from_abbr($ns))) {
191 return $self->find_schemas_from_namespace($namespace,%params);
192 }
193 $self->_debug(__LINE__,"$ns: not find URI from this namespace abbr");
194 return wantarray ? () : [];
195 }
196  
197 1;
198  
199 __END__