Discussion:
[jruby-user] Problems with getValue
r***@L-3com.com
2014-04-09 03:10:23 UTC
Permalink
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
***@L-3com.com



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

http://xircles.codehaus.org/manage_email
Thomas E Enebo
2014-04-09 13:37:12 UTC
Permalink
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
Post by r***@L-3com.com
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
$ 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
---------------------------------------------------------------------
http://xircles.codehaus.org/manage_email
--
blog: http://blog.enebo.com twitter: tom_enebo
mail: ***@gmail.com
Keith Bennett
2014-04-09 14:20:04 UTC
Permalink
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
Post by Thomas E Enebo
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
Post by r***@L-3com.com
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
$ 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
---------------------------------------------------------------------
http://xircles.codehaus.org/manage_email
--
blog: http://blog.enebo.com twitter: tom_enebo
Keith Bennett
2014-04-09 14:26:52 UTC
Permalink
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_19/javax/swing/TransferHandler.TransferAction.htmlsays
that TransferAction is an inner class of TransferHandler.

- Keith
Post by Keith Bennett
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
Post by Thomas E Enebo
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
Post by r***@L-3com.com
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
$ 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
---------------------------------------------------------------------
http://xircles.codehaus.org/manage_email
--
blog: http://blog.enebo.com twitter: tom_enebo
Thomas E Enebo
2014-04-09 14:44:23 UTC
Permalink
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
Post by Keith Bennett
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_19/javax/swing/TransferHandler.TransferAction.htmlsays that TransferAction is an inner class of TransferHandler.
- Keith
Post by Keith Bennett
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
Post by Thomas E Enebo
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
Post by r***@L-3com.com
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
$ 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
---------------------------------------------------------------------
http://xircles.codehaus.org/manage_email
--
blog: http://blog.enebo.com twitter: tom_enebo
--
blog: http://blog.enebo.com twitter: tom_enebo
mail: ***@gmail.com
r***@L-3com.com
2014-04-09 16:35:32 UTC
Permalink
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:***@gmail.com]
Sent: Wednesday, April 09, 2014 7:37 AM
To: ***@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, <***@l-3com.com<mailto:***@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
***@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: ***@gmail.com<mailto:***@gmail.com>
Thomas E Enebo
2014-04-09 17:42:18 UTC
Permalink
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
Post by r***@L-3com.com
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
*Sent:* Wednesday, April 09, 2014 7:37 AM
*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
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
$ 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
---------------------------------------------------------------------
http://xircles.codehaus.org/manage_email
--
blog: http://blog.enebo.com twitter: tom_enebo
--
blog: http://blog.enebo.com twitter: tom_enebo
mail: ***@gmail.com
r***@L-3com.com
2014-04-09 21:54:22 UTC
Permalink
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:***@gmail.com]
Sent: Wednesday, April 09, 2014 11:42 AM
To: ***@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, <***@l-3com.com<mailto:***@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:***@gmail.com<mailto:***@gmail.com>]
Sent: Wednesday, April 09, 2014 7:37 AM
To: ***@jruby.codehaus.org<mailto:***@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, <***@l-3com.com<mailto:***@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
***@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: ***@gmail.com<mailto:***@gmail.com>



--
blog: http://blog.enebo.com twitter: tom_enebo
mail: ***@gmail.com<mailto:***@gmail.com>

Loading...