-
Notifications
You must be signed in to change notification settings - Fork 0
/
SimpleImplementation.java
80 lines (67 loc) · 2.91 KB
/
SimpleImplementation.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import org.jruby.Ruby;
import org.jruby.RubyObject;
import org.jruby.javasupport.util.RuntimeHelpers;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.javasupport.JavaUtil;
import org.jruby.RubyClass;
import simplejavainterface.SimpleJavaInterface;
public class SimpleImplementation extends RubyObject implements SimpleJavaInterface {
private static final Ruby __ruby__ = Ruby.getGlobalRuntime();
private static final RubyClass __metaclass__;
static {
String source = new StringBuilder("require 'java'\n" +
"\n" +
"java_import \"simplejavainterface.SimpleJavaInterface\"\n" +
"\n" +
"class SimpleImplementation\n" +
" java_implements Java::simplejavainterface.SimpleJavaInterface\n" +
" \n" +
" java_signature 'void testingMehthod()'\n" +
" def testingMethod()\n" +
" p \"testing method implemented in JRuby\"\n" +
" end\n" +
"end\n" +
"").toString();
__ruby__.executeScript(source, "SimpleImplementation.rb");
RubyClass metaclass = __ruby__.getClass("SimpleImplementation");
metaclass.setRubyStaticAllocator(SimpleImplementation.class);
if (metaclass == null) throw new NoClassDefFoundError("Could not load Ruby class: SimpleImplementation");
__metaclass__ = metaclass;
}
/**
* Standard Ruby object constructor, for construction-from-Ruby purposes.
* Generally not for user consumption.
*
* @param ruby The JRuby instance this object will belong to
* @param metaclass The RubyClass representing the Ruby class of this object
*/
private SimpleImplementation(Ruby ruby, RubyClass metaclass) {
super(ruby, metaclass);
}
/**
* A static method used by JRuby for allocating instances of this object
* from Ruby. Generally not for user comsumption.
*
* @param ruby The JRuby instance this object will belong to
* @param metaclass The RubyClass representing the Ruby class of this object
*/
public static IRubyObject __allocate__(Ruby ruby, RubyClass metaClass) {
return new SimpleImplementation(ruby, metaClass);
}
/**
* Default constructor. Invokes this(Ruby, RubyClass) with the classloader-static
* Ruby and RubyClass instances assocated with this class, and then invokes the
* no-argument 'initialize' method in Ruby.
*
* @param ruby The JRuby instance this object will belong to
* @param metaclass The RubyClass representing the Ruby class of this object
*/
public SimpleImplementation() {
this(__ruby__, __metaclass__);
RuntimeHelpers.invoke(__ruby__.getCurrentContext(), this, "initialize");
}
public void testingMehthod() {
IRubyObject ruby_result = RuntimeHelpers.invoke(__ruby__.getCurrentContext(), this, "testingMethod");
return;
}
}