[jdom-interest] JDOM && Jaxen

bob mcwhirter bob at werken.com
Wed Aug 1 12:13:17 PDT 2001


On Wed, 1 Aug 2001, Jason Hunter wrote:

> bob mcwhirter wrote:
> > 
> > Yah, even without getParent(), though, not using flyweights on the
> > Namespaces would help.
> 
> Really, why?

<foo>
	<bar xmlns:cheese="http://cheese.org/"/>
	<bar xmlns:cheese="http://cheese.org/"/>
</foo>

This document has 2 namespace nodes, but that's represented
in JDOM as only a single Namespace object, due to fly-weighting.

Thus, this xpath

	count(//namespace::*)

should return 2, but for JDOM, only returns 1.

> > In a given document, how many times do you typically see the exactly
> > same namespace decl?  Is it worth the overhead of flyweighting them?
> 
> JDOM stores namespaces in each element (so when they move they keep
> their namespace).  This means it's not just the decls that matter. 
> Imagine a namespace-aware document with 10,000 elements in 3
> namespaces... With the current model you'll have 3 Namespace instances. 
> With a non-flyweight you'll have between 3 and 10,000 depending on
> usage.  And with a non-flyweight with parents, you'll for sure have
> 10,000.  The reason the middle choice varies is that if the builder
> (class or programmer) is at all smart, they can reuse namespace
> instances with a private factory instead of the public one used now.  If
> parentage must be retained, no reuse is possible.

I guess it's the difference between namespace-attached-to-element and
namespace-decl.  I'm seeking out the decls, where the number of decls
in the document is equal to the number of objects located by the
xpath //namespace::*.

	-bob




More information about the jdom-interest mailing list