1
14
15 package com.liferay.portal.scripting.ruby;
16
17 import org.jruby.Ruby;
18 import org.jruby.javasupport.Java;
19 import org.jruby.javasupport.JavaObject;
20 import org.jruby.javasupport.JavaUtil;
21 import org.jruby.runtime.Block;
22 import org.jruby.runtime.IAccessor;
23 import org.jruby.runtime.builtin.IRubyObject;
24
25
30 class BeanGlobalVariable implements IAccessor {
31
32 public BeanGlobalVariable(Ruby ruby, Object bean, Class<?> type) {
33 _ruby = ruby;
34 _bean = bean;
35 _type = type;
36 }
37
38 public IRubyObject getValue() {
39 IRubyObject value = JavaUtil.convertJavaToRuby(
40 _ruby, _bean, _type);
41
42 if (value instanceof JavaObject) {
43 return Java.wrap(_ruby, value);
44 }
45 else {
46 return value;
47 }
48 }
49
50 public IRubyObject setValue(IRubyObject value) {
51 Object bean = Java.ruby_to_java(
52 _ruby.getObject(), value, Block.NULL_BLOCK);
53
54 _bean = JavaUtil.convertArgument(_ruby, bean, _type);
55
56 return value;
57 }
58
59 private Object _bean;
60 private Ruby _ruby;
61 private Class<?> _type;
62
63 }