You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by Gary L Peskin <ga...@firstech.com> on 2000/09/29 02:35:17 UTC

XalanJ2 Extension Function Mechanism [3 of 3]

Continued from part 2

Finally, a short note about caching.  The current implementation caches
the Method object when it finally locates the correct one.  Since the
types of the arguments to a function could change from invocation to
invocation, the best method is only determined for the first
invocation.  If a subsequent invocation is compatible with the cached
method, then the cached method will be invoked even if it is not the
best method.

For example, 

  <xsl:template match="/">
    <xsl:call-template name="foo">
      <xsl:with-param name="my-param" select="/a/b"/>
    </xsl:call-template>
    <xsl:call-template name="foo">
      <xsl:with-param name="my-param" select="3.0"/>
    </xsl:call-template>
  </xsl:template>

  <xsl:template name="foo">
    <xsl:param name="my-param"/>
    <xsl:copy-of select="java:Bar.zorch($my-param)"/>
  </xsl:template>

And the class:

  public class Bar {
    public static NodeSet zorch(Object obj1) {...}
    public static NodeSet zorch(double double1) {...}
  }

The first time through the zorch(Object) method will be selected and
cached because we are dealing with a node-set.  Since this will also
work for the second invocation of zorch, it will be used even though
zorch(double) is the better method because less conversion of parameters
is required.

I think the current standard is pretty much silent on this but is
something we should be aware of and document.

Gary