The reason the line number sometimes appears off is because it uses the 
"current" line when the object is created. Usually the object is created 
by unmarshalling a start tag, and because the parser scans the whole 
start tag (attributes and all) at once you'll get the line number for 
the end of the start tag rather than the beginning of the start tag. For 
a simple start tag that's not a problem (though it does mean the column 
number looks off), but if the start tag spans multiple lines the line 
number will also appear off.

I could cache the line and column values, so that I'd have the line and 
column matching the actual start of the start tag. The only reason I 
haven't done that is because it'd be a minor (probably very minor) 
performance hit to do this, and I hate doing anything to slow down the 
runtime.

Hmmm. JiBX uses this itself for the binding definitions (and schema 
definitions and customization files, for 1.2), and it is probably 
confusing to people that the reported line number doesn't always match 
the actual line number. Perhaps I should go to caching for 1.2. What do 
the other people using track-source think?

  - Dennis

Dennis M. Sosnoski
SOA and Web Services in Java
Training and Consulting
http://www.sosnoski.com - http://www.sosnoski.co.nz
Seattle, WA +1-425-939-0576 - Wellington, NZ +64-4-298-6117



Laurent PETIT wrote:
> Wow, it's great !
>
> I have it worked in minutes ! Thanks !
>
> But, one more question please : how does the line count "work" ? It 
> seems to me that while the real line number is 7 (counting from 1), 
> with ITrackSource I get is 8.
>
> Is there a logic explanation to this ?
>
> Thanks in advance,
>
> -- 
> Laurent
>
> 2008/9/23 Joshua Davies <[EMAIL PROTECTED] 
> <mailto:[EMAIL PROTECTED]>>
>
>     Yeah, just add "track-source" to your binding declarations:
>
>     <binding direction="input" track-source="true">
>     ...
>
>     Then (after parsing) you can cast any of your bound objects to
>     ITrackSource and retrieve document source information:
>
>     ITrackSource tracker = ( ITrackSource ) boundObject;
>     System.out.println( "This element came from line " +
>            tracker.jibx_getLineNumber() + ", column " +
>            tracker.jibx_getColumnNumber() );
>
>     On Tue, 2008-09-23 at 15:44 +0200, Laurent PETIT wrote:
>     > Hello,
>     >
>     > Another thing that is currently done on my project that uses JAXB is
>     > that at marshalling time, a custom stax listener has been
>     created that
>     > adds "on-the-fly" information to the generated XML : the start line
>     > and column number of some elements.
>     >
>     > (FYI, it is then used as debugging hits).
>     >
>     > Will this be possible with jibx ?
>     >
>     > I yet haven't read all the documentation concerning possible
>     > customization, but if this seems not possible and may be a blocking
>     > argument preventing me from using jibx, your answer could help
>     me save
>     > time  ! :-)
>     >
>     > Thanks in advance,
>     >
>     > Regards,
>     >
>     > --
>     > Laurent
>     >
>     >
>     -------------------------------------------------------------------------
>     > This SF.Net email is sponsored by the Moblin Your Move
>     Developer's challenge
>     > Build the coolest Linux based applications with Moblin SDK & win
>     great prizes
>     > Grand prize is a trip for two to an Open Source event anywhere
>     in the world
>     > http://moblin-contest.org/redirect.php?banner_id=100&url=/
>     <http://moblin-contest.org/redirect.php?banner_id=100&url=/>
>     > _______________________________________________ jibx-users
>     mailing list jibx-users@lists.sourceforge.net
>     <mailto:jibx-users@lists.sourceforge.net>
>     https://lists.sourceforge.net/lists/listinfo/jibx-users
>
>     -------------------------------------------------------------------------
>     This SF.Net email is sponsored by the Moblin Your Move Developer's
>     challenge
>     Build the coolest Linux based applications with Moblin SDK & win
>     great prizes
>     Grand prize is a trip for two to an Open Source event anywhere in
>     the world
>     http://moblin-contest.org/redirect.php?banner_id=100&url=/
>     <http://moblin-contest.org/redirect.php?banner_id=100&url=/>
>     _______________________________________________
>     jibx-users mailing list
>     jibx-users@lists.sourceforge.net
>     <mailto:jibx-users@lists.sourceforge.net>
>     https://lists.sourceforge.net/lists/listinfo/jibx-users
>
>
> ------------------------------------------------------------------------
>
> -------------------------------------------------------------------------
> This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
> Build the coolest Linux based applications with Moblin SDK & win great prizes
> Grand prize is a trip for two to an Open Source event anywhere in the world
> http://moblin-contest.org/redirect.php?banner_id=100&url=/
> ------------------------------------------------------------------------
>
> _______________________________________________
> jibx-users mailing list
> jibx-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/jibx-users
>   

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
jibx-users mailing list
jibx-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jibx-users

Reply via email to