KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > python > core > PyProperty


1 package org.python.core;
2
3 public class PyProperty extends PyObject implements PyType.Newstyle {
4     /* type info */
5
6     public static final String JavaDoc exposed_name = "property";
7
8     public static void typeSetup(PyObject dict, PyType.Newstyle marker) {
9         dict.__setitem__("fget", new PyGetSetDescr("fget", PyProperty.class,
10                 "getFget", null));
11         dict.__setitem__("fset", new PyGetSetDescr("fset", PyProperty.class,
12                 "getFset", null));
13         dict.__setitem__("fdel", new PyGetSetDescr("fdel", PyProperty.class,
14                 "getFdel", null));
15         dict.__setitem__("__doc__", new PyGetSetDescr("__doc__",
16                 PyProperty.class, "getDoc", null));
17         class exposed___get__ extends PyBuiltinFunctionNarrow {
18
19             private PyProperty self;
20
21             public PyObject getSelf() {
22                 return self;
23             }
24
25             exposed___get__(PyProperty self, PyBuiltinFunction.Info info) {
26                 super(info);
27                 this.self = self;
28             }
29
30             public PyBuiltinFunction makeBound(PyObject self) {
31                 return new exposed___get__((PyProperty) self, info);
32             }
33
34             public PyObject __call__(PyObject arg0, PyObject arg1) {
35                 PyObject obj = (arg0 == Py.None) ? null : arg1;
36                 PyObject type = (arg1 == Py.None) ? null : arg0;
37                 return self.property___get__(obj, type);
38             }
39
40             public PyObject inst_call(PyObject gself, PyObject arg0,
41                     PyObject arg1) {
42                 PyProperty self = (PyProperty) gself;
43                 PyObject obj = (arg0 == Py.None) ? null : arg1;
44                 PyObject type = (arg1 == Py.None) ? null : arg0;
45                 return self.property___get__(obj, type);
46             }
47
48             public PyObject __call__(PyObject arg0) {
49                 PyObject obj = (arg0 == Py.None) ? null : (null);
50                 PyObject type = ((null) == Py.None) ? null : arg0;
51                 return self.property___get__(obj, type);
52             }
53
54             public PyObject inst_call(PyObject gself, PyObject arg0) {
55                 PyProperty self = (PyProperty) gself;
56                 PyObject obj = (arg0 == Py.None) ? null : (null);
57                 PyObject type = ((null) == Py.None) ? null : arg0;
58                 return self.property___get__(obj, type);
59             }
60
61         }
62         dict.__setitem__("__get__", new PyMethodDescr("__get__",
63                 PyProperty.class, 1, 2, new exposed___get__(null, null)));
64         class exposed___set__ extends PyBuiltinFunctionNarrow {
65
66             private PyProperty self;
67
68             public PyObject getSelf() {
69                 return self;
70             }
71
72             exposed___set__(PyProperty self, PyBuiltinFunction.Info info) {
73                 super(info);
74                 this.self = self;
75             }
76
77             public PyBuiltinFunction makeBound(PyObject self) {
78                 return new exposed___set__((PyProperty) self, info);
79             }
80
81             public PyObject __call__(PyObject arg0, PyObject arg1) {
82                 self.property___set__(arg0, arg1);
83                 return Py.None;
84             }
85
86             public PyObject inst_call(PyObject gself, PyObject arg0,
87                     PyObject arg1) {
88                 PyProperty self = (PyProperty) gself;
89                 self.property___set__(arg0, arg1);
90                 return Py.None;
91             }
92
93         }
94         dict.__setitem__("__set__", new PyMethodDescr("__set__",
95                 PyProperty.class, 2, 2, new exposed___set__(null, null)));
96         class exposed___delete__ extends PyBuiltinFunctionNarrow {
97
98             private PyProperty self;
99
100             public PyObject getSelf() {
101                 return self;
102             }
103
104             exposed___delete__(PyProperty self, PyBuiltinFunction.Info info) {
105                 super(info);
106                 this.self = self;
107             }
108
109             public PyBuiltinFunction makeBound(PyObject self) {
110                 return new exposed___delete__((PyProperty) self, info);
111             }
112
113             public PyObject __call__(PyObject arg0) {
114                 self.property___delete__(arg0);
115                 return Py.None;
116             }
117
118             public PyObject inst_call(PyObject gself, PyObject arg0) {
119                 PyProperty self = (PyProperty) gself;
120                 self.property___delete__(arg0);
121                 return Py.None;
122             }
123
124         }
125         dict.__setitem__("__delete__", new PyMethodDescr("__delete__",
126                 PyProperty.class, 1, 1, new exposed___delete__(null, null)));
127         class exposed___init__ extends PyBuiltinFunctionWide {
128
129             private PyProperty self;
130
131             public PyObject getSelf() {
132                 return self;
133             }
134
135             exposed___init__(PyProperty self, PyBuiltinFunction.Info info) {
136                 super(info);
137                 this.self = self;
138             }
139
140             public PyBuiltinFunction makeBound(PyObject self) {
141                 return new exposed___init__((PyProperty) self, info);
142             }
143
144             public PyObject inst_call(PyObject self, PyObject[] args) {
145                 return inst_call(self, args, Py.NoKeywords);
146             }
147
148             public PyObject __call__(PyObject[] args) {
149                 return __call__(args, Py.NoKeywords);
150             }
151
152             public PyObject __call__(PyObject[] args, String JavaDoc[] keywords) {
153                 self.property_init(args, keywords);
154                 return Py.None;
155             }
156
157             public PyObject inst_call(PyObject gself, PyObject[] args,
158                     String JavaDoc[] keywords) {
159                 PyProperty self = (PyProperty) gself;
160                 self.property_init(args, keywords);
161                 return Py.None;
162             }
163
164         }
165         dict.__setitem__("__init__", new PyMethodDescr("__init__",
166                 PyProperty.class, -1, -1, new exposed___init__(null, null)));
167         dict.__setitem__("__new__", new PyNewWrapper(PyProperty.class,
168                 "__new__", -1, -1) {
169
170             public PyObject new_impl(boolean init, PyType subtype,
171                     PyObject[] args, String JavaDoc[] keywords) {
172                 PyProperty newobj;
173                 if (for_type == subtype) {
174                     newobj = new PyProperty();
175                     if (init)
176                         newobj.property_init(args, keywords);
177                 } else {
178                     newobj = null; // new PyPropertyDerived(subtype);
179
}
180                 return newobj;
181             }
182
183         });
184     }
185
186     protected PyObject fget;
187     protected PyObject fset;
188     protected PyObject fdel;
189     protected PyObject doc;
190
191     public PyObject getDoc() {
192         return doc;
193     }
194     public PyObject getFdel() {
195         return fdel;
196     }
197     public PyObject getFset() {
198         return fset;
199     }
200
201     public PyObject getFget() {
202         return fget;
203     }
204
205     public void property_init(PyObject[] args, String JavaDoc[] keywords) {
206         ArgParser argparse = new ArgParser("property",args, keywords,
207                 new String JavaDoc[] {"fget","fset","fdel","doc"}, 0);
208         fget = argparse.getPyObject(0, null);
209         fget = fget==Py.None?null:fget;
210         fset = argparse.getPyObject(1, null);
211         fset = fset==Py.None?null:fset;
212         fdel = argparse.getPyObject(2, null);
213         fdel = fdel==Py.None?null:fdel;
214         doc = argparse.getPyObject(3, null);
215     }
216
217     public PyObject __call__(PyObject arg1, PyObject args[], String JavaDoc keywords[]) {
218         return fget.__call__(arg1);
219     }
220
221     public PyObject __get__(PyObject obj, PyObject type) {
222         return property___get__(obj,type);
223     }
224
225     final PyObject property___get__(PyObject obj, PyObject type) {
226         if (obj == null || null == Py.None)
227             return this;
228         if (fget == null)
229             throw Py.AttributeError("unreadable attribute");
230         return fget.__call__(obj);
231     }
232
233     public void __set__(PyObject obj, PyObject value) {
234         property___set__(obj,value);
235     }
236
237     final void property___set__(PyObject obj, PyObject value) {
238         if (fset == null)
239             throw Py.AttributeError("can't set attribute");
240         fset.__call__(obj, value);
241     }
242
243     public void __delete__(PyObject obj) {
244         property___delete__(obj);
245     }
246
247     final void property___delete__(PyObject obj) {
248         if (fdel == null)
249             throw Py.AttributeError("can't delete attribute");
250         fdel.__call__(obj);
251     }
252
253 }
254
Popular Tags