comparison Lib/IMPL/DOM/Schema.pm @ 381:ced5937ff21a

Custom getters/setters support method names in theirs definitions Initial support for localizable labels in DOM schemas
author cin
date Wed, 22 Jan 2014 16:56:10 +0400
parents 4ddb27ff4a0b
children 99ac2e19c0cc
comparison
equal deleted inserted replaced
380:1eca08048ba9 381:ced5937ff21a
1 package IMPL::DOM::Schema; 1 package IMPL::DOM::Schema;
2 use strict; 2 use strict;
3 use warnings; 3 use warnings;
4 4
5 use IMPL::require { 5 use File::Spec;
6 ComplexNode => 'IMPL::DOM::Schema::ComplexNode', 6 use IMPL::Const qw(:prop);
7 ComplexType => 'IMPL::DOM::Schema::ComplexType', 7 use IMPL::declare {
8 SimpleNode => 'IMPL::DOM::Schema::SimpleNode', 8 require => {
9 SimpleType => 'IMPL::DOM::Schema::SimpleType', 9 ComplexNode => 'IMPL::DOM::Schema::ComplexNode',
10 Node => 'IMPL::DOM::Schema::Node', 10 ComplexType => 'IMPL::DOM::Schema::ComplexType',
11 AnyNode => 'IMPL::DOM::Schema::AnyNode', 11 SimpleNode => 'IMPL::DOM::Schema::SimpleNode',
12 NodeList => 'IMPL::DOM::Schema::NodeList', 12 SimpleType => 'IMPL::DOM::Schema::SimpleType',
13 NodeSet => 'IMPL::DOM::Schema::NodeSet', 13 Node => 'IMPL::DOM::Schema::Node',
14 Property => 'IMPL::DOM::Schema::Property', 14 AnyNode => 'IMPL::DOM::Schema::AnyNode',
15 SwitchNode => 'IMPL::DOM::Schema::SwitchNode', 15 NodeList => 'IMPL::DOM::Schema::NodeList',
16 Validator => 'IMPL::DOM::Schema::Validator', 16 NodeSet => 'IMPL::DOM::Schema::NodeSet',
17 Builder => 'IMPL::DOM::Navigator::Builder', 17 Property => 'IMPL::DOM::Schema::Property',
18 XMLReader => 'IMPL::DOM::XMLReader', # XMLReader references Schema 18 SwitchNode => 'IMPL::DOM::Schema::SwitchNode',
19 InflateFactory => 'IMPL::DOM::Schema::InflateFactory', 19 Validator => 'IMPL::DOM::Schema::Validator',
20 Loader => 'IMPL::Code::Loader' 20 Builder => 'IMPL::DOM::Navigator::Builder',
21 XMLReader => 'IMPL::DOM::XMLReader', # XMLReader references Schema
22 InflateFactory => 'IMPL::DOM::Schema::InflateFactory',
23 Loader => 'IMPL::Code::Loader',
24 StringMap => 'IMPL::Resources::StringLocaleMap'
25 },
26 base => [
27 'IMPL::DOM::Document' => sub {
28 nodeName => 'schema'
29 }
30 ],
31 props => [
32 _TypesMap => PROP_RW | PROP_DIRECT,
33 baseDir => PROP_RW | PROP_DIRECT,
34 schemaName => PROP_RW | PROP_DIRECT,
35 BaseSchemas => PROP_RO | PROP_DIRECT,
36 stringMap => {
37 get => '_getStringMap',
38 direct => 1
39 }
40 ]
21 }; 41 };
22
23 use parent qw(IMPL::DOM::Document);
24 use IMPL::Class::Property;
25 use File::Spec;
26
27 our %CTOR = (
28 'IMPL::DOM::Document' => sub { nodeName => 'schema' }
29 );
30
31 BEGIN {
32 private _direct property _TypesMap => prop_all;
33 public _direct property baseDir => prop_all;
34 public _direct property BaseSchemas => prop_get | owner_set;
35 }
36 42
37 my $validatorLoader = Loader->new(prefix => Validator, verifyNames => 1); 43 my $validatorLoader = Loader->new(prefix => Validator, verifyNames => 1);
38 44
39 #TODO rename and remove 45 #TODO rename and remove
40 sub resolveType { 46 sub resolveType {
69 } 75 }
70 76
71 return $this->SUPER::Create($nodeName,$class,$refArgs); 77 return $this->SUPER::Create($nodeName,$class,$refArgs);
72 } 78 }
73 79
80 sub _getStringMap {
81 my ($this) = @_;
82
83
84
85 File::Spec->catdir($this->baseDir,'locale');
86 }
87
74 sub Process { 88 sub Process {
75 my ($this) = @_; 89 my ($this) = @_;
76 90
77 # process instructions 91 # process instructions
78 $this->Include($_) foreach map $_->nodeProperty('source'), $this->selectNodes('Include'); 92 $this->Include($_) foreach map $_->nodeProperty('source'), $this->selectNodes('Include');
106 120
107 $reader->ParseFile($file); 121 $reader->ParseFile($file);
108 122
109 my $schema = $reader->Navigator->Document; 123 my $schema = $reader->Navigator->Document;
110 124
111 my ($vol,$dir) = File::Spec->splitpath($file); 125 my ($vol,$dir,$name) = File::Spec->splitpath($file);
126
127 $name =~ s/\.xml$//;
112 128
113 $schema->baseDir($dir); 129 $schema->baseDir($dir);
130 $schema->schemaName($name);
114 131
115 my @errors = $class->MetaSchema->Validate($schema); 132 my @errors = $class->MetaSchema->Validate($schema);
116 133
117 die new IMPL::Exception("Schema is invalid",$file,map( $_->message, @errors ) ) if @errors; 134 die new IMPL::Exception("Schema is invalid",$file,map( $_->message, @errors ) ) if @errors;
118 135