Forum: JRuby Problems with getValue

2a11c93e55ef1e3bcca56c7f2d5e011d?d=identicon&s=25 unknown (Guest)
on 2014-04-09 05:11
(Received via mailing list)
I can't figure out what I'm doing wrong here.  The Java code works.  All
the Ruby permutations return nil.  How can I get the names I want?

Thanks!


=== deleteme.java ===
import java.io.*;
import javax.swing.*;

class Deleteme {
    public static void main(String args[]) throws IOException {
        String str;
        str =
(String)TransferHandler.getCutAction().getValue(Action.NAME);
        System.out.println("Cut action name is: " + str);
        str =
(String)TransferHandler.getCopyAction().getValue(Action.NAME);
        System.out.println("Copy action name is: " + str);
        str =
(String)TransferHandler.getPasteAction().getValue(Action.NAME);
        System.out.println("Paste action name is: " + str);
    }
}
=== END deleteme.java ===

$ javac deleteme.java
$ java Deleteme
Cut action name is: cut
Copy action name is: copy
Paste action name is: paste



=== deleteme.rb ===
require 'java'

# Easier way to do this at file scope?  Normally I would just
include_package
# 'javax.swing' in my class.
java_import javax.swing.TransferHandler
java_import javax.swing.Action


name = TransferHandler.getCutAction.getValue(Action.NAME)
puts "Cut action name is: #{name}"
name = TransferHandler.getCopyAction.getValue(Action.NAME)
puts "Copy action name is: #{name}"
name = TransferHandler.getPasteAction.getValue(Action.NAME)
puts "Paste action name is: #{name}"

# try really hard
action = TransferHandler.getCutAction
name = action.java_send(:getValue, [java.lang.String], Action.NAME)
puts "Cut action #{action.inspect} name is: #{name}"

# try another way; doesn't work because getValue takes an argument
#name = TransferHandler.getCutAction.value(Action.NAME)
#puts "Cut action name is: #{name}"

# try another way
meth = action.java_method(:getValue, [java.lang.String])
puts "Cut action name is: #{meth.call(Action.NAME)}"
puts "Cut action name is: #{meth.call(Action.NAME.to_java)}"
=== END deleteme.rb ===

$ jruby deleteme.rb
Cut action name is:
Copy action name is:
Paste action name is:
Cut action #<Java::JavaxSwing::TransferAction:0x7548c02f> name is:
Cut action name is:
Cut action name is:
$ jruby --version
jruby 1.7.4 (1.9.3p392) 2013-05-16 2390d3b on OpenJDK 64-Bit Server VM
1.6.0_22-b22 [linux-amd64]

C:\...> jruby deleteme.rb
[all names still nil]
C:\...> jruby --version
jruby 1.7.10 (1.9.3p392) 2014-01-09 c4ecd6b on Java HotSpot(TM) Client
VM 1.6.0_37-b06 [Windows 7-x86]


---
Ryan Hinton
L-3 Communications / Communication Systems West
ryan.w.hinton@L-3com.com
13313ac2ec7ba7c43b1b952db034ff3b?d=identicon&s=25 Thomas E Enebo (Guest)
on 2014-04-09 15:47
(Received via mailing list)
wow.  Can you report this as an issue on our github project?  I can
confirm
this does not work.  My guess is getValue is public in the interface but
non-public in the concrete class of TransferAction.  We actually use
reflection to get around these odd cases so I don't understand why this
is
not working.

-Tom
486ca04f06d968004643ce5b47376ded?d=identicon&s=25 Keith B. (keith_b)
on 2014-04-09 16:21
(Received via mailing list)
Yeah, this is really interesting.  I wrote a test script at
https://gist.github.com/keithrbennett/10275705 that also illustrates
that
the Action's method names are not rubified, i.e. getValue cannot be
accessed as value. I got the same result in JRuby 1.7.1 and 1.7.9.

- Keith
486ca04f06d968004643ce5b47376ded?d=identicon&s=25 Keith B. (keith_b)
on 2014-04-09 16:29
(Received via mailing list)
Might it be an issue with JRuby's handling of inner classes in Java?

JRuby reports that the action is an instance
ofJava::JavaxSwing::TransferAction,
whereas a web page at
http://www.cs.rit.edu/usr/local/pub/swm/jdoc1.6.0_...
that TransferAction is an inner class of TransferHandler.

- Keith
13313ac2ec7ba7c43b1b952db034ff3b?d=identicon&s=25 Thomas E Enebo (Guest)
on 2014-04-09 16:46
(Received via mailing list)
Yeah, it could be something to do with the inner class relationship too.
Amazed we have not seen this one before.  Lots of a folks have done
Swing
stuff using JRuby.

