On 13 Mar 2002, (Jason E. Stewart) wrote:

> "John Utz" <[EMAIL PROTECTED]> writes:
> 
> > here is the current place that i am stuck:
> > 
> > die "Non schema grammar, no output available\n"
> >     if( $saxParser->getValidator()->getGrammar()->getGrammarType() != 
> >     $XML::Xerces::Grammar::SchemaGrammarType );
> > 
> > my $grammar  = $saxParser->getValidator()->getGrammar();
> > print "GRAMMAR: $grammar\n";
> > 
> > my $elemEnum  = $grammar->getElemEnumerator(); #barfs here
> >
> > bash-2.04$ perl SEnumval.pl
> > /sfusers/utz/Compile/xerces-c-src1_6_0/samples/data/personal-schema.xml 
> > GRAMMAR: XML::Xerces::Grammar=HASH(0x84871e0)
> > Can't locate auto/XML/Xerces/Grammar/getElemEnum.al in @INC (@INC
> > contains: /usr/local/lib/perl5/5.6.1/i686-linux /usr/local/lib/perl5/5.6.1
> > /usr/local/lib/perl5/site_perl/5.6.1/i686-linux
> > /usr/local/lib/perl5/site_perl/5.6.1 /usr/local/lib/perl5/site_perl .) at
> > SEnumval.pl line 43
> > 
> > but here is the dang call in the Xeces.pm that i created this morning:
> > 
> > ############# Class : XML::Xerces::SchemaGrammar ##############
> > 
> > package XML::Xerces::SchemaGrammar;
> > @ISA = qw( XML::Xerces XML::Xerces::Grammar );
> > %OWNER = ();
> > <snip>
> > *getGrammarType = *XML::Xercesc::SchemaGrammar_getGrammarType;
> > <snip>
> > *getElemEnumerator = *XML::Xercesc::SchemaGrammar_getElemEnumerator;
> > 
> > getGrammarType works, getElemEnumerator doesnt, what else might i be doing
> > wrong?
> 
> Ok. You're getting bitten by the SWIG-casts-things-to-the-base-class
> problem. Look at the class of the object your code printed out:
> 
>   GRAMMAR: XML::Xerces::Grammar=HASH(0x84871e0)

glad i added the print!

> It's an XML::Xerces::Grammar instance *not* a
> XML::Xerces::SchemaGrammar instance. So it's looking in the
> XML::Xerces::Grammar namespace for a method called getElemEnumerator()
> and not finding one...
> 
> You can't blame swig, because the method it was wrapping has a
> signature that says it returns a Grammar instance, so it has to bless
> the object into some class, so it hard-codes in the base class name
> XML::Xerces::Grammar into the bless command.

and we want a SchemaGrammar, not a Grammar. i am so glad this made sense
to you.....

> The way we get around this for the other class hierarchies is to use a
> method called actual_cast() to re-bless the object into the
> appropriate subclass:


do i add my fixes to the actual_cast sub in postModule.pl? or do i make a
new function?

>   package XML::Xerces::DOM_Node;
> 
>   sub actual_cast {
>     return undef unless _isa( ref($_[0]), 'XML::Xerces::DOM_Node' );
>     return $_[0] if $_[0]->isNull;
>   
>     my $node_type = $_[0]->getNodeType;
>     return _reinterpret_cast('XML::Xerces::DOM_Text', $_[0])
>       if $node_type == $XML::Xerces::DOM_Node::TEXT_NODE;
>     return _reinterpret_cast('XML::Xerces::DOM_ProcessingInstruction', $_[0])
>       if $node_type == $XML::Xerces::DOM_Node::PROCESSING_INSTRUCTION_NODE;
>     return _reinterpret_cast('XML::Xerces::DOM_Document', $_[0])
>       if $node_type == $XML::Xerces::DOM_Node::DOCUMENT_NODE;
>     .
>     .
>     .
>   }
>   
>   sub _reinterpret_cast {
>     return undef unless ref $_[1];
>   
>     bless $_[1], $_[0];
>   
>     my($raw_ref, $tied) = ($_[1] =~ m[=(.*)\(]);
>   
>     if ($raw_ref eq 'SCALAR')   { $tied = tied ${$_[1]}; }
>     elsif ($raw_ref eq 'ARRAY') { $tied = tied @{$_[1]}; }
>     elsif ($raw_ref eq 'HASH')  { $tied = tied %{$_[1]}; }
>   
>     return $_[1] unless $tied;
>   
>     bless $tied, $_[0];
>     return $_[1];
>   };
> 
> You could do something similar for the Grammar classes. Just stick the
> extra code you want into postModule.pl, and it will insert it into
> Xerces.pm whenever SWIG re-makes the code.
> 
> jas.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to