Source Code Cross Referenced for CollectionProxy.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:        // Copyright (c) Corporation for National Research Initiatives
002:
003:        package org.python.core;
004:
005:        import java.util.*;
006:
007:        class CollectionProxy {
008:            public static final CollectionProxy NoProxy = new EnumerationProxy(
009:                    null);
010:
011:            private static boolean checkedJava2 = false;
012:
013:            private static CollectionProxy java2Proxy = null;
014:
015:            public CollectionProxy instanceFindCollection(Object object) {
016:                return null;
017:            }
018:
019:            public static CollectionProxy findCollection(Object object) {
020:                if (object == null)
021:                    return NoProxy;
022:
023:                if (!checkedJava2) {
024:                    checkedJava2 = true;
025:                    try {
026:                        Class c = Class
027:                                .forName("org.python.core.CollectionProxy2");
028:                        Class.forName("java.util.Collection");
029:                        java2Proxy = (CollectionProxy) c.newInstance();
030:                    } catch (Throwable t) {
031:                    }
032:                }
033:                if (java2Proxy != null) {
034:                    CollectionProxy ret = java2Proxy
035:                            .instanceFindCollection(object);
036:                    if (ret != null)
037:                        return ret;
038:                }
039:
040:                if (object instanceof  Vector) {
041:                    return new VectorProxy(((Vector) object));
042:                }
043:                if (object instanceof  Enumeration) {
044:                    return new EnumerationProxy(((Enumeration) object));
045:                }
046:                if (object instanceof  Dictionary) {
047:                    return new DictionaryProxy(((Dictionary) object));
048:                }
049:
050:                return NoProxy;
051:            }
052:
053:            /** The basic functions to implement a mapping* */
054:            public int __len__() {
055:                throw Py.AttributeError("__len__");
056:            }
057:
058:            public PyObject __finditem__(int key) {
059:                return __finditem__(new PyInteger(key));
060:            }
061:
062:            public PyObject __finditem__(PyObject key) {
063:                throw Py.AttributeError("__getitem__");
064:            }
065:
066:            public PyObject __getitem__(int key) {
067:                PyObject ret = __finditem__(key);
068:                if (ret == null)
069:                    throw Py.KeyError("" + key);
070:                return ret;
071:            }
072:
073:            public PyObject __getitem__(PyObject key) {
074:                PyObject ret = __finditem__(key);
075:                if (ret == null)
076:                    throw Py.KeyError(key.toString());
077:                return ret;
078:            }
079:
080:            public void __setitem__(PyObject key, PyObject value) {
081:                throw Py.AttributeError("__setitem__");
082:            }
083:
084:            public void __delitem__(PyObject key) {
085:                throw Py.AttributeError("__delitem__");
086:            }
087:        }
088:
089:        class EnumerationProxy extends CollectionProxy {
090:            Enumeration proxy;
091:
092:            int counter;
093:
094:            public EnumerationProxy(Enumeration proxy) {
095:                this .proxy = proxy;
096:                this .counter = 0;
097:            }
098:
099:            public PyObject __finditem__(int key) {
100:                if (key != this .counter) {
101:                    throw Py
102:                            .ValueError("enumeration indices must be consecutive ints starting at 0");
103:                }
104:                this .counter++;
105:                if (this .proxy.hasMoreElements()) {
106:                    return Py.java2py(this .proxy.nextElement());
107:                } else {
108:                    return null;
109:                }
110:            }
111:
112:            public PyObject __finditem__(PyObject key) {
113:                if (key instanceof  PyInteger) {
114:                    return __finditem__(((PyInteger) key).getValue());
115:                } else {
116:                    throw Py.TypeError("only integer keys accepted");
117:                }
118:            }
119:        }
120:
121:        class VectorProxy extends CollectionProxy {
122:            Vector proxy;
123:
124:            public VectorProxy(Vector proxy) {
125:                this .proxy = proxy;
126:            }
127:
128:            public int __len__() {
129:                return this .proxy.size();
130:            }
131:
132:            public PyObject __finditem__(int key) {
133:                try {
134:                    return Py.java2py(this .proxy.elementAt(key));
135:                } catch (ArrayIndexOutOfBoundsException exc) {
136:                    return null;
137:                }
138:            }
139:
140:            public PyObject __finditem__(PyObject key) {
141:                if (key instanceof  PyInteger) {
142:                    return __finditem__(((PyInteger) key).getValue());
143:                } else {
144:                    throw Py.TypeError("only integer keys accepted");
145:                }
146:            }
147:
148:            public void __setitem__(PyObject key, PyObject value) {
149:                if (key instanceof  PyInteger) {
150:                    this .proxy.setElementAt(Py.tojava(value, Object.class),
151:                            ((PyInteger) key).getValue());
152:                } else {
153:                    throw Py.TypeError("only integer keys accepted");
154:                }
155:            }
156:
157:            public void __delitem__(PyObject key) {
158:                if (key instanceof  PyInteger) {
159:                    this .proxy.removeElementAt(((PyInteger) key).getValue());
160:                } else {
161:                    throw Py.TypeError("only integer keys accepted");
162:                }
163:            }
164:        }
165:
166:        class DictionaryProxy extends CollectionProxy {
167:            Dictionary proxy;
168:
169:            public DictionaryProxy(Dictionary proxy) {
170:                this .proxy = proxy;
171:            }
172:
173:            public int __len__() {
174:                return this .proxy.size();
175:            }
176:
177:            public PyObject __finditem__(int key) {
178:                throw Py.TypeError("loop over non-sequence");
179:            }
180:
181:            public PyObject __finditem__(PyObject key) {
182:                return Py.java2py(this .proxy.get(Py.tojava(key, Object.class)));
183:            }
184:
185:            public void __setitem__(PyObject key, PyObject value) {
186:                this .proxy.put(Py.tojava(key, Object.class), Py.tojava(value,
187:                        Object.class));
188:            }
189:
190:            public void __delitem__(PyObject key) {
191:                this .proxy.remove(Py.tojava(key, Object.class));
192:            }
193:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.