SEARCH
0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Prev | Current Page 261 | Next

Ola Bini

"Practical JRuby on Rails Web 2.0 Projects: Bringing Ruby on Rails to Java"

You then create a new load path list,
and initialize JRuby??™s load service with this. After you??™ve done that, you can finally do the
equivalent of "require 'bb_engine'", and then get a handle on the BBEngine class.
The destruct method just closes your out stream and removes the reference to the Ruby
engine.
The only thing missing at this point is the invoke method, and it should look like this:
public Object invoke(String uid, String cred, String methodName, String argument) {
try {
IRubyObject u, p, m, a;
if(uid != null) {
u = engine.newString(uid);
} else {
u = engine.getNil();
CHAPTER 9 ?–  A JRUBY ENTERPRISE BEAN 177
}
if(cred != null) {
p = engine.newString(cred);
} else {
p = engine.getNil();
}
if(methodName != null) {
m = engine.newString(methodName);
} else {
m = engine.getNil();
}
if(argument != null) {
a = engine.newString(argument);
} else {
a = engine.getNil();
}
IRubyObject inst = engineClass.callMethod(
engine.getCurrentContext(),"new", new IRubyObject[]{u,p,m});
IRubyObject res = inst.callMethod(
engine.getCurrentContext(),"invoke", a);
if(res instanceof RubyString) {
return res.toString();
} else if(res.isNil()) {
return null;
} else if(res instanceof RubyArray) {
List arr = new ArrayList();
for(Iterator iter = ((RubyArray)res).iterator();iter.hasNext();) {
arr.add(iter.next());
}
return arr;
}
return res.toString();
} catch(RaiseException re) {
RubyException rr = re.getException();
if(rr != null) {
out.


Pages:
249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273