cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jeff Turner <>
Subject Re: What is a Parser?
Date Tue, 28 Jan 2003 01:54:40 GMT
On Mon, Jan 27, 2003 at 07:19:05PM +0100, Ugo Cei wrote:
> Once upon a time there was a org.apache.cocoon.components.parser.Parser, 
> but now it's deprecated. OK, so I think I should use the Excalibur 
> parser component, which has recently been split into a SAX parser and a 
> DOM parser.
> Looking in excalibur-xmlutil-20030122.jar, I found this class: 
> org.apache.excalibur.xml.sax.Parser.

I guess you mean o.a.e.xml.sax.SAXParser (to complement

> Maybe I can use that. This is my first try:
> org.apache.excalibur.xml.sax.Parser saxParser = null;
> try {
>   saxParser = (org.apache.excalibur.xml.sax.Parser)
>     manager.lookup(org.apache.excalibur.xml.sax.Parser.ROLE);
> }
> finally {
>   if (saxParser != null) manager.release(saxParser);
> }
> Unfortunately, it doesn't compile, because Parser does not implement 
> Component
> so I resolve the problem with a cast:
>   if (saxParser != null) manager.release((Component) saxParser);

(cripes.. I've been happily nulling it in my code.. I'd better go fix:)

> I'm starting to feel a little bit confused, because I was not aware that 
> in Java you could get away with that at compile time.

You should get back a JaxpParser instance, which is a Component, so the
cast is valid.  I'd imagine the compiler doesn't realise this at
compile-time, and you'd get a ClassCastException if it wasn't a

> Maybe I should have a look at the JLS, but since I'm lazy and my code
> runs, I figure I'd better ask cocoon-dev ;-).
> Is this the kosher way of obtaining an XML parser in Cocoon 2.1?
> To further complicate things, Eclipse does not like my little class 
> which implements org.apache.avalon.framework.component.Component, since 
> it insists that the type Component is deprecated, along with 
> ComponentManager. In order to play by the rules, I've removed 
> "Component" from the interfaces my class implements, but Cocoon (or is 
> it Excalibur?) barfs with a "ClassCastException" when I try to put it in 
> cocoon.xconf. Well, I just put back the "implements Component" 
> declaration and live with Eclipse's warnings, but I cannot help feeling 
> a little disoriented about all this ;-).

Yes, those deprecation warnings are annoying and misleading, because
Component is deprecated for Avalon, not Cocoon.  Perhaps Cocoon should
have a special avalon-framework-nodepr-4.1.3.jar , without the


> 	Ugo

To unsubscribe, e-mail:
For additional commands, email:

View raw message