You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-users@xalan.apache.org by Juergen Hermann <jh...@web.de> on 2003/03/25 19:49:05 UTC

RE: returning xml nodes from extensions functions

On Sun, 2 Feb 2003 05:02:20 -0000, Mark Weaver wrote:

>class XalanDynamicBuilder

Mark / David, can you tell us something about the status of this class. 
Was it added to the 1.5 release code freeze?


Ciao, Jürgen



RE: returning xml nodes from extensions functions

Posted by Mark Weaver <ma...@npsl.co.uk>.
> Here is a CVS diff against the latest (intended to go into the 
> 1.6 dev try).  

With brain on...

RE: returning xml nodes from extensions functions

Posted by Mark Weaver <ma...@npsl.co.uk>.
Here is a CVS diff against the latest (intended to go into the 1.6 dev try).
To apply unzip to src which will put new files in the right place and apply
the patch.  For project files, the additional files (XSLT/XalanDynamic*)
need to be added; I don't have VC6 installed otherwise I'd do this.

I'll do another one against the final release if it changes owt else.

My comments/questions from the original patch are below.

Mark

Hi David,

OK, I finally something for you to look at.  This is a patch against the
Xalan 1.4 release to add support for returning nodesets and result tree
fragments from extension functions.  The hacked up ExternalFunction sample
shows how this works.  Roughly, things are as discussed, but I'll go through
it from the top for completeness.  I've chopped out code to make the
explanations shorter, so look at the patch for the details.

Firstly, to dynamically building trees or fragments, we provide objects that
gives access to the SAX2 interfaces.  The basic functionality whether you
are building a tree or a fragment is the same, and this is reflected in the
class XalanDynamicBuilder:

class XalanDynamicBuilder
{
public:
	XalanDynamicBuilder(StylesheetExecutionContext& executionContext);
	virtual void reset() = 0;
	virtual ~XalanDynamicBuilder();

	// SAX2 i/fs
	virtual ContentHandler* getContentHandler();
	virtual LexicalHandler*	getLexicalHandler();
	virtual DTDHandler* getDTDHandler();

	// Get an XObject for the nodeset or result tree fragment.  The XObject
adopts the tree.
	virtual XObjectPtr detachXObject() = 0;
};

Then either we are building a result tree fragment, or a nodeset, so we use
the appropriate derived class: XalanDynamicNodeSetBuilder and
XalanDynamicResultTreeFragmentBuilder (I'm trying to win an award for the
longest class name here).  These follow exactly the interface above, with
appropriate overrides to make them do what they should.

Next we need access to these objects.  Since the original idea was to do
this from an extension function, XPathExecutionContext has been extended
with:

	virtual void getObject(XalanDynamicNodeSetBuilder **theBuilder) = 0;
	virtual void releaseObject(XalanDynamicNodeSetBuilder *theBuilder) = 0;
	virtual void getObject(XalanDynamicResultTreeFragmentBuilder **theBuilder)
= 0;
	virtual void releaseObject(XalanDynamicResultTreeFragmentBuilder
*theBuilder) = 0;

These are unimplemented outside of the XSLT subsystem: the
XPathExecutionContextDefault implements return NULL objects, and the
StyleSheetExecutionContextDefault implementations are complete.

It is not intended to use these functions directly (for reasons of guarding
against leakiness), so we have two helper classes,

XPathExecutionContext::GetAndReleaseCachedNodeSetBuilder
XPathExecutionContext::GetAndReleaseCachedResultTreeFragmentBuilder (I'm
going to walk away with the award, surely no-one can compete with that)

These works as for GetAndReleasedCachedString, and are implemented by a
template class, GetAndReleasedCachedObject<T> (hence the odd looking
getObject/releaseObject), and their use can be seen in the modified
ExternalFunction.

That's about it from a high level.  Details and my concerns are:

1. Both of the builder objects manage cleaning up memory by using an
unexposed class for the XObject derived from the standard ones (XNodeSet,
XResultTreeFrag).  In the case of XalanDynamicNodeSetBuilder, this is
XDynamicNodeSet, in the case of XalanDynamicResultTreeFragmentBuilder, this
is XDynamicResultTreeFrag.  Simply, they cache and delete the
document/fragment pointers at appropriate times.  Things I'm unclear on:

XalanDynamicNodeSetBuilder:
	A) Do I need to keep the document hanging around after stuffing it into
XNodeSet using a BorrowReturnMutableNodeRefList?  I seem to remember that I
did, but I'm not quite clear now.  Might it be possible to get the nodeset
copied (e.g. one convoluted way would seem to be to create an XNodeSet, and
create another one copying it with fDeepClone=true).
	B) Do I need to copy the cached document in the copy c'tor?  I am doing so,
