Source Code Cross Referenced for RubyBinding.java in  » Scripting » jruby » org » jruby » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Scripting » jruby » org.jruby 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /***** BEGIN LICENSE BLOCK *****
002:         * Version: CPL 1.0/GPL 2.0/LGPL 2.1
003:         *
004:         * The contents of this file are subject to the Common Public
005:         * License Version 1.0 (the "License"); you may not use this file
006:         * except in compliance with the License. You may obtain a copy of
007:         * the License at http://www.eclipse.org/legal/cpl-v10.html
008:         *
009:         * Software distributed under the License is distributed on an "AS
010:         * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
011:         * implied. See the License for the specific language governing
012:         * rights and limitations under the License.
013:         *
014:         * Copyright (C) 2001 Chad Fowler <chadfowler@chadfowler.com>
015:         * Copyright (C) 2001 Alan Moore <alan_moore@gmx.net>
016:         * Copyright (C) 2001-2004 Jan Arne Petersen <jpetersen@uni-bonn.de>
017:         * Copyright (C) 2002-2004 Anders Bengtsson <ndrsbngtssn@yahoo.se>
018:         * Copyright (C) 2002-2005 Thomas E Enebo <enebo@acm.org>
019:         * Copyright (C) 2004 Stefan Matthias Aust <sma@3plus4.de>
020:         * Copyright (C) 2005 Charles O Nutter <headius@headius.com>
021:         * 
022:         * Alternatively, the contents of this file may be used under the terms of
023:         * either of the GNU General Public License Version 2 or later (the "GPL"),
024:         * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
025:         * in which case the provisions of the GPL or the LGPL are applicable instead
026:         * of those above. If you wish to allow use of your version of this file only
027:         * under the terms of either the GPL or the LGPL, and not to allow others to
028:         * use your version of this file under the terms of the CPL, indicate your
029:         * decision by deleting the provisions above and replace them with the notice
030:         * and other provisions required by the GPL or the LGPL. If you do not delete
031:         * the provisions above, a recipient may use your version of this file under
032:         * the terms of any one of the CPL, the GPL or the LGPL.
033:         ***** END LICENSE BLOCK *****/package org.jruby;
034:
035:        import org.jruby.runtime.Block;
036:        import org.jruby.runtime.CallbackFactory;
037:        import org.jruby.runtime.Frame;
038:        import org.jruby.runtime.ObjectAllocator;
039:        import org.jruby.runtime.ThreadContext;
040:        import org.jruby.runtime.builtin.IRubyObject;
041:
042:        /**
043:         * @author  jpetersen
044:         */
045:        public class RubyBinding extends RubyObject {
046:            private Block block;
047:
048:            public RubyBinding(Ruby runtime, RubyClass rubyClass, Block block) {
049:                super (runtime, rubyClass);
050:
051:                this .block = block;
052:            }
053:
054:            private static ObjectAllocator BINDING_ALLOCATOR = new ObjectAllocator() {
055:                public IRubyObject allocate(Ruby runtime, RubyClass klass) {
056:                    RubyBinding instance = runtime.newBinding();
057:
058:                    instance.setMetaClass(klass);
059:
060:                    return instance;
061:                }
062:            };
063:
064:            public static RubyClass createBindingClass(Ruby runtime) {
065:                RubyClass bindingClass = runtime.defineClass("Binding", runtime
066:                        .getObject(), BINDING_ALLOCATOR);
067:                CallbackFactory callbackFactory = runtime
068:                        .callbackFactory(RubyBinding.class);
069:
070:                bindingClass.getMetaClass().defineMethod("of_caller",
071:                        callbackFactory.getSingletonMethod("of_caller"));
072:
073:                return bindingClass;
074:            }
075:
076:            public Block getBlock() {
077:                return block;
078:            }
079:
080:            // Proc class
081:
082:            public static RubyBinding newBinding(Ruby runtime, Block block) {
083:                return new RubyBinding(runtime, runtime.getClass("Binding"),
084:                        block);
085:            }
086:
087:            public static RubyBinding newBinding(Ruby runtime) {
088:                ThreadContext context = runtime.getCurrentContext();
089:
090:                // FIXME: We should be cloning, not reusing: frame, scope, dynvars, and potentially iter/block info
091:                Frame frame = context.getCurrentFrame();
092:                Block bindingBlock = Block.createBinding(frame, context
093:                        .getCurrentScope());
094:
095:                return new RubyBinding(runtime, runtime.getClass("Binding"),
096:                        bindingBlock);
097:            }
098:
099:            /**
100:             * Create a binding appropriate for a bare "eval", by using the previous (caller's) frame and current
101:             * scope.
102:             */
103:            public static RubyBinding newBindingForEval(Ruby runtime) {
104:                ThreadContext context = runtime.getCurrentContext();
105:
106:                // This requires some explaining.  We use Frame values when executing blocks to fill in 
107:                // various values in ThreadContext and EvalState.eval like rubyClass, cref, and self.
108:                // Largely, for an eval that is using the logical binding at a place where the eval is 
109:                // called we mostly want to use the current frames value for this.  Most importantly, 
110:                // we need that self (JRUBY-858) at this point.  We also need to make sure that returns
111:                // jump to the right place (which happens to be the previous frame).  Lastly, we do not
112:                // want the current frames klazz since that will be the klazz represented of self.  We
113:                // want the class right before the eval (well we could use cref class for this too I think).
114:                // Once we end up having Frames created earlier I think the logic of stuff like this will
115:                // be better since we won't be worried about setting Frame to setup other variables/stacks
116:                // but just making sure Frame itself is correct...
117:
118:                Frame previousFrame = context.getPreviousFrame();
119:                Frame currentFrame = context.getCurrentFrame();
120:                currentFrame.setKlazz(previousFrame.getKlazz());
121:
122:                // Set jump target to whatever the previousTarget thinks is good.
123:                currentFrame
124:                        .setJumpTarget(previousFrame.getJumpTarget() != null ? previousFrame
125:                                .getJumpTarget()
126:                                : previousFrame);
127:
128:                Block bindingBlock = Block.createBinding(previousFrame, context
129:                        .getCurrentScope());
130:
131:                return new RubyBinding(runtime, runtime.getClass("Binding"),
132:                        bindingBlock);
133:            }
134:
135:            public static RubyBinding newBindingOfCaller(Ruby runtime) {
136:                ThreadContext context = runtime.getCurrentContext();
137:
138:                // FIXME: We should be cloning, not reusing: frame, scope, dynvars, and potentially iter/block info
139:                Frame frame = context.getPreviousFrame();
140:                Block bindingBlock = Block.createBinding(frame, context
141:                        .getPreviousScope());
142:
143:                return new RubyBinding(runtime, runtime.getClass("Binding"),
144:                        bindingBlock);
145:            }
146:
147:            public static IRubyObject of_caller(IRubyObject recv, Block aBlock) {
148:                return RubyBinding.newBindingOfCaller(recv.getRuntime());
149:            }
150:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.