Mercurial > pub > Impl
view Lib/IMPL/DOM/Navigator/Builder.pm @ 16:75d55f4ee263
Окончательная концепция описания схем и построения DOM документов
author | Sergey |
---|---|
date | Tue, 08 Sep 2009 17:29:07 +0400 |
parents | 16795016e70b |
children | 7f00786f8210 |
line wrap: on
line source
package IMPL::DOM::Navigator::Builder; use strict; use warnings; use base qw(IMPL::DOM::Navigator); use IMPL::Class::Property; use IMPL::Class::Property::Direct; BEGIN { protected _direct property _navigatorSchema => prop_all; public _direct property Document => prop_get | owner_set; } our %CTOR = ( 'IMPL::DOM::Navigator' => sub { $_[0] } # IMPL::DOM::Navigator($domDocument) ); sub CTOR { my ($this,$domDocument,$schema) = @_; $this->{$Document} = $domDocument; $this->{$_navigatorSchema} = new IMPL::DOM::Navigator($schema); } sub NavigateCreate { my ($this,$nodeName,%props) = @_; if ( my $nodeSchema = $this->{$_navigatorSchema}->Navigate(sub { $_[0]->nodeName eq $nodeName or $_[0]->isa('IMPL::DOM::Schema::AnyNode') }) ) { my $class = delete $props{type} || $nodeSchema->type || $nodeName; my $node = $this->{$Document}->Create(delete $props{nodeName} || $nodeName, $class, \%props); $this->Current()->appendNode($node); $this->Current($node); } else { die new IMPL::InvalidOperationException("Requested elemnt not found in the schema"); } } sub Back { my ($this) = @_; $this->{$_navigatorSchema}->Back; return $this->SUPER::Back(); } 1; __END__ =pod =head1 SYNOPSIS my $builder = new IMPL::DOM::Navigator::Builder(new MyApp::Document,$schema); my $reader = new IMPL::DOM::XMLReader(Navigator => $builder); $reader->ParseFile("document.xml"); my @errors = $schema->Validate($builder->Document); =head1 DESCRIPTION DOM . C<IMPL::DOM::XMLReader>. =head1 METHODS =over =item C<CTOR($domDocument,$schema)> , ( ) . =item C<< $obj->NavigateCreate($nodeName) >> . , . , , =over =item C<type> , =item C<type> , , . =item =back C<nodeName>. .. C<< <ComplexNode nodeName="Box" type="Container"> >> C<< Container->new(nodeName => 'Box') >>. =back =cut