[jdom-interest] Re: Factories for Element creation
Dave Churchville
dmc at clearlight.com
Wed Nov 1 08:51:05 PST 2000
Just to clarify...I'm not really talking about "special" elements that
know
something extra that can be gleaned by parsing, but rather app-specific
overloaded elements that will information added to them after the fact,
not
at creation time.
So, in fact, a "standard" SAXBuilder, etc., could just support no-arg
constructors for custom "MyElement" style classes - assuming they are
extensions of Element. This eliminates the need for a factory, even, if
one
could just say "oh, by the way, when you construct a new element, make
it:
Class.forName( elementClass).newInstance(), and by default, elementClass
is
"org.jdom.Element". Of course, this is assuming that all Element
properties
can be set in JavaBean style, and don't have to be passed in the
constructor
?
Anyway, I would vote for at least this capability, since its not
disruptive,
and doesn't even requre a lot of thought.
Jason Hunter wrote:
> > Problem with creating your own builder, (ie, MySAXBuilder), is that
> > it'd only work for SAX, and you'd have to Do It Again
> > for MyDOMBuilder,
> > or MyJDBCBuilder. A Factory of some flavor would do wonders. Have
> > a BuilderBase with hooks for a factory, and derive FooBuilder from
> > it. Instantly, everything would work. ;)
> >
> > -bob
>
> Problem with a BuilderBase is that you'd have to know beforehand all the
> possible createElement() arguments that might be necessary to create the
> element. Because you're wanting this general, it can't leverage any
> builder internals to pass anything except the standard info. Therefore,
> I see problems for anything above the trivial situation, for example
> wanting a special element that knows where in the source file it came
> from. With a subclass, you can take advantage of special builder
> abilities in a specific subclass.
>
> But the beauty of the JDOM model is you can use whatever builder you
> want! If you or anyone wants to write a builder like SAXBuilder that
> supports factories, JDOM works perfectly well with that builder. It's
> only an issue of whether the builder classes would be official in
> org.jdom or not. Making them official would essentially require
> refactoring the API to support factories, and as you know I'm not eager
> to see that.
>
> -jh-
More information about the jdom-interest
mailing list