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


001:        // Copyright (c) Corporation for National Research Initiatives
002:        // Copyright 2000 Samuele Pedroni
003:
004:        package org.python.core;
005:
006:        import java.util.StringTokenizer;
007:
008:        /**
009:         * A representation of java package.
010:         */
011:
012:        public class PyJavaPackage extends PyObject {
013:            public String __name__;
014:
015:            public PyStringMap __dict__;
016:            //public String _unparsedAll;
017:            /** Its keys are the names of statically known classes.
018:             * E.g. from jars pre-scan.
019:             */
020:            public PyStringMap clsSet;
021:            public String __file__;
022:            //public PyList __all__;
023:
024:            /** (Control) package manager whose hierarchy contains this java pkg.
025:             */
026:            public PackageManager __mgr__;
027:
028:            public PyJavaPackage(String name) {
029:                this (name, null, null);
030:            }
031:
032:            public PyJavaPackage(String name, String jarfile) {
033:                this (name, null, jarfile);
034:            }
035:
036:            public PyJavaPackage(String name, PackageManager mgr) {
037:                this (name, mgr, null);
038:            }
039:
040:            public PyJavaPackage(String name, PackageManager mgr, String jarfile) {
041:                __file__ = jarfile;
042:                __name__ = name;
043:
044:                if (mgr == null)
045:                    __mgr__ = PySystemState.packageManager; // default
046:                else
047:                    __mgr__ = mgr;
048:
049:                clsSet = new PyStringMap();
050:
051:                __dict__ = new PyStringMap();
052:                __dict__.__setitem__("__name__", new PyString(__name__));
053:            }
054:
055:            public PyJavaPackage addPackage(String name) {
056:                return addPackage(name, null);
057:            }
058:
059:            public PyJavaPackage addPackage(String name, String jarfile) {
060:                int dot = name.indexOf('.');
061:                String firstName = name;
062:                String lastName = null;
063:                if (dot != -1) {
064:                    firstName = name.substring(0, dot);
065:                    lastName = name.substring(dot + 1, name.length());
066:                }
067:                firstName = firstName.intern();
068:                PyJavaPackage p = (PyJavaPackage) __dict__
069:                        .__finditem__(firstName);
070:                if (p == null) {
071:                    String pname = __name__.length() == 0 ? firstName
072:                            : __name__ + '.' + firstName;
073:                    p = new PyJavaPackage(pname, __mgr__, jarfile);
074:                    __dict__.__setitem__(firstName, p);
075:                } else {
076:                    // this code is ok here, because this is not needed for
077:                    // a top level package
078:                    if (jarfile == null || !jarfile.equals(p.__file__))
079:                        p.__file__ = null;
080:                }
081:                if (lastName != null)
082:                    return p.addPackage(lastName, jarfile);
083:                else
084:                    return p;
085:            }
086:
087:            public PyObject addClass(String name, Class c) {
088:                // xxx what to do with PyObject subclasses?
089:                //PyObject ret = PyJavaClass.lookup(c);  // xxx java2py?
090:                // perhaps introduce class2py
091:                PyObject ret = Py.java2py(c);
092:                __dict__.__setitem__(name.intern(), ret);
093:                return ret;
094:            }
095:
096:            public PyObject addLazyClass(String name) {
097:                // xxx what to do with PyObject subclasses? this now fails on them
098:                PyObject ret = PyJavaClass.lookup(__name__ + '.' + name,
099:                        __mgr__);
100:                __dict__.__setitem__(name.intern(), ret);
101:                return ret;
102:            }
103:
104:            /** Add statically known classes.
105:             * @param classes their names as comma-separated string
106:             */
107:            public void addPlaceholders(String classes) {
108:                StringTokenizer tok = new StringTokenizer(classes, ",@");
109:                while (tok.hasMoreTokens()) {
110:                    String p = tok.nextToken();
111:                    String name = p.trim().intern();
112:                    if (clsSet.__finditem__(name) == null)
113:                        clsSet.__setitem__(name, Py.One);
114:                }
115:            }
116:
117:            public PyObject __dir__() {
118:                return __mgr__.doDir(this , false, false);
119:            }
120:
121:            /**
122:             * Used for 'from xyz import *', dynamically dir pkg filling up __dict__.
123:             * It uses {@link PackageManager#doDir} implementation furnished by
124:             * the control package manager with instatiate true. The package
125:             * manager should lazily load classes with {@link #addLazyClass} in
126:             * the package.
127:             *
128:             * @return list of member names
129:             */
130:            public PyObject fillDir() {
131:                return __mgr__.doDir(this , true, false);
132:            }
133:
134:            public PyObject __findattr__(String name) {
135:
136:                PyObject ret = __dict__.__finditem__(name);
137:                if (ret != null)
138:                    return ret;
139:
140:                if (__mgr__.packageExists(__name__, name)) {
141:                    __mgr__.notifyPackageImport(__name__, name);
142:                    return addPackage(name);
143:                }
144:
145:                Class c = __mgr__.findClass(__name__, name);
146:                if (c != null)
147:                    return addClass(name, c);
148:
149:                if (name == "__name__")
150:                    return new PyString(__name__);
151:                if (name == "__dict__")
152:                    return __dict__;
153:                if (name == "__mgr__")
154:                    return Py.java2py(__mgr__);
155:                if (name == "__file__") {
156:                    if (__file__ != null)
157:                        return new PyString(__file__);
158:
159:                    return Py.None;
160:                }
161:
162:                return null;
163:            }
164:
165:            public void __setattr__(String attr, PyObject value) {
166:                if (attr == "__mgr__") {
167:                    PackageManager newMgr = (PackageManager) Py.tojava(value,
168:                            PackageManager.class);
169:                    if (newMgr == null) {
170:                        throw Py
171:                                .TypeError("cannot set java package __mgr__ to None");
172:                    }
173:                    __mgr__ = newMgr;
174:                    return;
175:                }
176:                if (attr == "__file__") {
177:                    __file__ = value.__str__().toString();
178:                    return;
179:                }
180:
181:                super .__setattr__(attr, value);
182:            }
183:
184:            public String toString() {
185:                return "<java package " + __name__ + " " + Py.idstr(this ) + ">";
186:            }
187:
188:            /**
189:             * @see org.python.core.PyObject#safeRepr()
190:             */
191:            public String safeRepr() throws PyIgnoreMethodTag {
192:                return "java package '" + __name__ + "'";
193:            }
194:
195:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.