Re: Caching grammars

Robert Huffman <[email protected]>
Newsgroups gmane.text.xml.xerces-j.user
Message-ID <CAKhQOUaX9HuV0aGh9xvKPBMkFnu+0a+BqDojYTqqB13-yh9=oQ@mail.gmail.com>
That does seem to be the way it works. I dug into the source more after my
initial post. It seems that the grammar pool in the Schema is used to
initialize a second grammar pool owned by the Validator. This second
grammar pool lives only as long as the validator.

I haven't gotten back into that part of my code in a week or so, but I
believe I can ultimately get my grammars that are dynamically loaded via
the LSResourceResolver by reusing my Validator. Of course, the Validator is
not thread-safe, so I will probably use a ThreadLocal<Validator>.
(Synchronizing a single validator is probably not acceptable in my
environment.)

Of course, that means I will end up with a grammar cache in each thread in
my thread pool. So my next step is to figure out if the grammars are thread
safe. If they are, perhaps I can figure out a way to share a single
instance of a thread safe grammar cache between validators.


On Sun, Jan 20, 2013 at 10:23 AM, Michael Glavassevich
<[email protected]>wrote:

> The JAXP Schema created through SchemaFactory.newSchema() caches grammars
> (through SoftReferences [1]) by their schema location. It's been quite
> awhile since I've looked at how this works, but it wouldn't surprise me if
> Xerces calls your LSResourceResolver each time you validate in order to
> give your application an opportunity to redirect the schema location and
> then use the value returned from the LSResourceResolver to look up the
> cached grammar.
>
> Thanks.
>
> [1]
>
> http://svn.apache.org/viewvc/xerces/java/trunk/src/org/apache/xerces/jaxp/validation/SoftReferenceGrammarPool.java?annotate=699892
>
> Michael Glavassevich
> XML Technologies and WAS Development
> IBM Toronto Lab
> E-mail: [email protected]
> E-mail: [email protected]
>
> Robert Huffman <[email protected]> wrote on 12/01/2013 05:04:17 PM:
>
> > I must parse documents that may use a large number of fairly large
> > XSDs. However, the large majority of documents will not use most of
> > those XSDs. Therefore, I would like to use a custom
> > LSResourceResolver to resolve the target namespaces to local
> > resources during parsing rather than building a Schema object that
> > has all the grammars loaded up front.
> >
> > Unfortunately, as nearly as I can tell, grammars loaded through the
> > use of a LSResourceResolver are never cached in the grammar pool. Is
> > that correct? Is there some nuance I'm missing?
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.