-Tom
2a11c93e55ef1e3bcca56c7f2d5e011d?d=identicon&s=25 unknown (Guest)
on 2014-04-09 18:40
(Received via mailing list)
I tried to report it on GitHub yesterday, but the buttons weren't
working.  I suspect the corporate firewall/mandated browser are to
blame.  I'll try tonight from home unless someone beats me to it.

Is there any way I can work around it for now (besides writing Java code
:-)?

- Ryan

From: Thomas E Enebo [mailto:tom.enebo@gmail.com]
Sent: Wednesday, April 09, 2014 7:37 AM
To: user@jruby.codehaus.org
Subject: Re: [jruby-user] Problems with getValue

wow.  Can you report this as an issue on our github project?  I can
confirm this does not work.  My guess is getValue is public in the
interface but non-public in the concrete class of TransferAction.  We
actually use reflection to get around these odd cases so I don't
understand why this is not working.
-Tom

On Tue, Apr 8, 2014 at 10:10 PM,
<ryan.w.hinton@l-3com.com<mailto:ryan.w.hinton@l-3com.com>> wrote:
I can't figure out what I'm doing wrong here.  The Java code works.  All
the Ruby permutations return nil.  How can I get the names I want?

Thanks!


=== deleteme.java ===
import java.io.*;
import javax.swing.*;

class Deleteme {
    public static void main(String args[]) throws IOException {
        String str;
        str =
(String)TransferHandler.getCutAction().getValue(Action.NAME);
        System.out.println("Cut action name is: " + str);
        str =
(String)TransferHandler.getCopyAction().getValue(Action.NAME);
        System.out.println("Copy action name is: " + str);
        str =
(String)TransferHandler.getPasteAction().getValue(Action.NAME);
        System.out.println("Paste action name is: " + str);
    }
}
=== END deleteme.java ===

$ javac deleteme.java
$ java Deleteme
Cut action name is: cut
Copy action name is: copy
Paste action name is: paste



=== deleteme.rb ===
require 'java'

# Easier way to do this at file scope?  Normally I would just
include_package
# 'javax.swing' in my class.
java_import javax.swing.TransferHandler
java_import javax.swing.Action


name = TransferHandler.getCutAction.getValue(Action.NAME)
puts "Cut action name is: #{name}"
name = TransferHandler.getCopyAction.getValue(Action.NAME)
puts "Copy action name is: #{name}"
name = TransferHandler.getPasteAction.getValue(Action.NAME)
puts "Paste action name is: #{name}"

# try really hard
action = TransferHandler.getCutAction
name = action.java_send(:getValue, [java.lang.String], Action.NAME)
puts "Cut action #{action.inspect} name is: #{name}"

# try another way; doesn't work because getValue takes an argument
#name = TransferHandler.getCutAction.value(Action.NAME)
#puts "Cut action name is: #{name}"

# try another way
meth = action.java_method(:getValue, [java.lang.String])
puts "Cut action name is: #{meth.call(Action.NAME)}"
puts "Cut action name is: #{meth.call(Action.NAME.to_java)}"
=== END deleteme.rb ===

$ jruby deleteme.rb
Cut action name is:
Copy action name is:
Paste action name is:
Cut action #<Java::JavaxSwing::TransferAction:0x7548c02f> name is:
Cut action name is:
Cut action name is:
$ jruby --version
jruby 1.7.4 (1.9.3p392) 2013-05-16 2390d3b on OpenJDK 64-Bit Server VM
1.6.0_22-b22 [linux-amd64]

C:\...> jruby deleteme.rb
[all names still nil]
C:\...> jruby --version
jruby 1.7.10 (1.9.3p392) 2014-01-09 c4ecd6b on Java HotSpot(TM) Client
VM 1.6.0_37-b06 [Windows 7-x86]


---
Ryan Hinton
L-3 Communications / Communication Systems West
ryan.w.hinton@L-3com.com
13313ac2ec7ba7c43b1b952db034ff3b?d=identicon&s=25 Thomas E Enebo (Guest)
on 2014-04-09 19:43
(Received via mailing list)
If you can dig out the java_object from the TransferHandler you should
be
able to use Java reflection APIs + setAccessible.  If you search for
JRuby
setAccessible something might turn up.  It is pretty gruesome workaround
but it should work.

-Tom
2a11c93e55ef1e3bcca56c7f2d5e011d?d=identicon&s=25 unknown (Guest)
on 2014-04-09 23:55
(Received via mailing list)
That does sound gruesome.  I have a less-gruesome (but more evil) hack
implemented right now.  I'll submit the bug report, and hopefully the
hack will last long enough for the bug to be fixed and released.

