You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avalon.apache.org by Carsten Ziegeler <cz...@s-und-n.de> on 2002/04/17 11:09:13 UTC
Component Design Question
Hi,
I have just finished the integration of the source resolving components
from excalibur into the latest Cocoon.
But (unfortunately) I'm not very pleased with the current solution. As I
think that this is a general design question, I would like to start this
discussion.
Putting it short, the question is: Should instanceof be used or avoided?
My short answer to this is: It should be avoided as it is not
object-oriented.
Ok, no for the longer story:
Excalibur has a new component (in the scratchpad) called the source resolver
which is able to resolve any URI and which supports custom protocols.
The SourceResolver resolves a URI by returning a Source object. This is a
very
lightweight object which has not many methods/features.
The Source interface can be *extended* with several features, for example
the ModifiableSource or the XMLizable interface.
Now, when dealing with a Source object (especially in Cocoon, but I believe
in other environments as well), the client of the source resolver has always
to check if the returned source object is modifiable (= instanceof
ModifiableSource)
or not.
Within Cocoon this leads to two checks for instanceof Modifiable for each
URI
used (this means for each XML or XSL file read etc.).
I don't think that this is very elegant.
So, I personally tend to adding the methods of the ModifiableSource
interface
to the Source interface and add a "isModifiable()" method to the Source
interface
as well. This is in my eyes a cleaner solution and avoids instanceof checks.
(But with the disadvantage of a bigger Source interface).
For Cocoon the same applies to the XMLizable interface which marks a Source
object that it can produce XML SAX represantation. I would like to add
a isXMLizable() method and extend the Source interface with the XMLizable
interface.
So, I'm really interested in your opinions about this.
Thanks
Carsten
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
RE: Component Design Question
Posted by David BERNARD <dw...@freesurf.fr>.
Hi,
I'm not a expert, but like wrote Peter Donald, XMLizable is a interface
and use "instanceof" to check a role isn't bad, and IHMO it's preferable
to coupling XML and Source.
> So, I see several possible solutions:
>
> a) Source interface extends XMLizable
> For all applications dealing with XML this is the easiest way. All
> applications not dealing with XML can ignore this part of the interface.
> The disadvantage is the coupling of the source and the xml package.
>
> b) Source does not extend XMLizable but the Implementations do
> Disadvantages: No decoupling and instanceof is required.
>
> c) Source does not extend XMLizable and the Implementations neither do so
> Advantage: Decoupling
> Disadvantage: instanceof required and each Source has to be subclasses
> for XML applications.
I think to use a XMLizable from a source, you can create a specific
class but you don't need to subclass each Source. You can use a
Decorator to provide XMLizable method from InputStream.
> d) Source does not extend XMLizable and does not care about XML, too
> As you pointed out in your other email in this thread, it is very
> easy to make out of the input stream provided by the Source object
> a sax stream.
> Advantage: Decoupled, no instanceof required
>
> Now, looking at this list d) seems to be the way to go, but what
> about more "abstract" Sources which provide an InputStream which
> does not deliver XML and only the XMLizable interface adds this
> functionality? I think, we have some of them in Cocoon already...
In Cocoon all sources aren't XMLizable : image, css, js...
And there are some Source XMLizable some time, by exemple XML:DB
Resources can be XML or Binary.
> So, for simplicity, I still prefer a) (although from the theoretical
> point I dislike the coupling of Source and XMLizable).
>
> The question is, is the coupling of the packages xml and source
> really so bad?
I think yes, because source can be used in context whitout XML,
like ANT, Virtual File System...
--
--------------------------------------------------------------
David "Dwayne" Bernard Freelance Developer (Java)
mailto:dwayne@java-fan.com
\|/ http://dwayne.java-fan.com
--o0O @.@ O0o-------------------------------------------------
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: Component Design Question
Posted by Peter Royal <pr...@managingpartners.com>.
On Wednesday 17 April 2002 10:34 am, Carsten Ziegeler wrote:
> d) Source does not extend XMLizable and does not care about XML, too
> As you pointed out in your other email in this thread, it is very
> easy to make out of the input stream provided by the Source object
> a sax stream.
> Advantage: Decoupled, no instanceof required
>
> Now, looking at this list d) seems to be the way to go, but what
> about more "abstract" Sources which provide an InputStream which
> does not deliver XML and only the XMLizable interface adds this
> functionality? I think, we have some of them in Cocoon already...
(d) is fine, but any consumer of a Source that needs the Source as XML should
check to see if the source is XMLizable first. For Cocoon, the SitemapSource
can returns the SAX event stream directly via toSAX, but has to convert its
SAX events into an InputStream for getInputStream().
To me, the benefit of having Source extend XMLizable, is that any consumer of
a source that needs the source as XML just has to call toSAX() rather than
checking to see if the instance returned is XMLizable.
I do realize that the potential uses of the SourceResolver go far beyond
returning XMLizable sources though.
Or as long as we provide a simple utility method to convert any Source into
XML, that works for me.
--
peter royal -> proyal@managingpartners.com
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: Component Design Question
Posted by Nicola Ken Barozzi <ni...@apache.org>.
From: "Peter Donald" <pe...@apache.org>
> So maybe a generic framework for converting streams to XML may be in order
?
> Something separate from XML parsing stuff already in place?
Look at the comons sandbox morphos proposal.
We are ready to start.
I will commit initial codebase this week.
Hope to see ya! :-D
--
Nicola Ken Barozzi nicolaken@apache.org
- verba volant, scripta manent -
(discussions get forgotten, just code remains)
---------------------------------------------------------------------
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: Component Design Question
Posted by Peter Donald <pe...@apache.org>.
On Thu, 18 Apr 2002 19:52, Carsten Ziegeler wrote:
> > So maybe a generic framework for converting streams to XML may be
> > in order ?
> > Something separate from XML parsing stuff already in place?
>
> The XMLizer itself is intependent from the parser stuff but of course
> some implementations like the conversion from "text/xml" into SAX
> events requires a parser.
> I thought of the package "org.apache.excalibur.xmlizer" resp.
> "org.apache.excalibur.xmlizer.impl".
works for me.
--
Cheers,
Peter Donald
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
RE: Component Design Question
Posted by Carsten Ziegeler <cz...@s-und-n.de>.
Peter Donald wrote:
>
> <snip>
> > So, my proposol is to add a getMimeType() method to the Source interface
> > and an "XMLizer" component to the xml package. This XMLizer gets
> > a mime-type and an input stream as input and creates sax events
> from this.
> > This will
> > - decouple the source and the xml package totally
> > - the XMLizer is not only usable for source objects
> > - the XMLizer is extensible...
>
> fantastic. This brings up another idea I have been playing with
> recently. I
> have a couple of binary file formats that I convert into SAX events for
> further processing...
>
Yo, that sort of things.
> Maybe it would be an idea to instead create a new package for XMLizer
> interface and related implementations. ie I assume that there is a POI
> deserializer (or whatever they are called in cocoon) that reads the
> excel/word/whatever documents and produces an XML stream (either
> as SAX or as
> DOM). I have similar readers that deal with other binary
> protocols. I also
> used to always use a directory to XML producer (I stole idea from
> stylebook
> IIRC). I am sure other people have other similar demands. (PDF to XML?)
>
> So maybe a generic framework for converting streams to XML may be
> in order ?
> Something separate from XML parsing stuff already in place?
>
The XMLizer itself is intependent from the parser stuff but of course
some implementations like the conversion from "text/xml" into SAX
events requires a parser.
I thought of the package "org.apache.excalibur.xmlizer" resp.
"org.apache.excalibur.xmlizer.impl".
Carsten
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: Component Design Question
Posted by Peter Donald <pe...@apache.org>.
On Thu, 18 Apr 2002 15:46, Carsten Ziegeler wrote:
> Peter Donald wrote:
> > <snip/>
> >
> > 2 options here.
> >
> > [1] We add an extra component to do conversion of stream to xml
> > (I assume this
> > is for converting things like excel into XML??? or .psd files to
> > svga??). So
> > what I would do in this case is then add a "getMimeType()" to the Source
> > interface that returns a string about what type the underlying file. Then
> > have another set of components that convert objects of different
> > mimetypes to
> > xml streams.
> >
> > This is the same architecture as used in the Java URL system ie they have
> > stream handlers (which are like Source objects) and
> > ContentHandlers (which
> > are like converters between stream and object type).
>
> Hi Peter,
>
> believe me or not, but I thought about this problem the whole night
> and finally came to the same conclusion as you propose above
woohoo! Hate when that happens though ;)
> So, my proposol is to add a getMimeType() method to the Source interface
> and an "XMLizer" component to the xml package. This XMLizer gets
> a mime-type and an input stream as input and creates sax events from this.
> This will
> - decouple the source and the xml package totally
> - the XMLizer is not only usable for source objects
> - the XMLizer is extensible...
fantastic. This brings up another idea I have been playing with recently. I
have a couple of binary file formats that I convert into SAX events for
further processing...
Maybe it would be an idea to instead create a new package for XMLizer
interface and related implementations. ie I assume that there is a POI
deserializer (or whatever they are called in cocoon) that reads the
excel/word/whatever documents and produces an XML stream (either as SAX or as
DOM). I have similar readers that deal with other binary protocols. I also
used to always use a directory to XML producer (I stole idea from stylebook
IIRC). I am sure other people have other similar demands. (PDF to XML?)
So maybe a generic framework for converting streams to XML may be in order ?
Something separate from XML parsing stuff already in place?
> I hope to make a first version of my proposal today, so there
> should be no time problem.
excellent. Look forward to it ;)
--
Cheers,
Peter Donald
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
RE: Component Design Question
Posted by Carsten Ziegeler <cz...@s-und-n.de>.
Peter Donald wrote:
>
> <snip/>
>
> 2 options here.
>
> [1] We add an extra component to do conversion of stream to xml
> (I assume this
> is for converting things like excel into XML??? or .psd files to
> svga??). So
> what I would do in this case is then add a "getMimeType()" to the Source
> interface that returns a string about what type the underlying file. Then
> have another set of components that convert objects of different
> mimetypes to
> xml streams.
>
> This is the same architecture as used in the Java URL system ie they have
> stream handlers (which are like Source objects) and
> ContentHandlers (which
> are like converters between stream and object type).
>
Hi Peter,
believe me or not, but I thought about this problem the whole night
and finally came to the same conclusion as you propose above (it only
took much longer for me :( ).
I think the mistake I made is that a saw a relation between the protocol
and the type of content this protocol returns. But as we all know
this is not true. The protocol specifies the type of transport but
not the type of content.
So, my proposol is to add a getMimeType() method to the Source interface
and an "XMLizer" component to the xml package. This XMLizer gets
a mime-type and an input stream as input and creates sax events from this.
This will
- decouple the source and the xml package totally
- the XMLizer is not only usable for source objects
- the XMLizer is extensible...
> [2] Make the sources implement XMLizable ;) Personally I have no
> problem with
> the "object instanceof XMLizable" statement though and don't
> really consider
> it a problem.
>
> I really think [1] is the right way to go but it is also more
> work so I would
> suggest that you go with [2] for now if there is a deadline
> looming else go
> with [1]
I hope to make a first version of my proposal today, so there
should be no time problem.
>
> > The question is, is the coupling of the packages xml and source
> > really so bad?
>
> It would stop me using it :)
>
Argh, that's really bad.
Carsten
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: Component Design Question
Posted by Peter Donald <pe...@apache.org>.
On Thu, 18 Apr 2002 00:34, Carsten Ziegeler wrote:
> Peter Donald wrote:
> > Hmmm. Not sure I got across what I meant to. Basically it came
> > down to this.
> > If you don't implment XMLizable (and thus decouple from xml.*
> > package) then
> > you can reuse the whole package in other contexts.
>
> Yes, this was the intension of the initial decoupling XMLizable
> from the Source interface.
> Unfortunately, the implementations of the Source package are
> tied to the xml package as they already implement XMLizable.
True but I would recomend un-coupling them personally ;)
> It is possible. If the Source interface would extend the XMLizable
> interface and you resolve an html file the implementation of the
> XMLizable interface could either return an exception or use
> jtidy to convert it etc. If you don't need XML and your context,
> you don't have to use it.
Again I would consider the conversion to XML (and optional normalization and
cleanup with jtidy or whatever) to be the concern of a different component. I
would probably have a different converter project to do this
> b) Source does not extend XMLizable but the Implementations do
> Disadvantages: No decoupling and instanceof is required.
...
> d) Source does not extend XMLizable and does not care about XML, too
> As you pointed out in your other email in this thread, it is very
> easy to make out of the input stream provided by the Source object
> a sax stream.
> Advantage: Decoupled, no instanceof required
+1 to either of above
> Now, looking at this list d) seems to be the way to go, but what
> about more "abstract" Sources which provide an InputStream which
> does not deliver XML and only the XMLizable interface adds this
> functionality? I think, we have some of them in Cocoon already...
2 options here.
[1] We add an extra component to do conversion of stream to xml (I assume this
is for converting things like excel into XML??? or .psd files to svga??). So
what I would do in this case is then add a "getMimeType()" to the Source
interface that returns a string about what type the underlying file. Then
have another set of components that convert objects of different mimetypes to
xml streams.
This is the same architecture as used in the Java URL system ie they have
stream handlers (which are like Source objects) and ContentHandlers (which
are like converters between stream and object type).
[2] Make the sources implement XMLizable ;) Personally I have no problem with
the "object instanceof XMLizable" statement though and don't really consider
it a problem.
I really think [1] is the right way to go but it is also more work so I would
suggest that you go with [2] for now if there is a deadline looming else go
with [1]
> The question is, is the coupling of the packages xml and source
> really so bad?
It would stop me using it :)
--
Cheers,
Peter Donald
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
RE: Component Design Question
Posted by Carsten Ziegeler <cz...@s-und-n.de>.
Peter Donald wrote:
>
> Hmmm. Not sure I got across what I meant to. Basically it came
> down to this.
> If you don't implment XMLizable (and thus decouple from xml.*
> package) then
> you can reuse the whole package in other contexts.
>
Yes, this was the intension of the initial decoupling XMLizable
from the Source interface.
Unfortunately, the implementations of the Source package are
tied to the xml package as they already implement XMLizable.
So for a real decoupling we have to separate the interfaces *and*
the implementation, which would lead to the point that for
each Source implementation in the source package we have
a subclass in the xml.source package which extends the
implementation by implementing the XMLizable interface.
Hm, this sounds not very elegant.
> For instance I would like to use it to retrieve
> * xml and xsl sheets as per Cocoon
> * velocity templates
> * other resources that can be referred to by a URI. In Ant2 quite
> a few things
> will be resolvable by URIs and it would be nice to have a common
> interface to
> it all.
>
> Anyways I think that should be possible ? And I would love it to be ;P
>
It is possible. If the Source interface would extend the XMLizable
interface and you resolve an html file the implementation of the
XMLizable interface could either return an exception or use
jtidy to convert it etc. If you don't need XML and your context,
you don't have to use it.
I personally don't like this, too, but it makes things less
complicated.
So, I see several possible solutions:
a) Source interface extends XMLizable
For all applications dealing with XML this is the easiest way. All
applications not dealing with XML can ignore this part of the interface.
The disadvantage is the coupling of the source and the xml package.
b) Source does not extend XMLizable but the Implementations do
Disadvantages: No decoupling and instanceof is required.
c) Source does not extend XMLizable and the Implementations neither do so
Advantage: Decoupling
Disadvantage: instanceof required and each Source has to be subclasses
for XML applications.
d) Source does not extend XMLizable and does not care about XML, too
As you pointed out in your other email in this thread, it is very
easy to make out of the input stream provided by the Source object
a sax stream.
Advantage: Decoupled, no instanceof required
Now, looking at this list d) seems to be the way to go, but what
about more "abstract" Sources which provide an InputStream which
does not deliver XML and only the XMLizable interface adds this
functionality? I think, we have some of them in Cocoon already...
So, for simplicity, I still prefer a) (although from the theoretical
point I dislike the coupling of Source and XMLizable).
The question is, is the coupling of the packages xml and source
really so bad?
> BTW you should probably move the classes into
> org.apache.excalibur.source.*
> priorit to releasing it.
>
Yes, I will do this when I move them out of the scratchpad.
> BTW2 if you would like to move the implementations of the various
> interfaces
> into a subpackage org.apache.excalibur.source.impl.* then that
> would make the
> component much more easier to learn IMHO
>
Thanks, this is a good idea.
> BTW3 Love the javadocs! :)
>
Thanks :)
Carsten
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: Component Design Question
Posted by Peter Donald <pe...@apache.org>.
Hmmm. Not sure I got across what I meant to. Basically it came down to this.
If you don't implment XMLizable (and thus decouple from xml.* package) then
you can reuse the whole package in other contexts.
For instance I would like to use it to retrieve
* xml and xsl sheets as per Cocoon
* velocity templates
* other resources that can be referred to by a URI. In Ant2 quite a few things
will be resolvable by URIs and it would be nice to have a common interface to
it all.
Anyways I think that should be possible ? And I would love it to be ;P
BTW you should probably move the classes into org.apache.excalibur.source.*
priorit to releasing it.
BTW2 if you would like to move the implementations of the various interfaces
into a subpackage org.apache.excalibur.source.impl.* then that would make the
component much more easier to learn IMHO
BTW3 Love the javadocs! :)
On Wed, 17 Apr 2002 23:52, Peter Donald wrote:
> On Wed, 17 Apr 2002 19:09, Carsten Ziegeler wrote:
> > Putting it short, the question is: Should instanceof be used or avoided?
> > My short answer to this is: It should be avoided as it is not
> > object-oriented.
>
> We use instanceof throughout avalon. ie We often pick out features of a
> component and apply special processing to component if component requires
> feature. Consider the
>
> if( object instanceof Initializable )
> {
> ((Initializable)object).initialize();
> }
>
> However using instanceof operator to pick up out members in a inheritance
> hierarchy (aka members in a classification hierarchy) is definetly
> considered bad. As a rule of thumb - Anytime the second parameter to
> instanceof operator is a class (and not an interface) you know you are
> probably doing something bad.
>
> > The Source interface can be *extended* with several features, for example
> > the ModifiableSource or the XMLizable interface.
> >
> > Now, when dealing with a Source object (especially in Cocoon, but I
> > believe in other environments as well), the client of the source resolver
> > has always to check if the returned source object is modifiable (=
> > instanceof ModifiableSource)
> > or not.
> > Within Cocoon this leads to two checks for instanceof Modifiable for each
> > URI
> > used (this means for each XML or XSL file read etc.).
> > I don't think that this is very elegant.
>
> I think mergingthe ModificableSource and Source is a good idea as it is a
> reasonable assumption that in the majority of use cases the two interfaces
> will be highly correlated and it does not hurt to expose the Modifiable
> features in base interface as there is no security/performance or other
> issues that I am aware of ?
>
> > For Cocoon the same applies to the XMLizable interface which marks a
> > Source object that it can produce XML SAX represantation. I would like to
> > add a isXMLizable() method and extend the Source interface with the
> > XMLizable interface.
>
> XMLizable is a different kettle of fish IMHO. It is not part of the work
> interface exposed by Resolver but a feature of implementation returned. I
> would highly recomend you dont mix these concerns.
>
> For instance I was considering using the source stuff inside myrmidon (Ant2
> proposal) but have no real need of toXML and thus requiring that would be
> overkill for my use.
>
> If you actually look at the implementations of source in package they
> actually are just convenience methods. You could quite easily implement
> toXML outside the class with zero negative effects. Doing it this way would
> decouple source from the excalibur.xml.* package and the
> framework.component.* package making it much more easier to support in
> future. Ad much easier to extract and use in other contexts.
--
Cheers,
Peter Donald
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: Component Design Question
Posted by Peter Royal <pr...@managingpartners.com>.
On Wednesday 17 April 2002 09:52 am, Peter Donald wrote:
> If you actually look at the implementations of source in package they
> actually are just convenience methods. You could quite easily implement
> toXML outside the class with zero negative effects. Doing it this way would
> decouple source from the excalibur.xml.* package and the
> framework.component.* package making it much more easier to support in
> future. Ad much easier to extract and use in other contexts.
I think we should provide a utility function to do that as it will be
frequently used by some users of the source package. Where would the utility
function live though, as it will carry the dependencies you mention. Plus if
we were to make it a static method, it would need a signature such as
toSAX(Source source, ContentHandler handler, ComponetManager manager);
I understand how the concerns are separate though.
-pete
--
peter royal -> proyal@managingpartners.com
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: Component Design Question
Posted by Peter Donald <pe...@apache.org>.
On Wed, 17 Apr 2002 19:09, Carsten Ziegeler wrote:
> Putting it short, the question is: Should instanceof be used or avoided?
> My short answer to this is: It should be avoided as it is not
> object-oriented.
We use instanceof throughout avalon. ie We often pick out features of a
component and apply special processing to component if component requires
feature. Consider the
if( object instanceof Initializable )
{
((Initializable)object).initialize();
}
However using instanceof operator to pick up out members in a inheritance
hierarchy (aka members in a classification hierarchy) is definetly considered
bad. As a rule of thumb - Anytime the second parameter to instanceof operator
is a class (and not an interface) you know you are probably doing something
bad.
> The Source interface can be *extended* with several features, for example
> the ModifiableSource or the XMLizable interface.
>
> Now, when dealing with a Source object (especially in Cocoon, but I believe
> in other environments as well), the client of the source resolver has
> always to check if the returned source object is modifiable (= instanceof
> ModifiableSource)
> or not.
> Within Cocoon this leads to two checks for instanceof Modifiable for each
> URI
> used (this means for each XML or XSL file read etc.).
> I don't think that this is very elegant.
I think mergingthe ModificableSource and Source is a good idea as it is a
reasonable assumption that in the majority of use cases the two interfaces
will be highly correlated and it does not hurt to expose the Modifiable
features in base interface as there is no security/performance or other
issues that I am aware of ?
> For Cocoon the same applies to the XMLizable interface which marks a Source
> object that it can produce XML SAX represantation. I would like to add
> a isXMLizable() method and extend the Source interface with the XMLizable
> interface.
XMLizable is a different kettle of fish IMHO. It is not part of the work
interface exposed by Resolver but a feature of implementation returned. I
would highly recomend you dont mix these concerns.
For instance I was considering using the source stuff inside myrmidon (Ant2
proposal) but have no real need of toXML and thus requiring that would be
overkill for my use.
If you actually look at the implementations of source in package they actually
are just convenience methods. You could quite easily implement toXML outside
the class with zero negative effects. Doing it this way would decouple source
from the excalibur.xml.* package and the framework.component.* package making
it much more easier to support in future. Ad much easier to extract and use
in other contexts.
--
Cheers,
Peter Donald
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: Component Design Question
Posted by Peter Royal <pr...@managingpartners.com>.
On Wednesday 17 April 2002 09:31 am, Carsten Ziegeler wrote:
> Ok, I agree with you both. I'm currently adding XMLizable to the
> Source interface aggain.
Very good. I'll modify the XSLTProcessor accordingly before sending patches.
-pete
--
peter royal -> proyal@managingpartners.com
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
RE: Component Design Question
Posted by Carsten Ziegeler <cz...@s-und-n.de>.
Peter Royal wrote:
>
> On Wednesday 17 April 2002 08:45 am, Berin Loritsch wrote:
> > Lastly, we have to consider the Source interfae itself. If it is
> > common to be able to read a Source using an InputStream and have
> > the option to read it using a ContentHandler, why not have both
> > of those in the interface. Again, if it is common to check when
> > the Source was last modified, why not have that in the Source
> > interface. The Source objects that don't support a feature would
> > throw an exception or return a 0 value.
>
> This is what I was thinking. Any source can easily be XMLizable,
> and should
> have some notion of when it was created, if not last modified.
> Thus I would
> be in favor of changing source to extend XMLizable and adding a method
> getLastModified().
>
Ok, I agree with you both. I'm currently adding XMLizable to the
Source interface aggain.
> I ported the XSLTProcessor from Cocoon toe xcalibur last night
Great!!!
> and ran into
> the exact XMLizable issue you describe, Carsten. I made a method
> sourceToSAX() that checked to see if a Source was XMLizable, and
> if so just
> used its toSAX() otherwise piped its InputStream through the Parser. The
> thought of merging XMLizable into source would remove the need to do that.
>
Agree!
> I was also thinking about the ModifiableSource interface. Currently it
> doesn't let you modify a source, it just lets you check to see if
> it has been
> modified. That seems like a misnomer to me. In the spirit of the
> getLastModified() method that returns an int, why not merge the
> SourceValiditity-related methods back into the primary Source interface?
>
Yes, I'm currently doing this as well!
> I would expect a ModifiableSource to expose a method such as
> getOutputStream() or getXMLConsumer(), to enable a client to change the
> contents of the source.
Thanks
Carsten
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: Component Design Question
Posted by Peter Royal <pr...@managingpartners.com>.
On Wednesday 17 April 2002 08:45 am, Berin Loritsch wrote:
> Lastly, we have to consider the Source interfae itself. If it is
> common to be able to read a Source using an InputStream and have
> the option to read it using a ContentHandler, why not have both
> of those in the interface. Again, if it is common to check when
> the Source was last modified, why not have that in the Source
> interface. The Source objects that don't support a feature would
> throw an exception or return a 0 value.
This is what I was thinking. Any source can easily be XMLizable, and should
have some notion of when it was created, if not last modified. Thus I would
be in favor of changing source to extend XMLizable and adding a method
getLastModified().
I ported the XSLTProcessor from Cocoon toe xcalibur last night and ran into
the exact XMLizable issue you describe, Carsten. I made a method
sourceToSAX() that checked to see if a Source was XMLizable, and if so just
used its toSAX() otherwise piped its InputStream through the Parser. The
thought of merging XMLizable into source would remove the need to do that.
I was also thinking about the ModifiableSource interface. Currently it
doesn't let you modify a source, it just lets you check to see if it has been
modified. That seems like a misnomer to me. In the spirit of the
getLastModified() method that returns an int, why not merge the
SourceValiditity-related methods back into the primary Source interface?
I would expect a ModifiableSource to expose a method such as
getOutputStream() or getXMLConsumer(), to enable a client to change the
contents of the source.
-pete
--
peter royal -> proyal@managingpartners.com
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: Component Design Question
Posted by Berin Loritsch <bl...@apache.org>.
Carsten Ziegeler wrote:
> Berin Loritsch wrote:
>
<snip/>
> If I get you right, the "hasFeature()" replaces "instanceof" and I
> have to cast the Source object to the "feature interface" if hasFeature()
> is true. Ok, this looks more elegant, than instanceof then, but has
> not really an advantage.
True
>
>
>>Lastly, we have to consider the Source interfae itself. If it is
>>common to be able to read a Source using an InputStream and have
>>the option to read it using a ContentHandler, why not have both
>>of those in the interface. Again, if it is common to check when
>>the Source was last modified, why not have that in the Source
>>interface. The Source objects that don't support a feature would
>>throw an exception or return a 0 value.
>>
>>Which do you like the best?
>
>
> This last one! I think we should add the common features to the
> Source object, like the ModifiableSource.
> I'm not sure about XMLizable. It is *very* common for Cocoon,
> but perhaps absolutely uncommon in the general approach. So this
> should be as it is now.
Nowadays with all the corporate investment in XML/Relational mapping
and Web Services, XMLizable would be more common than you might think.
Esp. when you consider the process of serializing Sources to disk.
A SOurce can represent something in memory, and we may want to send
it somewhere else. XML is a convenient format to represent information.
>
> So, thank you very much for this great analysis, Berin!
> I think, I know what to do now.
Kool BEans MAn!
(I have got to let go of that shift key sooner :) )
--
"They that give up essential liberty to obtain a little temporary safety
deserve neither liberty nor safety."
- Benjamin Franklin
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
RE: Component Design Question
Posted by Carsten Ziegeler <cz...@s-und-n.de>.
Berin Loritsch wrote:
>
> Carsten Ziegeler wrote:
> > Hi,
> >
> > I have just finished the integration of the source resolving components
> > from excalibur into the latest Cocoon.
> > But (unfortunately) I'm not very pleased with the current solution. As I
> > think that this is a general design question, I would like to start this
> > discussion.
> >
> > Putting it short, the question is: Should instanceof be used or avoided?
> > My short answer to this is: It should be avoided as it is not
> > object-oriented.
>
> Remember, COP is similar but not the same as OOP. Now, for the longer
> story...
>
Ah, I didn't see it this way. Hmm, yes, that's a good argument!
> <snip/>
>
>
> > The Source interface can be *extended* with several features,
> for example
> > the ModifiableSource or the XMLizable interface.
> >
> > Now, when dealing with a Source object (especially in Cocoon,
> but I believe
> > in other environments as well), the client of the source
> resolver has always
> > to check if the returned source object is modifiable (= instanceof
> > ModifiableSource)
> > or not.
> > Within Cocoon this leads to two checks for instanceof
> Modifiable for each
> > URI
> > used (this means for each XML or XSL file read etc.).
> > I don't think that this is very elegant.
>
> Its not. However, we have to look at the alternatives:
>
> 1) modify the interface so that we have "isXXX()" methods
> 2) live with "instanceof"
> 3) implement a "hasFeature()" method.
> 4) have all features in one Source object
>
> The key point is that we want something that is a _quick_ check, and we
> don't want to deal with unnecessary strings--they take much longer to
> evaluate than integers or other primitives.
Yes
>
> The "isXXX()" approach, as you were advocating seems favorable until
> you realize that we need to know all types of Sources available. WHat
> happens if another project has a new type of Source? We can't have
> all Source objects in Avalon, nor can we expect to be able to change
> the interface every time a new Source type is introduced. So we can
> rule this out.
>
Yes, this is true, we can't know all types in advance. But we know
the common ones.
> Living with "instanceof" is not pretty, but very flexible. We are
> Component Oriented, not Object Oriented--so arguments about it not
> being object oriented are moot. However, the instanceof approach
> should be shunned for other reasons. In COP, we just want to *use*
> the object, not check to see if it is a certain type of object.
> At that time, you are binding yourself to an implementation, which
> is counterproductive.
Yupp.
>
> Using the "hasFeature()" method also looks promissing. It follows the
> SAX API useage pattern--except I would prefer primitives to Strings.
> The only problem with primitives is deciding which Source object gets
> what value.
If I get you right, the "hasFeature()" replaces "instanceof" and I
have to cast the Source object to the "feature interface" if hasFeature()
is true. Ok, this looks more elegant, than instanceof then, but has
not really an advantage.
>
> Lastly, we have to consider the Source interfae itself. If it is
> common to be able to read a Source using an InputStream and have
> the option to read it using a ContentHandler, why not have both
> of those in the interface. Again, if it is common to check when
> the Source was last modified, why not have that in the Source
> interface. The Source objects that don't support a feature would
> throw an exception or return a 0 value.
>
> Which do you like the best?
This last one! I think we should add the common features to the
Source object, like the ModifiableSource.
I'm not sure about XMLizable. It is *very* common for Cocoon,
but perhaps absolutely uncommon in the general approach. So this
should be as it is now.
So, thank you very much for this great analysis, Berin!
I think, I know what to do now.
Thanks
Carsten
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: Component Design Question
Posted by Berin Loritsch <bl...@apache.org>.
Carsten Ziegeler wrote:
> Hi,
>
> I have just finished the integration of the source resolving components
> from excalibur into the latest Cocoon.
> But (unfortunately) I'm not very pleased with the current solution. As I
> think that this is a general design question, I would like to start this
> discussion.
>
> Putting it short, the question is: Should instanceof be used or avoided?
> My short answer to this is: It should be avoided as it is not
> object-oriented.
Remember, COP is similar but not the same as OOP. Now, for the longer
story...
<snip/>
> The Source interface can be *extended* with several features, for example
> the ModifiableSource or the XMLizable interface.
>
> Now, when dealing with a Source object (especially in Cocoon, but I believe
> in other environments as well), the client of the source resolver has always
> to check if the returned source object is modifiable (= instanceof
> ModifiableSource)
> or not.
> Within Cocoon this leads to two checks for instanceof Modifiable for each
> URI
> used (this means for each XML or XSL file read etc.).
> I don't think that this is very elegant.
Its not. However, we have to look at the alternatives:
1) modify the interface so that we have "isXXX()" methods
2) live with "instanceof"
3) implement a "hasFeature()" method.
4) have all features in one Source object
The key point is that we want something that is a _quick_ check, and we
don't want to deal with unnecessary strings--they take much longer to
evaluate than integers or other primitives.
The "isXXX()" approach, as you were advocating seems favorable until
you realize that we need to know all types of Sources available. WHat
happens if another project has a new type of Source? We can't have
all Source objects in Avalon, nor can we expect to be able to change
the interface every time a new Source type is introduced. So we can
rule this out.
Living with "instanceof" is not pretty, but very flexible. We are
Component Oriented, not Object Oriented--so arguments about it not
being object oriented are moot. However, the instanceof approach
should be shunned for other reasons. In COP, we just want to *use*
the object, not check to see if it is a certain type of object.
At that time, you are binding yourself to an implementation, which
is counterproductive.
Using the "hasFeature()" method also looks promissing. It follows the
SAX API useage pattern--except I would prefer primitives to Strings.
The only problem with primitives is deciding which Source object gets
what value.
Lastly, we have to consider the Source interfae itself. If it is
common to be able to read a Source using an InputStream and have
the option to read it using a ContentHandler, why not have both
of those in the interface. Again, if it is common to check when
the Source was last modified, why not have that in the Source
interface. The Source objects that don't support a feature would
throw an exception or return a 0 value.
Which do you like the best?
--
"They that give up essential liberty to obtain a little temporary safety
deserve neither liberty nor safety."
- Benjamin Franklin
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>