<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Generator" CONTENT="MS Exchange Server version 5.5.2655.35">
<TITLE>RE: [jdom-interest] Is JDOM dying?</TITLE>
</HEAD>
<BODY>
<P><FONT SIZE=2>How about the following:</FONT>
</P>
<BR>
<P><FONT SIZE=2> element.addContent(changeNamespace(subelement, element.getNamespace());</FONT>
</P>
<P><FONT SIZE=2>where changeNamespace is defined as follows:</FONT>
</P>
<P><FONT SIZE=2> private static Element changeNamespace(Element emt, Namespace to) {</FONT>
<BR><FONT SIZE=2> return changeNamespace(emt, emt.getNamespace(), to);</FONT>
<BR><FONT SIZE=2> }</FONT>
</P>
<P><FONT SIZE=2> private static Element changeNamespace(Element emt, Namespace from, Namespace to) {</FONT>
<BR><FONT SIZE=2> Namespace ns = emt.getNamespace();</FONT>
</P>
<P><FONT SIZE=2> if (!ns.equals(from)) return emt;</FONT>
</P>
<P><FONT SIZE=2>/* Uncomment to change attribute namespaces....</FONT>
<BR><FONT SIZE=2> for (Iterator ait = emt.getAttributes().iterator(); ait.hasNext();) {</FONT>
<BR><FONT SIZE=2> Attribute att = (Attribute)ait.next();</FONT>
<BR><FONT SIZE=2> if (att.getNamespace().equals(from) && !att.getNamespace().equals(to)) {</FONT>
<BR><FONT SIZE=2> att.setNamespace(to);</FONT>
<BR><FONT SIZE=2> System.out.println(att.getName());</FONT>
<BR><FONT SIZE=2> }</FONT>
<BR><FONT SIZE=2> }</FONT>
<BR><FONT SIZE=2>*/</FONT>
<BR><FONT SIZE=2> if (!ns.equals(to)) {</FONT>
<BR><FONT SIZE=2> emt.setNamespace(to);</FONT>
<BR><FONT SIZE=2> }</FONT>
<BR><FONT SIZE=2> for (Iterator it = emt.getChildren().iterator(); it.hasNext();) {</FONT>
<BR><FONT SIZE=2> changeNamespace((Element)it.next(), from, to);</FONT>
<BR><FONT SIZE=2> }</FONT>
<BR><FONT SIZE=2> return emt</FONT>
<BR><FONT SIZE=2> }</FONT>
</P>
<BR>
<P><FONT SIZE=2>This changes the namespace for the supplied element and all it's children with the same namespace.</FONT>
</P>
<P><FONT SIZE=2>Rolf</FONT>
</P>
<P><FONT SIZE=2>-----Original Message-----</FONT>
<BR><FONT SIZE=2>From: Stephan Trebels [<A HREF="mailto:stephan@ncube.de">mailto:stephan@ncube.de</A>]</FONT>
<BR><FONT SIZE=2>Sent: Friday, March 14, 2003 11:20 AM</FONT>
<BR><FONT SIZE=2>To: Elliotte Rusty Harold</FONT>
<BR><FONT SIZE=2>Cc: Stephan Trebels; JDOM</FONT>
<BR><FONT SIZE=2>Subject: Re: [jdom-interest] Is JDOM dying?</FONT>
</P>
<BR>
<P><FONT SIZE=2>Here I am as advocatus diaboli even though I'm nearly sure I'd never use</FONT>
<BR><FONT SIZE=2>it myself ;-/ But alas, this is a technical discussion not a religious</FONT>
<BR><FONT SIZE=2>war - I hope.</FONT>
</P>
<BR>
<P><FONT SIZE=2>disclaimer:</FONT>
<BR><FONT SIZE=2> I'm sure, that normally it makes more sense to use an explicit</FONT>
<BR><FONT SIZE=2> namespace in all Elements. This is definitely true for all my work</FONT>
<BR><FONT SIZE=2> areas where mutable Elements would be a nightmare. This is not in</FONT>
<BR><FONT SIZE=2> question.</FONT>
</P>
<BR>
<P><FONT SIZE=2>But we have to face, that some people want to use Elements differently.</FONT>
<BR><FONT SIZE=2>So I'd ask whether it is possible to make everyone happy without</FONT>
<BR><FONT SIZE=2>sacrificing anything essential.</FONT>
</P>
<P><FONT SIZE=2>In my compromise not a single line of code using JDOM anyone had have</FONT>
<BR><FONT SIZE=2>written would be invalidated or behave any different. The namespace set</FONT>
<BR><FONT SIZE=2>by new Element(String) should not be changed - that should definitely be</FONT>
<BR><FONT SIZE=2>rejected. </FONT>
</P>
<P><FONT SIZE=2>The only added feature would be, that you CAN use a special Namespace</FONT>
<BR><FONT SIZE=2>constant for different _output_ behaviour. The only code changes would</FONT>
<BR><FONT SIZE=2>have to be in the outputters.</FONT>
</P>
<BR>
<P><FONT SIZE=2>So I ask you: Why/How would this make the API any uglier? The API isn't</FONT>
<BR><FONT SIZE=2>changed a bit. The only way to get the changed behaviour would be to</FONT>
<BR><FONT SIZE=2>use a static constant in the Namespace class, which can be documented</FONT>
<BR><FONT SIZE=2>"for special applications, only". It shouldn't even be documented in a</FONT>
<BR><FONT SIZE=2>user's guide (this would be something for a special addendum in the</FONT>
<BR><FONT SIZE=2>reference). </FONT>
</P>
<BR>
<P><FONT SIZE=2>My personal opinion about an API is, that it should be easy to use and</FONT>
<BR><FONT SIZE=2>easy to learn, agreed. Not all tasks need to be available in the</FONT>
<BR><FONT SIZE=2>entry-level API, but ultimately all possible tasks should be made as</FONT>
<BR><FONT SIZE=2>easy as possible.</FONT>
</P>
<P><FONT SIZE=2>Stephan</FONT>
</P>
<P><FONT SIZE=2>On Fri, 2003-03-14 at 13:46, Elliotte Rusty Harold wrote:</FONT>
<BR><FONT SIZE=2>> At 8:56 AM +0100 3/14/03, Stephan Trebels wrote:</FONT>
<BR><FONT SIZE=2>> >Would it be a workable compromise to have a Namespace.INHERIT for an</FONT>
<BR><FONT SIZE=2>> >Element as a possible namespace argument?</FONT>
<BR><FONT SIZE=2>> </FONT>
<BR><FONT SIZE=2>> I wouldn't accept such a compromise. It's ugly. Right now the JDOM </FONT>
<BR><FONT SIZE=2>> namespace story is clean and consistent. This proposal says it </FONT>
<BR><FONT SIZE=2>> changes depending on whether or not you set Namespace.INHERIT. Too </FONT>
<BR><FONT SIZE=2>> many options just create a baroque API that's hard to learn, hard to </FONT>
<BR><FONT SIZE=2>> teach, and hard to use. Generally when faced with two possible ways </FONT>
<BR><FONT SIZE=2>> of accomplishing something, it's better to pick one than to pick both.</FONT>
<BR><FONT SIZE=2>-- </FONT>
<BR><FONT SIZE=2> Stephan Trebels <stephan@ncube.de> Consultant</FONT>
<BR><FONT SIZE=2>company: nCUBE Deutschland GmbH, Hanauer Str. 56, 80992 Munich, Germany</FONT>
<BR><FONT SIZE=2>phone: cell:+49 172 8433111 office:+49 89 1498930 fax:+49 89 14989350</FONT>
</P>
<BR>
<P><FONT SIZE=2>_______________________________________________</FONT>
<BR><FONT SIZE=2>To control your jdom-interest membership:</FONT>
<BR><FONT SIZE=2><A HREF="http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhost.com" TARGET="_blank">http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhost.com</A></FONT>
</P>
</BODY>
</HTML>