[jdom-interest] Re: Factories for Element creation
Jason Hunter
jhunter at collab.net
Tue Oct 31 18:52:05 PST 2000
> Consider an app-specific element I want (so that, for example, I can
> navigate my elements and assign some :
>
> public class CustomElement extends Element {
>
> String extraData;
>
> public void setExtraData( String data) {...}
>
> }
>
> 1) Custom class approach:
>
> SAXBuilder myBuilder = new SAXBuilder();
>
> myBuilder.setElementClass("com.bar.foo.CustomElement");
>
> 2) Factory approach:
>
> SAXBuilder myBuilder = new SAXBuilder();
>
> myBuilder.setElementFactory( new MyElementFactory());
>
> public class MyElementFactory implements JDOMElementFactory {
>
> public Element createElement() { return new CustomElement() ...}
>
> public Element createElement( arg1, arg2.) { ...}
>
> ...
>
> }
>
>
>
> Has anyone thought about this approach? I think its a nice compromise
> between imposing a Factory style on JDOM (plus its a bit late now,
> anyway), and forcing users to "deal with it" by writing custom code
> for this case.
You can do this today, right?. Write your own builder that creates your
own type of elements. What you're wanting is SAXBuilder to provide
extra help with a setElementFactory() method. I'd rather see SAXBuilder
have protected create methods that could be overridden, if such
functionality is needed at all.
-jh-
More information about the jdom-interest
mailing list