Thanks!

- Ryan

From: Thomas E Enebo [mailto:tom.enebo@gmail.com]
Sent: Wednesday, April 09, 2014 11:42 AM
To: user@jruby.codehaus.org
Subject: Re: [jruby-user] Problems with getValue

If you can dig out the java_object from the TransferHandler you should
be able to use Java reflection APIs + setAccessible.  If you search for
JRuby setAccessible something might turn up.  It is pretty gruesome
workaround but it should work.
-Tom

On Wed, Apr 9, 2014 at 11:35 AM,
<ryan.w.hinton@l-3com.com<mailto:ryan.w.hinton@l-3com.com>> wrote:
I tried to report it on GitHub yesterday, but the buttons weren't
working.  I suspect the corporate firewall/mandated browser are to
blame.  I'll try tonight from home unless someone beats me to it.

Is there any way I can work around it for now (besides writing Java code
:-)?

- Ryan

From: Thomas E Enebo
[mailto:tom.enebo@gmail.com<mailto:tom.enebo@gmail.com>]
Sent: Wednesday, April 09, 2014 7:37 AM
To: user@jruby.codehaus.org<mailto:user@jruby.codehaus.org>
Subject: Re: [jruby-user] Problems with getValue

wow.  Can you report this as an issue on our github project?  I can
confirm this does not work.  My guess is getValue is public in the
interface but non-public in the concrete class of TransferAction.  We
actually use reflection to get around these odd cases so I don't
understand why this is not working.
-Tom

On Tue, Apr 8, 2014 at 10:10 PM,
<ryan.w.hinton@l-3com.com<mailto:ryan.w.hinton@l-3com.com>> wrote:
I can't figure out what I'm doing wrong here.  The Java code works.  All
the Ruby permutations return nil.  How can I get the names I want?

Thanks!


=== deleteme.java ===
import java.io.*;
import javax.swing.*;

class Deleteme {
    public static void main(String args[]) throws IOException {
        String str;
        str =
(String)TransferHandler.getCutAction().getValue(Action.NAME);
        System.out.println("Cut action name is: " + str);
        str =
(String)TransferHandler.getCopyAction().getValue(Action.NAME);
        System.out.println("Copy action name is: " + str);
        str =
(String)TransferHandler.getPasteAction().getValue(Action.NAME);
        System.out.println("Paste action name is: " + str);
    }
}
=== END deleteme.java ===

$ javac deleteme.java
$ java Deleteme
Cut action name is: cut
Copy action name is: copy
Paste action name is: paste



=== deleteme.rb ===
require 'java'

# Easier way to do this at file scope?  Normally I would just
include_package
# 'javax.swing' in my class.
java_import javax.swing.TransferHandler
java_import javax.swing.Action


name = TransferHandler.getCutAction.getValue(Action.NAME)
puts "Cut action name is: #{name}"
name = TransferHandler.getCopyAction.getValue(Action.NAME)
puts "Copy action name is: #{name}"
name = TransferHandler.getPasteAction.getValue(Action.NAME)
puts "Paste action name is: #{name}"

# try really hard
action = TransferHandler.getCutAction
name = action.java_send(:getValue, [java.lang.String], Action.NAME)
puts "Cut action #{action.inspect} name is: #{name}"

# try another way; doesn't work because getValue takes an argument
#name = TransferHandler.getCutAction.value(Action.NAME)
#puts "Cut action name is: #{name}"

# try another way
meth = action.java_method(:getValue, [java.lang.String])
puts "Cut action name is: #{meth.call(Action.NAME)}"
puts "Cut action name is: #{meth.call(Action.NAME.to_java)}"
=== END deleteme.rb ===

$ jruby deleteme.rb
Cut action name is:
Copy action name is:
Paste action name is:
Cut action #<Java::JavaxSwing::TransferAction:0x7548c02f> name is:
Cut action name is:
Cut action name is:
$ jruby --version
jruby 1.7.4 (1.9.3p392) 2013-05-16 2390d3b on OpenJDK 64-Bit Server VM
1.6.0_22-b22 [linux-amd64]

C:\...> jruby deleteme.rb
[all names still nil]
C:\...> jruby --version
jruby 1.7.10 (1.9.3p392) 2014-01-09 c4ecd6b on Java HotSpot(TM) Client
VM 1.6.0_37-b06 [Windows 7-x86]


---
Ryan Hinton
L-3 Communications / Communication Systems West
ryan.w.hinton@L-3com.com



---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



--
blog: http://blog.enebo.com       twitter: tom_enebo
mail: tom.enebo@gmail.com<mailto:tom.enebo@gmail.com>
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.