KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jruby > RubyBinding


1 /***** BEGIN LICENSE BLOCK *****
2  * Version: CPL 1.0/GPL 2.0/LGPL 2.1
3  *
4  * The contents of this file are subject to the Common Public
5  * License Version 1.0 (the "License"); you may not use this file
6  * except in compliance with the License. You may obtain a copy of
7  * the License at http://www.eclipse.org/legal/cpl-v10.html
8  *
9  * Software distributed under the License is distributed on an "AS
10  * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
11  * implied. See the License for the specific language governing
12  * rights and limitations under the License.
13  *
14  * Copyright (C) 2001 Chad Fowler <chadfowler@chadfowler.com>
15  * Copyright (C) 2001 Alan Moore <alan_moore@gmx.net>
16  * Copyright (C) 2001-2004 Jan Arne Petersen <jpetersen@uni-bonn.de>
17  * Copyright (C) 2002-2004 Anders Bengtsson <ndrsbngtssn@yahoo.se>
18  * Copyright (C) 2002-2005 Thomas E Enebo <enebo@acm.org>
19  * Copyright (C) 2004 Stefan Matthias Aust <sma@3plus4.de>
20  * Copyright (C) 2005 Charles O Nutter <headius@headius.com>
21  *
22  * Alternatively, the contents of this file may be used under the terms of
23  * either of the GNU General Public License Version 2 or later (the "GPL"),
24  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
25  * in which case the provisions of the GPL or the LGPL are applicable instead
26  * of those above. If you wish to allow use of your version of this file only
27  * under the terms of either the GPL or the LGPL, and not to allow others to
28  * use your version of this file under the terms of the CPL, indicate your
29  * decision by deleting the provisions above and replace them with the notice
30  * and other provisions required by the GPL or the LGPL. If you do not delete
31  * the provisions above, a recipient may use your version of this file under
32  * the terms of any one of the CPL, the GPL or the LGPL.
33  ***** END LICENSE BLOCK *****/

34 package org.jruby;
35
36 import org.jruby.runtime.Block;
37 import org.jruby.runtime.Frame;
38 import org.jruby.runtime.ThreadContext;
39
40 /**
41  * @author jpetersen
42  */

43 public class RubyBinding extends RubyObject {
44     private Block block = null;
45     private RubyModule wrapper = null;
46
47     public RubyBinding(Ruby runtime, RubyClass rubyClass, Block block, RubyModule wrapper) {
48         super(runtime, rubyClass);
49         
50         this.block = block;
51         this.wrapper = wrapper;
52     }
53
54     public Block getBlock() {
55         return block;
56     }
57
58     public RubyModule getWrapper() {
59         return wrapper;
60     }
61
62     // Proc class
63

64     public static RubyBinding newBinding(Ruby runtime, Block block) {
65         return new RubyBinding(runtime, runtime.getClass("Binding"), block, block.getKlass());
66     }
67
68     public static RubyBinding newBinding(Ruby runtime) {
69         ThreadContext context = runtime.getCurrentContext();
70         
71         // FIXME: We should be cloning, not reusing: frame, scope, dynvars, and potentially iter/block info
72
RubyModule wrapper = context.getWrapper();
73         Frame frame = context.getCurrentFrame();
74
75         Block bindingBlock = Block.createBinding(wrapper, frame, context.getCurrentScope());
76         return new RubyBinding(runtime, runtime.getClass("Binding"), bindingBlock, context.getBindingRubyClass());
77     }
78 }
79
Popular Tags