| BeanGlobalVariable.java |
1 /**
2 * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3 *
4 * This library is free software; you can redistribute it and/or modify it under
5 * the terms of the GNU Lesser General Public License as published by the Free
6 * Software Foundation; either version 2.1 of the License, or (at your option)
7 * any later version.
8 *
9 * This library is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12 * details.
13 */
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.IAccessor;
22 import org.jruby.runtime.builtin.IRubyObject;
23
24 /**
25 * <a href="BeanGlobalVariable.java.html"><b><i>View Source</i></b></a>
26 *
27 * @author Alberto Montero
28 */
29 class BeanGlobalVariable implements IAccessor {
30
31 public BeanGlobalVariable(Ruby ruby, Object bean, Class<?> type) {
32 _ruby = ruby;
33 _type = type;
34
35 _bean = JavaUtil.convertJavaToRuby(_ruby, bean, _type);
36
37 if (_bean instanceof JavaObject) {
38 _bean = Java.wrap(_ruby, _bean);
39 }
40 }
41
42 public IRubyObject getValue() {
43 return _bean;
44 }
45
46 public IRubyObject setValue(IRubyObject bean) {
47 _bean = bean;
48
49 return bean;
50 }
51
52 private IRubyObject _bean;
53 private Ruby _ruby;
54 private Class<?> _type;
55
56 }