Source Code Cross Referenced for PyGetSetDescr.java in  » Scripting » jython » org » python » core » 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 » jython » org.python.core 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.python.core;
002:
003:        import java.lang.reflect.InvocationTargetException;
004:        import java.lang.reflect.Method;
005:        import java.lang.reflect.Modifier;
006:
007:        public class PyGetSetDescr extends PyDescriptor {
008:
009:            private Method get_meth;
010:
011:            private Method set_meth;
012:
013:            private Method del_meth;
014:
015:            private Class getset_type;
016:
017:            public PyGetSetDescr(PyType dtype, String name, Class c,
018:                    String get, String set) {
019:                this (dtype, name, c, get, set, null);
020:            }
021:
022:            public PyGetSetDescr(String name, Class c, String get, String set) {
023:                this (PyType.fromClass(c), name, c, get, set, null);
024:            }
025:
026:            public PyGetSetDescr(PyType dtype, String name, Class c,
027:                    String get, String set, String del) {
028:                this .name = name;
029:                this .dtype = dtype;
030:                try {
031:                    get_meth = c.getMethod(get, new Class[] {});
032:                } catch (NoSuchMethodException e) {
033:                    throw Py.SystemError("method " + get + " doesn't exist: "
034:                            + c.getName());
035:                }
036:                if (Modifier.isStatic(get_meth.getModifiers()))
037:                    throw Py.SystemError("static " + get + " not supported: "
038:                            + c.getName());
039:                getset_type = get_meth.getReturnType();
040:                if (set != null) {
041:                    try {
042:                        set_meth = c
043:                                .getMethod(set, new Class[] { getset_type });
044:                    } catch (NoSuchMethodException e) {
045:                        throw Py.SystemError("method " + set
046:                                + " doesn't exist: " + c.getName());
047:                    }
048:                    if (Modifier.isStatic(set_meth.getModifiers()))
049:                        throw Py.SystemError("static " + set
050:                                + " not supported: " + c.getName());
051:                }
052:                if (del != null) {
053:                    try {
054:                        del_meth = c.getMethod(del, new Class[] {});
055:                    } catch (NoSuchMethodException e) {
056:                        throw Py.SystemError("method " + set
057:                                + " doesn't exist: " + c.getName());
058:                    }
059:                    if (Modifier.isStatic(del_meth.getModifiers()))
060:                        throw Py.SystemError("static " + del
061:                                + " not supported: " + c.getName());
062:                }
063:            }
064:
065:            public PyGetSetDescr(String name, Class c, String get, String set,
066:                    String del) {
067:                this (PyType.fromClass(c), name, c, get, set, del);
068:            }
069:
070:            public String toString() {
071:                return "<attribute '" + name + "' of '" + dtype.fastGetName()
072:                        + "' objects>";
073:            }
074:
075:            /**
076:             * @see org.python.core.PyObject#__get__(org.python.core.PyObject,
077:             *      org.python.core.PyObject)
078:             */
079:            public PyObject __get__(PyObject obj, PyObject type) {
080:                try {
081:                    if (obj != null) {
082:                        PyType objtype = obj.getType();
083:                        if (objtype != dtype && !objtype.isSubType(dtype))
084:                            throw get_wrongtype(objtype);
085:                        Object v = get_meth.invoke(obj, new Object[0]);
086:                        if (v == null) {
087:                            obj.noAttributeError(name);
088:                        }
089:                        return Py.java2py(v);
090:                    }
091:                    return this ;
092:                } catch (IllegalArgumentException e) {
093:                    throw Py.JavaError(e);
094:                } catch (IllegalAccessException e) {
095:                    throw Py.JavaError(e); // unexpected
096:                } catch (InvocationTargetException e) {
097:                    throw Py.JavaError(e);
098:                }
099:            }
100:
101:            /**
102:             * @see org.python.core.PyObject#__set__(org.python.core.PyObject,
103:             *      org.python.core.PyObject)
104:             */
105:            public void __set__(PyObject obj, PyObject value) {
106:                try {
107:                    // obj != null
108:                    PyType objtype = obj.getType();
109:                    if (objtype != dtype && !objtype.isSubType(dtype))
110:                        throw get_wrongtype(objtype);
111:                    Object converted = value.__tojava__(getset_type);
112:                    if (converted == Py.NoConversion) {
113:                        throw Py.TypeError(""); // xxx
114:                    }
115:                    set_meth.invoke(obj, new Object[] { converted });
116:                } catch (IllegalArgumentException e) {
117:                    throw Py.JavaError(e);
118:                } catch (IllegalAccessException e) {
119:                    throw Py.JavaError(e); // unexpected
120:                } catch (InvocationTargetException e) {
121:                    throw Py.JavaError(e);
122:                }
123:            }
124:
125:            public void __delete__(PyObject obj) {
126:                try {
127:                    if (obj != null) {
128:                        PyType objtype = obj.getType();
129:                        if (objtype != dtype && !objtype.isSubType(dtype))
130:                            throw get_wrongtype(objtype);
131:                        del_meth.invoke(obj, new Object[0]);
132:                    }
133:                } catch (IllegalArgumentException e) {
134:                    throw Py.JavaError(e);
135:                } catch (IllegalAccessException e) {
136:                    throw Py.JavaError(e); // unexpected
137:                } catch (InvocationTargetException e) {
138:                    throw Py.JavaError(e);
139:                }
140:            }
141:
142:            /**
143:             * @see org.python.core.PyObject#implementsDescrSet()
144:             */
145:            public boolean implements DescrSet() {
146:                return set_meth != null;
147:            }
148:
149:            public boolean implements DescrDelete() {
150:                return del_meth != null;
151:            }
152:
153:            /**
154:             * @see org.python.core.PyObject#isDataDescr()
155:             */
156:            public boolean isDataDescr() {
157:                return true;
158:            }
159:
160:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.