This will work almost as shown in the interface implementation I'm working
on. (Note: I've been away from it for a couple of days, will get back to it
in a day or so.) Here's what I'll submit for consideration (open, of
course, to debate/discussion):
1. Current behavior (interfaces as Ruby classes) will be supported, though
(in my eyes, at least) deprecated. Existing code will continue to function
unmodified.
2. Interface modules will be implemented. It will be possible to get the
class version from the module version, and vice versa.
3. When proxies are created for concrete Java classes and inserted into the
Rubified Java class hierarchy, the interface modules for any implemented
interfaces will be included into them (unless they've already been included
in a superclass). This will enable the behavior you're looking for, as well
as kind_of?, (class/module) A < B, etc.
4. Multiple interfaces will be includable into new classes. For original
(non-generated) Java classes, the interfaces will be frozen; it will _not_
be possible to open java.lang.Object and include, say,
java.lang.Runnable(though you can include non-Java modules). For
generated proxies, interfaces
_could_ be frozen after the first instantiation, though I'm not convinced
this is necessary. (I'm open to convincing, of course.)
In your example, the only difference would be defining the execute method in
the Connection _module_, rather than the class:
module Connection::Includable # can come up with a different name if need
be
def execute(query)
...
end
...
end
Some of this is now working in my local JRuby; some is yet to be done. As I
said, I'll be getting back to it in a day or so.
(I've been working on an optimized variant of JavaProxyClass generation;
there's no reason that methods other than those overridden in Ruby should be
generated. It's kind of appalling (and, I believe, the source of some
problems) to see every (non-private) internal method call in, say, a JFrame
subclass routing through __jsend to the JavaProxy callback, everything being
converted to/from Ruby. Even when the user isn't doing anything, as long as
the Swing thread is running, this process churns along.)
Let me know what you think.
-Bill
On 4/25/07, Charles Oliver Nutter <[EMAIL PROTECTED]> wrote:
I was surprised to find out the following code doesn't work. It doesn't
seem to pick up my changes on the Connection class, nor did it work on
ResultSet. Then I remembered they're both interfaces, and so changes
there aren't getting picked up by incoming objects that implement them.
Where do we stand on the best way to do this? I want it.
include Java
import java.sql.Connection
import java.sql.DriverManager
import java.sql.ResultSet
java.lang.Class.for_name("com.mysql.jdbc.Driver")
class Connection
def execute(query)
statement = create_statement
results = statement.execute_query(query)
yield results
ensure
results.close if results
statement.close if statement
end
end
begin
connection =
DriverManager.get_connection
("jdbc:mysql://localhost/mephisto_development",
"mephisto", "mephisto")
connection.execute("select * from users") do |results|
puts results.get_string("email") while results.next
end
ensure
connection.close if connection
end
---------------------------------------------------------------------
To unsubscribe from this list please visit:
http://xircles.codehaus.org/manage_email