<octave-dev ML added in To:>
[email protected] wrote:
> Hello Philip,
> <snip>
In terms of methods I always used the object.method (dot) notation.
Same here, but sometimes I didn't know how to avoid javaMethod /
java_invoke, usually when Java objects/classes have no explicit
constructor but only a method "createSomething()". Especially JExcelAPI
(for Excel I/O) has lots of these.
> It surely would be good if you could repair this bug. I think I did simply
> copy the existing java_invoke method and renamed the copy javaMethod. I had
> planned to revise this later so that javaMethod just calls java_invoke. This
> would remove the duplication of code. The same duplication edists for
> java_new and javaObject.
I had a look.
Currently it is beyond me, but I'll gaze /stare at the code some more
and I'm sure then at some moment enlightenment will come automagically :-)
Well, at least, that's the way it often worked for me.
But just to be sure, I'll copy the part of __java__.cc below for hints.
Fixing the doc string is a breeze (I'll do that later), fixing the
argument order seems more involved... See my proposed # Change into....#
?? commments. Do you think these changes would be OK?
<snip>
> I also see that javaMethod in Matlab can be used in two ways to call static
> as well as instance methods. Not sure whether the javaMethod in Octave can
> handle these two variants.
I used java_invoke on both classes and objects and that worked OK.
BTW as regards Matlab's info (quoted below):
I think Octave is a bit better than the competition as it seems to not
have that stupid 31-chars limit on methods - in the ODS R/W scripts for
ODF toolkit I've used several methods directly (w/o java_invoke) with
ridiculously long names, e.g. 'setTableNumberColumnsRepeatedAttribute'
(38 chars), 'getTableNumberMatrixColumnsSpannedAttribute' (43) or even
'getTableProtectionKeyDigestAlgorithmAttribute' (45!), all of these Just
Work.
Greetz, & see below for __java__.cc stanza
Philip
> Thank you for spotting this and best regards,
<snip>
<QUOTE>
> ################### Matlab 2009b online help
<snip>
> javaMethod('MethodName','ClassName',x1,...,xn) calls the static method
> MethodName in the class ClassName, with the argument list x1,...,xn.
> javaMethod('MethodName',J,x1,...,xn) calls the nonstatic method MethodName on
> the object J, with the argument list x1,...,xn.
> Remarks
> Use the javaMethod function to:
> *
> Use methods having names longer than 31 characters.
> *
> Specify the method you want to invoke at run-time, for example, as
> input from an application user.
> The javaMethod function enables you to use methods having names longer than
> 31 characters. This is the only way you can invoke such a method in the
> MATLAB software. For example:
</QUOTE>
<snip>
__java__.cc stanza, watch out for line wrap:
DEFUN_DLD (javaMethod, args, ,
"-*- texinfo -*-\n\
@deftypefn {Loadable Function} {...@var{ret} =} javaMethod (@var{obj},
@var{name}, @var{arg1}, ...)\n\
Invoke the method @var{name} on the Java object @var{obj} with the
arguments\n\
@var{arg1}, ... For static methods, @var{obj} can be a string
representing the\n\
fully qualified name of the corresponding class. The function returns
the result\n\
of the method invocation.\n\
\n\
When @var{obj} is a regular Java object, the structure-like indexing can
be used\n\
as a shortcut syntax. For instance, the two following statements are
equivalent\n\
\n\
@example\n\
ret = javaMethod (x, \"method1\", 1.0, \"a string\")\n\
ret = x.method1 (1.0, \"a string\")\n\
@end example\n\
\n\
@seealso{java_get, java_set, java_new}\n\
@end deftypefn")
{
octave_value retval;
initialize_java ();
if (! error_state)
{
JNIEnv *current_env = octave_java::thread_jni_env ();
if (args.length() > 1)
{
std::string name = args(1).string_value ();
# Change into
# std::string name = args(0).string_value ();
# ??
if (! error_state)
{
octave_value_list tmp;
for (int i=2; i<args.length (); i++)
tmp(i-2) = args(i);
if (args(0).class_name () == "octave_java")
# Change into
# if (args(1).class_name () == "octave_java")
# ??
{
octave_java *jobj = TO_JAVA (args(0));
# Change into
# octave_java *jobj = TO_JAVA (args(1));
# ??
retval = jobj->do_java_invoke (current_env, name, tmp);
}
else if (args(0).is_string ())
# Change into
# else if (args(1).is_string ())
# ??
{
std::string cls = args(0).string_value ();
# Change into
# std::string cls = args(1).string_value ();
# ??
retval = octave_java::do_java_invoke (current_env,
cls, name, tmp);
}
else
error ("javaMethod: first argument must be a Java
object or a string");
}
else
error ("javaMethod: second argument must be a string");
# Change into
# error ("javaMethod: first argument must be a string");
# ??
}
else
print_usage ();
}
return retval;
}
------------------------------------------------------------------------------
Nokia and AT&T present the 2010 Calling All Innovators-North America contest
Create new apps & games for the Nokia N8 for consumers in U.S. and Canada
$10 million total in prizes - $4M cash, 500 devices, nearly $6M in marketing
Develop with Nokia Qt SDK, Web Runtime, or Java and Publish to Ovi Store
http://p.sf.net/sfu/nokia-dev2dev
_______________________________________________
Octave-dev mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/octave-dev