Source Code Cross Referenced for CodebaseAwareObjectInputStream.java in  » J2EE » spring-framework-2.0.6 » org » springframework » remoting » rmi » 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 » J2EE » spring framework 2.0.6 » org.springframework.remoting.rmi 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2002-2007 the original author or authors.
003:         *
004:         * Licensed under the Apache License, Version 2.0 (the "License");
005:         * you may not use this file except in compliance with the License.
006:         * You may obtain a copy of the License at
007:         *
008:         *      http://www.apache.org/licenses/LICENSE-2.0
009:         *
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         */
016:
017:        package org.springframework.remoting.rmi;
018:
019:        import java.io.IOException;
020:        import java.io.InputStream;
021:        import java.io.ObjectInputStream;
022:        import java.io.ObjectStreamClass;
023:        import java.lang.reflect.Proxy;
024:        import java.rmi.server.RMIClassLoader;
025:
026:        import org.springframework.util.ClassUtils;
027:
028:        /**
029:         * Special ObjectInputStream subclass that falls back to a specified codebase
030:         * to load classes from if not found locally. In contrast to standard RMI
031:         * conventions for dynamic class download, it is the client that determines
032:         * the codebase URL here, rather than the "java.rmi.server.codebase" system
033:         * property on the server.
034:         *
035:         * <p>Uses the JDK's RMIClassLoader to load classes from the specified codebase.
036:         * The codebase can consist of multiple URLs, separated by spaces.
037:         * Note that RMIClassLoader requires a SecurityManager to be set, like when
038:         * using dynamic class download with standard RMI! (See the RMI documentation
039:         * for details.)
040:         *
041:         * <p>Despite residing in the RMI package, this class is <i>not</i> used for
042:         * RmiClientInterceptor, which uses the standard RMI infrastructure instead
043:         * and thus is only able to rely on RMI's standard dynamic class download via
044:         * "java.rmi.server.codebase". CodebaseAwareObjectInputStream is used by
045:         * HttpInvokerClientInterceptor (see the "codebaseUrl" property there).
046:         *
047:         * <p>Thanks to Lionel Mestre for suggesting the option and providing
048:         * a prototype!
049:         *
050:         * @author Juergen Hoeller
051:         * @since 1.1.3
052:         * @see java.rmi.server.RMIClassLoader
053:         * @see org.springframework.remoting.httpinvoker.HttpInvokerClientInterceptor#setCodebaseUrl
054:         */
055:        public class CodebaseAwareObjectInputStream extends ObjectInputStream {
056:
057:            private final ClassLoader classLoader;
058:
059:            private final String codebaseUrl;
060:
061:            /**
062:             * Create a new CodebaseAwareObjectInputStream for the given InputStream and codebase.
063:             * @param	in the InputStream to read from
064:             * @param codebaseUrl the codebase URL to load classes from if not found locally
065:             * (can consist of multiple URLs, separated by spaces)
066:             * @see java.io.ObjectInputStream#ObjectInputStream(java.io.InputStream)
067:             */
068:            public CodebaseAwareObjectInputStream(InputStream in,
069:                    String codebaseUrl) throws IOException {
070:                this (in, null, codebaseUrl);
071:            }
072:
073:            /**
074:             * Create a new CodebaseAwareObjectInputStream for the given InputStream and codebase.
075:             * @param	in the InputStream to read from
076:             * @param classLoader the ClassLoader to use for loading local classes
077:             * (may be <code>null</code> to indicate RMI's default ClassLoader)
078:             * @param codebaseUrl the codebase URL to load classes from if not found locally
079:             * (can consist of multiple URLs, separated by spaces)
080:             * @see java.io.ObjectInputStream#ObjectInputStream(java.io.InputStream)
081:             */
082:            public CodebaseAwareObjectInputStream(InputStream in,
083:                    ClassLoader classLoader, String codebaseUrl)
084:                    throws IOException {
085:
086:                super (in);
087:                this .classLoader = classLoader;
088:                this .codebaseUrl = codebaseUrl;
089:            }
090:
091:            /**
092:             * Overridden version delegates to super class first,
093:             * falling back to the specified codebase if not found locally.
094:             */
095:            protected Class resolveClass(ObjectStreamClass classDesc)
096:                    throws IOException, ClassNotFoundException {
097:                try {
098:                    if (this .classLoader != null) {
099:                        // Use the specified ClassLoader to resolve local classes.
100:                        return Class.forName(classDesc.getName(), false,
101:                                this .classLoader);
102:                    } else {
103:                        // Let RMI use it's default ClassLoader...
104:                        return super .resolveClass(classDesc);
105:                    }
106:                } catch (ClassNotFoundException ex) {
107:                    // Explicitly resolve primitive class name.
108:                    // This will be done by the standard ObjectInputStream on JDK 1.4+,
109:                    // but needs to be done explicitly on JDK 1.3.
110:                    Class clazz = ClassUtils
111:                            .resolvePrimitiveClassName(classDesc.getName());
112:                    if (clazz != null) {
113:                        return clazz;
114:                    }
115:                    // If codebaseUrl is set, try to load the class with the RMIClassLoader.
116:                    // Else, propagate the ClassNotFoundException.
117:                    if (this .codebaseUrl == null) {
118:                        throw ex;
119:                    }
120:                    return RMIClassLoader.loadClass(this .codebaseUrl, classDesc
121:                            .getName());
122:                }
123:            }
124:
125:            /**
126:             * Overridden version delegates to super class first,
127:             * falling back to the specified codebase if not found locally.
128:             */
129:            protected Class resolveProxyClass(String[] interfaces)
130:                    throws IOException, ClassNotFoundException {
131:                if (this .classLoader != null) {
132:                    // Use the specified ClassLoader to resolve local proxy classes.
133:                    Class[] resolvedInterfaces = new Class[interfaces.length];
134:                    for (int i = 0; i < interfaces.length; i++) {
135:                        try {
136:                            resolvedInterfaces[i] = Class.forName(
137:                                    interfaces[i], false, this .classLoader);
138:                        } catch (ClassNotFoundException ex) {
139:                            if (this .codebaseUrl == null) {
140:                                throw ex;
141:                            }
142:                            resolvedInterfaces[i] = RMIClassLoader.loadClass(
143:                                    this .codebaseUrl, interfaces[i]);
144:                        }
145:                    }
146:                    try {
147:                        return Proxy.getProxyClass(this .classLoader,
148:                                resolvedInterfaces);
149:                    } catch (IllegalArgumentException ex) {
150:                        throw new ClassNotFoundException(null, ex);
151:                    }
152:                } else {
153:                    // Let RMI use it's default ClassLoader...
154:                    try {
155:                        return super .resolveProxyClass(interfaces);
156:                    } catch (ClassNotFoundException ex) {
157:                        if (this .codebaseUrl == null) {
158:                            throw ex;
159:                        }
160:                        ClassLoader loader = RMIClassLoader
161:                                .getClassLoader(this .codebaseUrl);
162:                        Class[] resolvedInterfaces = new Class[interfaces.length];
163:                        for (int i = 0; i < interfaces.length; i++) {
164:                            resolvedInterfaces[i] = loader
165:                                    .loadClass(interfaces[i]);
166:                        }
167:                        return Proxy.getProxyClass(loader, resolvedInterfaces);
168:                    }
169:                }
170:            }
171:
172:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.