KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jruby > runtime > builtin > meta > ObjectMetaClass


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) 2004 Jan Arne Petersen <jpetersen@uni-bonn.de>
15  * Copyright (C) 2004-2005 Thomas E Enebo <enebo@acm.org>
16  *
17  * Alternatively, the contents of this file may be used under the terms of
18  * either of the GNU General Public License Version 2 or later (the "GPL"),
19  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
20  * in which case the provisions of the GPL or the LGPL are applicable instead
21  * of those above. If you wish to allow use of your version of this file only
22  * under the terms of either the GPL or the LGPL, and not to allow others to
23  * use your version of this file under the terms of the CPL, indicate your
24  * decision by deleting the provisions above and replace them with the notice
25  * and other provisions required by the GPL or the LGPL. If you do not delete
26  * the provisions above, a recipient may use your version of this file under
27  * the terms of any one of the CPL, the GPL or the LGPL.
28  ***** END LICENSE BLOCK *****/

29 package org.jruby.runtime.builtin.meta;
30
31 import org.jruby.Ruby;
32 import org.jruby.RubyClass;
33 import org.jruby.RubyModule;
34 import org.jruby.RubyObject;
35 import org.jruby.runtime.Arity;
36 import org.jruby.runtime.ClassIndex;
37 import org.jruby.runtime.ObjectAllocator;
38 import org.jruby.runtime.builtin.IRubyObject;
39 import org.jruby.util.collections.SinglyLinkedList;
40
41 /**
42  * <p>
43  * The meta class for Object
44  * </p>
45  */

46 public class ObjectMetaClass extends AbstractMetaClass {
47     // Only for creating ObjectMetaClass directly
48
public ObjectMetaClass(Ruby runtime) {
49         super(runtime, null /*Would be Class if it existed yet */, null, OBJECT_ALLOCATOR, null, "Object");
50         
51         this.builtinClass = RubyObject.class;
52         this.index = ClassIndex.OBJECT;
53     }
54     
55     // Only for other core modules/classes
56
protected ObjectMetaClass(Ruby runtime, RubyClass metaClass, RubyClass superClass, ObjectAllocator allocator,
57             SinglyLinkedList parentCRef, String JavaDoc name, Class JavaDoc builtinClass) {
58         super(runtime, metaClass, superClass, allocator, parentCRef, name);
59         
60         this.builtinClass = builtinClass;
61     }
62     
63     protected ObjectMetaClass(String JavaDoc name, Class JavaDoc builtinClass, RubyClass superClass, ObjectAllocator allocator) {
64         this(name, builtinClass, superClass, allocator, superClass.getRuntime().getClass("Object").getCRef());
65     }
66
67     protected ObjectMetaClass(String JavaDoc name, Class JavaDoc builtinClass, RubyClass superClass, ObjectAllocator allocator, SinglyLinkedList parentCRef) {
68         super(superClass.getRuntime(), superClass.getRuntime().getClass("Class"), superClass, allocator, parentCRef, name);
69
70         assert builtinClass != null;
71         //assert RubyObject.class.isAssignableFrom(builtinClass) || RubyObject.class == builtinClass: "builtinClass have to be a subclass of RubyObject.";
72
assert superClass != null;
73
74         this.builtinClass = builtinClass;
75
76         makeMetaClass(superClass.getMetaClass(), getCRef());
77         inheritedBy(superClass);
78
79         if(name != null) {
80             ((RubyModule)parentCRef.getValue()).setConstant(name, this);
81         }
82     }
83     
84     protected class ObjectMeta extends Meta {
85         protected void initializeClass() {
86             definePrivateMethod("initialize", Arity.optional());
87             definePrivateMethod("inherited", Arity.singleArgument());
88             defineFastMethod("initialize_copy", Arity.singleArgument());
89         }
90     };
91     
92     protected Meta getMeta() {
93         return new ObjectMeta();
94     }
95     
96     public static ObjectAllocator OBJECT_ALLOCATOR = new ObjectAllocator() {
97         public IRubyObject allocate(Ruby runtime, RubyClass klass) {
98             IRubyObject instance = new RubyObject(runtime, klass);
99             instance.setMetaClass(klass);
100
101             return instance;
102         }
103     };
104     
105     public void initializeClass() {
106         getMeta().initializeClass();
107     }
108     
109 }
110
Popular Tags