[ 
https://issues.apache.org/jira/browse/XALANJ-1847?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Martin von Gagern updated XALANJ-1847:
--------------------------------------

    Attachment: ExtTest1.zip
                XALANJ-1847a.patch

I propose the attached patch to solve this issue.

The issue mostly concerns the class namespace format. The reason for this is 
that in the other namespace formats, the class to search for methods has to be 
determined from the "this" argument, and such type information is not available 
for references. It could be implemented inefficiently via reflection at runtime 
in the long run, but we'll better skip this for now.

With the class namespace format, we cannot tell by looking at the function name 
whether we are dealing with a static or an instance method. The best 
information in this respect probably comes from the class itself. The patch 
modifies the method search to return all public method with matching name, 
without regard for argument count. typeCheckExternal then does a case 
distinction: either it's a static method matching all parameters, or it's an 
instance method with the first argument of a suitable type (either assignable 
object type or reference type) and the rest or the arguments matching the 
method parameters. The "this" argument is removed from the list of all 
arguments only after a method has been chosen.

The patch also fixes what seems to be an error with the return type during 
method selection, where a method with a higher distance might override the 
return type of the expression without actually getting chosen. Haven't written 
a test case exposing this issue yet. If you absolutely need it, I can do so.

When the "this" argument is of reference type, it has to be cast to the target 
type. To do so, reference types have to be castable in the first place. I'm a 
bit worried about all those special cases in ReferenceType.translateTo, so I 
wouldn't be surprised if working on classes that are also used to express xslt 
data types might cause trouble.

I made no real attempt to fit my indentation scheme to the code around it, as 
the whole source file is completely mixed as to indentation levels and the use 
of tabs. I suggest reinenting it as a whole one of these days.

It might be that allowing references to be cast to anything might cause trouble 
in other parts of the code. I would assume that the Java VM should catch most 
of those, though. Having castable reference types solved another issue for me, 
where I tried to pass them not as "this" but as arguments to extension 
functions.

The attached test case exhibits many of these issues. I take the fact that it 
works on my build as a good indication that my patch is at least going in the 
right direction. I havn't integrated it into the test framework, as that 
completely fails for me in any case, and I don't want to dig too deeply into 
that.

> Transform.setParameter doesn't function as an extension mecanism
> ----------------------------------------------------------------
>
>                 Key: XALANJ-1847
>                 URL: https://issues.apache.org/jira/browse/XALANJ-1847
>             Project: XalanJ2
>          Issue Type: Bug
>      Security Level: No security risk; visible to anyone(Ordinary problems in 
> Xalan projects.  Anybody can view the issue.) 
>          Components: Xalan-extensions
>    Affects Versions: 2.6
>         Environment: Operating System: All
> Platform: All
>            Reporter: François Lemaire
>            Assignee: Xalan Developers Mailing List
>         Attachments: ExtTest1.zip, XALANJ-1847a.patch
>
>
> I don't know if that can be called a bug or if it is a proposed extension, 
> but 
> this bothers me. I've tried to do pass an object by calling 
> myTransformer.setParameter, then in my stylesheet call a method defined in my 
> object, but I got a NoSuchMethodError telling me that my method didn't exist 
> in 
> java.lang.String. My guess is that params are transformed into String objects 
> before being passed to the stylesheet. It's annoying, because I'd like to 
> pass 
> an extension object to the stylesheet from my java code rather than having 
> package and class names written in the stylesheet; if I want to change the 
> implementation of the interface implemented by my object (which is an URL 
> rewriting helper), I have to change package and function names everywhere in 
> my 
> stylesheets!

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to