Source Code Cross Referenced for VMBridge.java in  » Scripting » rhino » org » mozilla » javascript » 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 » rhino » org.mozilla.javascript 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
002:         *
003:         * ***** BEGIN LICENSE BLOCK *****
004:         * Version: MPL 1.1/GPL 2.0
005:         *
006:         * The contents of this file are subject to the Mozilla Public License Version
007:         * 1.1 (the "License"); you may not use this file except in compliance with
008:         * the License. You may obtain a copy of the License at
009:         * http://www.mozilla.org/MPL/
010:         *
011:         * Software distributed under the License is distributed on an "AS IS" basis,
012:         * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
013:         * for the specific language governing rights and limitations under the
014:         * License.
015:         *
016:         * The Original Code is Rhino code, released
017:         * May 6, 1999.
018:         *
019:         * The Initial Developer of the Original Code is
020:         * Netscape Communications Corporation.
021:         * Portions created by the Initial Developer are Copyright (C) 1997-2000
022:         * the Initial Developer. All Rights Reserved.
023:         *
024:         * Contributor(s):
025:         *
026:         * Alternatively, the contents of this file may be used under the terms of
027:         * the GNU General Public License Version 2 or later (the "GPL"), in which
028:         * case the provisions of the GPL are applicable instead of those above. If
029:         * you wish to allow use of your version of this file only under the terms of
030:         * the GPL and not to allow others to use your version of this file under the
031:         * MPL, indicate your decision by deleting the provisions above and replacing
032:         * them with the notice and other provisions required by the GPL. If you do
033:         * not delete the provisions above, a recipient may use your version of this
034:         * file under either the MPL or the GPL.
035:         *
036:         * ***** END LICENSE BLOCK ***** */
037:
038:        // API class
039:        package org.mozilla.javascript;
040:
041:        import java.lang.reflect.Method;
042:        import java.lang.reflect.Member;
043:        import java.util.Iterator;
044:
045:        public abstract class VMBridge {
046:
047:            static final VMBridge instance = makeInstance();
048:
049:            private static VMBridge makeInstance() {
050:                String[] classNames = {
051:                        "org.mozilla.javascript.VMBridge_custom",
052:                        "org.mozilla.javascript.jdk15.VMBridge_jdk15",
053:                        "org.mozilla.javascript.jdk13.VMBridge_jdk13",
054:                        "org.mozilla.javascript.jdk11.VMBridge_jdk11", };
055:                for (int i = 0; i != classNames.length; ++i) {
056:                    String className = classNames[i];
057:                    Class cl = Kit.classOrNull(className);
058:                    if (cl != null) {
059:                        VMBridge bridge = (VMBridge) Kit.newInstanceOrNull(cl);
060:                        if (bridge != null) {
061:                            return bridge;
062:                        }
063:                    }
064:                }
065:                throw new IllegalStateException(
066:                        "Failed to create VMBridge instance");
067:            }
068:
069:            /**
070:             * Return a helper object to optimize {@link Context} access.
071:             * <p>
072:             * The runtime will pass the resulting helper object to the subsequent
073:             * calls to {@link #getContext(Object contextHelper)} and
074:             * {@link #setContext(Object contextHelper, Context cx)} methods.
075:             * In this way the implementation can use the helper to cache
076:             * information about current thread to make {@link Context} access faster.
077:             */
078:            protected abstract Object getThreadContextHelper();
079:
080:            /**
081:             * Get {@link Context} instance associated with the current thread
082:             * or null if none.
083:             *
084:             * @param contextHelper The result of {@link #getThreadContextHelper()}
085:             *                      called from the current thread.
086:             */
087:            protected abstract Context getContext(Object contextHelper);
088:
089:            /**
090:             * Associate {@link Context} instance with the current thread or remove
091:             * the current association if <tt>cx</tt> is null.
092:             *
093:             * @param contextHelper The result of {@link #getThreadContextHelper()}
094:             *                      called from the current thread.
095:             */
096:            protected abstract void setContext(Object contextHelper, Context cx);
097:
098:            /**
099:             * Return the ClassLoader instance associated with the current thread.
100:             */
101:            protected abstract ClassLoader getCurrentThreadClassLoader();
102:
103:            /**
104:             * In many JVMSs, public methods in private
105:             * classes are not accessible by default (Sun Bug #4071593).
106:             * VMBridge instance should try to workaround that via, for example,
107:             * calling method.setAccessible(true) when it is available.
108:             * The implementation is responsible to catch all possible exceptions
109:             * like SecurityException if the workaround is not available.
110:             *
111:             * @return true if it was possible to make method accessible
112:             *         or false otherwise.
113:             */
114:            protected abstract boolean tryToMakeAccessible(
115:                    Object accessibleObject);
116:
117:            /**
118:             * Create helper object to create later proxies implementing the specified
119:             * interfaces later. Under JDK 1.3 the implementation can look like:
120:             * <pre>
121:             * return java.lang.reflect.Proxy.getProxyClass(..., interfaces).
122:             *     getConstructor(new Class[] {
123:             *         java.lang.reflect.InvocationHandler.class });
124:             * </pre>
125:             *
126:             * @param interfaces Array with one or more interface class objects.
127:             */
128:            protected Object getInterfaceProxyHelper(ContextFactory cf,
129:                    Class[] interfaces) {
130:                throw Context
131:                        .reportRuntimeError("VMBridge.getInterfaceProxyHelper is not supported");
132:            }
133:
134:            /**
135:             * Create proxy object for {@link InterfaceAdapter}. The proxy should call
136:             * {@link InterfaceAdapter#invoke(ContextFactory cf,
137:             *                                Object target,
138:             *                                Scriptable topScope,
139:             *                                Method method,
140:             *                                Object[] args)}
141:             * as implementation of interface methods associated with
142:             * <tt>proxyHelper</tt>.
143:             *
144:             * @param proxyHelper The result of the previous call to
145:             *        {@link #getInterfaceProxyHelper(ContextFactory, Class[])}.
146:             */
147:            protected Object newInterfaceProxy(Object proxyHelper,
148:                    ContextFactory cf, InterfaceAdapter adapter, Object target,
149:                    Scriptable topScope) {
150:                throw Context
151:                        .reportRuntimeError("VMBridge.newInterfaceProxy is not supported");
152:            }
153:
154:            /**
155:             * Returns whether or not a given member (method or constructor)
156:             * has variable arguments.
157:             * Variable argument methods have only been supported in Java since
158:             * JDK 1.5.
159:             */
160:            protected abstract boolean isVarArgs(Member member);
161:
162:            /**
163:             * If "obj" is a java.util.Iterator or a java.lang.Iterable, return a
164:             * wrapping as a JavaScript Iterator. Otherwise, return null.
165:             * This method is in VMBridge since Iterable is a JDK 1.5 addition.
166:             */
167:            public Iterator getJavaIterator(Context cx, Scriptable scope,
168:                    Object obj) {
169:                if (obj instanceof  Wrapper) {
170:                    Object unwrapped = ((Wrapper) obj).unwrap();
171:                    Iterator iterator = null;
172:                    if (unwrapped instanceof  Iterator)
173:                        iterator = (Iterator) unwrapped;
174:                    return iterator;
175:                }
176:                return null;
177:            }
178:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.