comparison Lib/IMPL/DOM/Schema.pm @ 383:2f16f13b000c

DOM localization
author cin
date Thu, 23 Jan 2014 17:26:34 +0400
parents 99ac2e19c0cc
children 5aff94ba842f
comparison
equal deleted inserted replaced
382:99ac2e19c0cc 383:2f16f13b000c
27 'IMPL::DOM::Document' => sub { 27 'IMPL::DOM::Document' => sub {
28 nodeName => 'schema' 28 nodeName => 'schema'
29 } 29 }
30 ], 30 ],
31 props => [ 31 props => [
32 _TypesMap => PROP_RW | PROP_DIRECT, 32 _typesMap => PROP_RW | PROP_DIRECT,
33 baseDir => PROP_RW | PROP_DIRECT, 33 baseDir => PROP_RW | PROP_DIRECT,
34 schemaName => PROP_RW | PROP_DIRECT, 34 schemaName => PROP_RW | PROP_DIRECT,
35 BaseSchemas => PROP_RO | PROP_DIRECT, 35 baseSchemas => PROP_RO | PROP_LIST | PROP_DIRECT,
36 stringMap => { 36 stringMap => {
37 get => '_getStringMap', 37 get => '_getStringMap',
38 direct => 1 38 direct => 1
39 } 39 }
40 ] 40 ]
42 42
43 my $validatorLoader = Loader->new(prefix => Validator, verifyNames => 1); 43 my $validatorLoader = Loader->new(prefix => Validator, verifyNames => 1);
44 44
45 #TODO rename and remove 45 #TODO rename and remove
46 sub resolveType { 46 sub resolveType {
47 $_[0]->{$_TypesMap}->{$_[1]} or die IMPL::KeyNotFoundException->new($_[1]); 47 goto &ResolveType;
48 } 48 }
49 49
50 sub CTOR { 50 sub CTOR {
51 my ($this,%args) = @_; 51 my ($this,%args) = @_;
52 52
53 $this->{$baseDir} = ($args{baseDir} || '.'); 53 $this->{$baseDir} = ($args{baseDir} || '.');
54 } 54 }
55 55
56 # compat 56 # compat
57 sub ResolveType { 57 sub ResolveType {
58 goto &resolveType 58 my ($this,$typeName) = @_;
59
60 my $type = $this->{$_typesMap}{$typeName};
61 return $type if $type;
62
63 foreach my $base ($this->baseSchemas) {
64 last if $type = $base->resolveType($typeName);
65 }
66
67 die IMPL::KeyNotFoundException->new($typeName)
68 unless $type;
69 return $this->{$_typesMap}{$typeName} = $type;
59 } 70 }
60 71
61 sub Create { 72 sub Create {
62 my ($this,$nodeName,$class,$refArgs) = @_; 73 my ($this,$nodeName,$class,$refArgs) = @_;
63 74
79 90
80 sub _getStringMap { 91 sub _getStringMap {
81 my ($this) = @_; 92 my ($this) = @_;
82 93
83 return $this->{$stringMap} 94 return $this->{$stringMap}
84 if return $this->{$stringMap}; 95 if $this->{$stringMap};
85 96
86 my $map = StringMap->new(); 97 my $map = StringMap->new();
87 if ($this->baseDir and $this->schemaName) { 98 if ($this->baseDir and $this->schemaName) {
88 99
89 $map->paths( File::Spec->catdir($this->baseDir,'locale') ); 100 $map->paths( File::Spec->catdir($this->baseDir,'locale') );
90 $map->name(schemaName); 101 $map->name( $this->schemaName );
91 } 102 }
92 103
93 return $this->{$stringMap} = $map; 104 return $this->{$stringMap} = $map;
94 } 105 }
95 106
98 109
99 # process instructions 110 # process instructions
100 $this->Include($_) foreach map $_->nodeProperty('source'), $this->selectNodes('Include'); 111 $this->Include($_) foreach map $_->nodeProperty('source'), $this->selectNodes('Include');
101 112
102 # build types map 113 # build types map
103 $this->{$_TypesMap} = { map { $_->type, $_ } $this->selectNodes(sub { $_[0]->nodeName eq 'ComplexType' || $_[0]->nodeName eq 'SimpleType' } ) }; 114 $this->{$_typesMap} = { map { $_->type, $_ } $this->selectNodes(sub { $_[0]->nodeName eq 'ComplexType' || $_[0]->nodeName eq 'SimpleType' } ) };
104 } 115 }
105 116
106 sub Include { 117 sub Include {
107 my ($this,$file) = @_; 118 my ($this,$file) = @_;
108 119
109 my $schema = $this->LoadSchema(File::Spec->catfile($this->baseDir, $file)); 120 my $schema = $this->LoadSchema(File::Spec->catfile($this->baseDir, $file));
110 121
111 $this->appendRange( $schema->childNodes ); 122 $this->baseSchemas->Append( $schema );
112 } 123 }
113 124
114 sub LoadSchema { 125 sub LoadSchema {
115 my ($this,$file) = @_; 126 my ($this,$file) = @_;
116 127