but if XNodeSet is cloning/referencing appropriately anyway, it's a pretty
pointless exercise.

XalanDynamicResultTreeFragmentBuilder:
	A) Do I need to copy the cached document/fragment in the copy c'tor?  (I'm
pretty sure in this case I need to look after them in the original
instance.)

2. For building documents, I used XalanSourceTreeContentHandler with the
SAX2 interfaces as prescribed.  This differed from FormatterToSourceTree in
that it does not allow creating a document fragment.  Never one to be
stopped by a lack of understanding of code, I've outfitted
XalanSourceTreeContentHandler with the functionality I needed.  I'm not sure
if I've got this right (or if it's a sane thing to do), but it seems to
work.

3. As I described in my previous mail, it is currently the case that an
XPathExecutionContextDefault implementation rather than the
StyleSheetExecutionContextDefault is passed on to extension functions.  I'm
not quite clear on how to do what you described, so I've addressed this by
adding a hack to XPathExecutionContextDefault that allows returning the
embedded XPathEnvSupport:

       XPathEnvSupport *getXPathEnvSupport() { return m_xpathEnvSupport; }

(Probably ought to be const as well).  Next I changed the external function
call in StyleSheetExecutionContextDefault to:
	return
m_xpathExecutionContextDefault.getXPathEnvSupport()->extFunction(*this,
theNamespace, functionName, context, argVec, locator);
from:
	return m_xpathExecutionContextDefault.extFunction(theNamespace,
functionName, context, argVec, locator);

This does the right thing, but probably not in the right way.

4. We had a thought that the nested class template might not work; I'm not
sure what the characteristics of the various platforms Xalan supports are so
I can't really comment on that.  It works fine in VC7, which is all I've got
available for testing right now.  If there is a problem, then most compilers
cease complaining if you move the template outside of the class, which is
not as tidy but I feel is an acceptable compromise.

5. Things that are left TODO are: bring up to date with current CVS (I
wanted to get the broad details OK'd before I did this -- I will do so
though); fix up makefiles and projects; update whatever documentation needs
to be updated.

Let me know what needs to be done, and I'll get on it.

> -----Original Message-----
> From: David N Bertoni/Cambridge/IBM [mailto:david_n_bertoni@us.ibm.com]
> Sent: 25 March 2003 19:15
> To: xalan-c-users@xml.apache.org
> Subject: RE: returning xml nodes from extensions functions
>
>
>
>
>
>
> Hi Jürgen,
>
> No, this did not make it in.
>
> Dave
>
>
>
>
>
>                       "Juergen
>
>                       Hermann"                 To:      "Mark
> Weaver" <ma...@npsl.co.uk>, "Xalan-C-Users"
>                       <jh...@web.de>
> <xa...@xml.apache.org>
>
>                       Sent by:                 cc:      (bcc:
> David N Bertoni/Cambridge/IBM)
>                       jh@web.de                Subject: RE:
> returning xml nodes from extensions functions
>
>
>
>
>                       03/25/2003 10:49
>
>                       AM
>
>
>
>
>
>
> On Sun, 2 Feb 2003 05:02:20 -0000, Mark Weaver wrote:
>
> >class XalanDynamicBuilder
>
> Mark / David, can you tell us something about the status of this class.
> Was it added to the 1.5 release code freeze?
>
>
> Ciao, Jürgen
>
>
>
>
>
>


RE: returning xml nodes from extensions functions

Posted by David N Bertoni/Cambridge/IBM <da...@us.ibm.com>.



Hi Jürgen,

No, this did not make it in.

Dave



                                                                                                                           
                      "Juergen                                                                                             
                      Hermann"                 To:      "Mark Weaver" <ma...@npsl.co.uk>, "Xalan-C-Users"                   
                      <jh...@web.de>              <xa...@xml.apache.org>                                              
                      Sent by:                 cc:      (bcc: David N Bertoni/Cambridge/IBM)                               
                      jh@web.de                Subject: RE: returning xml nodes from extensions functions                  
                                                                                                                           
                                                                                                                           
                      03/25/2003 10:49                                                                                     
                      AM                                                                                                   
                                                                                                                           



On Sun, 2 Feb 2003 05:02:20 -0000, Mark Weaver wrote:

>class XalanDynamicBuilder

Mark / David, can you tell us something about the status of this class.
Was it added to the 1.5 release code freeze?


Ciao, Jürgen