commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Craig R. McClanahan" <craig...@apache.org>
Subject Re: [digester] Multiple Digester Instances
Date Wed, 15 Oct 2003 03:29:23 GMT
Robert Grey wrote:

> Thank you Simon and Craig for your help on this, it seems that 
> creating new instances of the digester with the same Rules object will 
> work as long as all the Digesters are created <i>before</i> any 
> parsing begins.


This is still going to cause you problems.

You will note that a Rule has a setDigester() method, which Digester 
calls when you add it to that Digester.  This is used (within the rule) 
to access state information about the parse in progress -- for example, 
ObjectCreateRule calls digester.push() to push the new object onto the 
stack.  If you add the same ObjectCreateRule instance to two Digester 
instances, the push will always happen on the second Digester instance, 
even if you think you're parsing with the first one.

> I will also try creating separate rules object for each digester and 
> post the results. 

Much more likely to succeed :-).

>
> -Robert Grey


Craig


>
>> From: Simon Kitching <simon@ecnetwork.co.nz>
>> Reply-To: "Jakarta Commons Users List" <commons-user@jakarta.apache.org>
>> To: Jakarta Commons Users List <commons-user@jakarta.apache.org>
>> Subject: Re: [digester] Multiple Digester Instances
>> Date: Wed, 15 Oct 2003 10:48:20 +1300
>>
>> Hi Robert,
>>
>> On Wed, 2003-10-15 at 09:45, Robert Grey wrote:
>> > Actually I resolved the problem by creating a "cache" of digester 
>> objects in
>> > a Vector before the application starts. Then I pull those objects 
>> off one by
>> > one as I need them. It seems that if I intialize a new Digester 
>> object after
>> > parsing has started it begins to create the "null pointers" which 
>> occur in
>> > various places. I am using the same rules object I created in the 
>> beginning
>> > because all of the XML files are the same, I just hoped to split 
>> them into
>> > multiple files for sake of coherence in our application. Could that 
>> be the
>> > problem? Here is an example of one of the "null pointers":
>>
>> Unfortunately, I don't think that reusing rules will work.
>>
>> Rule objects contain a reference to their owning Digester object. This
>> is set when you add a rule to a digester, or set for all Rule object
>> owned by a Rules object (yecch, hate that naming) when the Rules object
>> is added to a Digester. So adding the same Rule object to multiple
>> Digester objects will cause problems; the rules end up having a
>> reference to the last Digester object they happen to have been added to.
>> When fired in the context of some other Digester, if they do something
>> like:
>>   digester.getMatch(), or digester.push()
>> they will be referencing the wrong Digester object. Not good.
>>
>> I think that it is ok to reuse rules *after* a parse has completed, eg
>> * create rules
>> * add to digester1
>> * digester1.parse()
>> * after parse is complete, add to digester2 & parse, etc.
>>
>> However I doubt that reusing them while a parse is still in progress
>> will work without significant rework of Digester core functionality.
>>
>> The exception you are getting is caused by some Rule object throwing an
>> exception in its end method, which fits with what I would expect to
>> happen if you change the Digester a rule is associated with between
>> calls to begin() and end() [because you added the rule to a different
>> Digester object].
>>
>> Regards,
>>
>> Simon
>>
>> > [EDS]  - Problems parsing main config file: :
>> > com.circuitcity.eds.exceptions.XmlParseException: com.
>> > circuitcity.eds.exceptions.XmlParseException:
>> > com.circuitcity.eds.exceptions.XmlParseException: java
>> > .lang.NullPointerException
>> >         at
>> > 
>> org.apache.commons.digester.Digester.createSAXException(Digester.java:2540) 
>>
>> >         at
>> > 
>> org.apache.commons.digester.Digester.createSAXException(Digester.java:2566) 
>>
>> >         at
>> > org.apache.commons.digester.Digester.endElement(Digester.java:1061)
>> >         at
>> > org.apache.xerces.parsers.SAXParser.endElement(SAXParser.java:1403)
>> >         at
>> > 
>> org.apache.xerces.validators.common.XMLValidator.callEndElement(XMLValidator.java:1550)

>>
>> >         at
>> > 
>> org.apache.xerces.framework.XMLDocumentScanner.scanElement(XMLDocumentScanner.java:1809)

>>
>> >         at
>> > 
>> org.apache.xerces.framework.XMLDocumentScanner$ContentDispatcher.dispatch(XMLDocumentScan

>>
>> > ner.java:1182)
>> >         at
>> > 
>> org.apache.xerces.framework.XMLDocumentScanner.parseSome(XMLDocumentScanner.java:381)

>>
>> >         at 
>> org.apache.xerces.framework.XMLParser.parse(XMLParser.java:1098)
>> >         at 
>> org.apache.commons.digester.Digester.parse(Digester.java:1567)
>> >
>> > Thanks for your support.
>> > -Robert Grey
>> >
>> > >From: Simon Kitching <simon@ecnetwork.co.nz>
>> > >Reply-To: "Jakarta Commons Users List" 
>> <commons-user@jakarta.apache.org>
>> > >To: Jakarta Commons Users List <commons-user@jakarta.apache.org>
>> > >Subject: Re: [digester] Multiple Digester Instances
>> > >Date: Wed, 15 Oct 2003 09:25:27 +1300
>> > >
>> > >Hi Robert,
>> > >
>> > >The "xmlrules" code currently does this sort of thing, so you may 
>> wish
>> > >to look there for inspiration.
>> > >
>> > >It would also help if you included the stack trace for your "null
>> > >pointer" problems.
>> > >
>> > >One thing I notice in your code snippet below: where does the "rules"
>> > >object you are passing to your new Digester instance come from? If 
>> it is
>> > >the value returned by digester.getRules(), then this may be the 
>> cause of
>> > >the problem; I doubt that the same Rules object can be used in 
>> multiple
>> > >Digester instances.
>> > >
>> > >Regards,
>> > >
>> > >Simon
>> > >
>> > >On Wed, 2003-10-15 at 09:10, Robert Grey wrote:
>> > > > Currently I am using digester recursively,  I have an object 
>> that will
>> > > > create a new instance of digester when it is called from a rule 
>> in a
>> > > > previous digester instance. I continually get null pointers 
>> when I try
>> > >to do
>> > > > this with this code:
>> > > >
>> > > > public void parseMainConfigFile(InputStream stream) throws
>> > >GeneralException
>> > > > {
>> > > >     // now that plugins are configured, start the parsing process
>> > > >     try {
>> > > >         //return (ParseMainXml) digester.parse(stream);
>> > > >         Digester newDigester = new Digester();
>> > > >         newDigester.setValidating(false);
>> > > >         newDigester.addObjectCreate(ROOTNODE, ParseMainXml.class);
>> > > >         newDigester.setRules(rules);
>> > > >         newDigester.parse(stream);
>> > > >      } catch (Exception e) {
>> > > >         throw new XmlParseException(e);
>> > > >      }
>> > > > }
>> > > >
>> > > > This method is used to create the original parser and to parse 
>> documents
>> > > > called from that original parser. Is there any way to do this 
>> properly?
>> > > > Thanks for any advice...
>> > > > -Robert Grey
>> > >
>> > >
>> > >
>> > >---------------------------------------------------------------------
>> > >To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
>> > >For additional commands, e-mail: commons-user-help@jakarta.apache.org
>> > >
>> >
>> > _________________________________________________________________
>> > Never get a busy signal because you are always connected  with 
>> high-speed
>> > Internet access. Click here to comparison-shop providers.
>> > https://broadband.msn.com
>> >
>> >
>> > ---------------------------------------------------------------------
>> > To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
>> > For additional commands, e-mail: commons-user-help@jakarta.apache.org
>> >
>> >
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>>
>
> _________________________________________________________________
> Add MSN 8 Internet Software to your current Internet access and enjoy 
> patented spam control and more.  Get two months FREE!     
> http://join.msn.com/?page=dept/byoa
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org




---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message