Source Code Cross Referenced for RMIClassLoader.java in  » Apache-Harmony-Java-SE » java-package » java » rmi » server » 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 » Apache Harmony Java SE » java package » java.rmi.server 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         *
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         *
015:         * See the License for the specific language governing permissions and
016:         * limitations under the License.
017:         */
018:
019:        /**
020:         * @author  Mikhail A. Markov
021:         * @version $Revision: 1.8.4.2 $
022:         */package java.rmi.server;
023:
024:        import java.io.InputStream;
025:        import java.io.IOException;
026:        import java.util.StringTokenizer;
027:        import java.net.MalformedURLException;
028:        import java.net.URL;
029:        import java.security.AccessController;
030:        import java.security.PrivilegedAction;
031:
032:        import org.apache.harmony.rmi.DefaultRMIClassLoaderSpi;
033:        import org.apache.harmony.rmi.internal.nls.Messages;
034:
035:        /**
036:         * @com.intel.drl.spec_ref
037:         * This class could not be instantiated.
038:         *
039:         * @author  Mikhail A. Markov
040:         * @version $Revision: 1.8.4.2 $
041:         */
042:        public class RMIClassLoader {
043:
044:            // The name of property for custom RMIClassLoaderSpi.
045:            private static final String spiProp = "java.rmi.server.RMIClassLoaderSpi"; //$NON-NLS-1$
046:
047:            // The name of resource for custom RMIClassLoaderSpi.
048:            private static final String spiResource = "META-INF/services/java.rmi.server.RMIClassLoaderSpi"; //$NON-NLS-1$
049:
050:            /*
051:             * Default RMIClassLoaderSpi instance.
052:             */
053:            private static RMIClassLoaderSpi defaultSpi = new DefaultRMIClassLoaderSpi();
054:
055:            /*
056:             * Implementation of RMIClassLoaderSpi which will be used for delegating
057:             * method calls of this class to.
058:             */
059:            private static RMIClassLoaderSpi activeSpi = (RMIClassLoaderSpi) AccessController
060:                    .doPrivileged(new PrivilegedAction<Object>() {
061:                        public Object run() {
062:                            return initActiveSpi();
063:                        }
064:                    });
065:
066:            // This class could not be instantiated.
067:            private RMIClassLoader() {
068:            }
069:
070:            /**
071:             * @com.intel.drl.spec_ref
072:             */
073:            public static Class<?> loadProxyClass(String codebase,
074:                    String[] interf, ClassLoader defaultCl)
075:                    throws ClassNotFoundException, MalformedURLException {
076:                return activeSpi.loadProxyClass(codebase, interf, defaultCl);
077:            }
078:
079:            /**
080:             * @com.intel.drl.spec_ref
081:             */
082:            public static Class<?> loadClass(String codebase, String name,
083:                    ClassLoader defaultCl) throws MalformedURLException,
084:                    ClassNotFoundException {
085:                return activeSpi.loadClass(codebase, name, defaultCl);
086:            }
087:
088:            /**
089:             * @com.intel.drl.spec_ref
090:             */
091:            public static Class<?> loadClass(URL codebase, String name)
092:                    throws MalformedURLException, ClassNotFoundException {
093:                return activeSpi.loadClass((codebase == null) ? null : codebase
094:                        .toString(), name, null);
095:            }
096:
097:            /**
098:             * @com.intel.drl.spec_ref
099:             */
100:            public static Class<?> loadClass(String codebase, String name)
101:                    throws MalformedURLException, ClassNotFoundException {
102:                return activeSpi.loadClass(codebase, name, null);
103:            }
104:
105:            /**
106:             * @com.intel.drl.spec_ref
107:             */
108:            public static String getClassAnnotation(Class<?> cl) {
109:                return activeSpi.getClassAnnotation(cl);
110:            }
111:
112:            /**
113:             * @com.intel.drl.spec_ref
114:             * It's depricated so we just return null.
115:             * @deprecated since Java v1.2 this method is no longer used by RMI
116:             *  framework
117:             */
118:            @Deprecated
119:            public static Object getSecurityContext(ClassLoader loader) {
120:                return null;
121:            }
122:
123:            /**
124:             * @com.intel.drl.spec_ref
125:             */
126:            public static ClassLoader getClassLoader(String codebase)
127:                    throws MalformedURLException, SecurityException {
128:                return activeSpi.getClassLoader(codebase);
129:            }
130:
131:            /**
132:             * @com.intel.drl.spec_ref
133:             * @deprecated method loadClass(String, String) should be used instead
134:             */
135:            @Deprecated
136:            public static Class<?> loadClass(String name)
137:                    throws MalformedURLException, ClassNotFoundException {
138:                return loadClass((String) null, name);
139:            }
140:
141:            /**
142:             * @com.intel.drl.spec_ref
143:             */
144:            public static RMIClassLoaderSpi getDefaultProviderInstance() {
145:                SecurityManager mgr = System.getSecurityManager();
146:
147:                if (mgr != null) {
148:                    mgr.checkPermission(new RuntimePermission("setFactory")); //$NON-NLS-1$
149:                }
150:                return defaultSpi;
151:            }
152:
153:            /*
154:             * Initialize active RMIClassLoaderSpi.
155:             */
156:            private static RMIClassLoaderSpi initActiveSpi() {
157:                String spi = System.getProperty(spiProp);
158:
159:                if (spi != null) {
160:                    if (spi.equals("default")) { //$NON-NLS-1$
161:                        return defaultSpi;
162:                    }
163:
164:                    try {
165:                        return (RMIClassLoaderSpi) (Class.forName(spi, false,
166:                                ClassLoader.getSystemClassLoader())
167:                                .newInstance());
168:                    } catch (Exception ex) {
169:                        // rmi.1B=Unable to initialize RMIClassLoaderSpi instance {0}, specified in {1} property
170:                        throw new Error(Messages.getString(
171:                                "rmi.1B", spi, spiProp), ex); //$NON-NLS-1$
172:                    }
173:                }
174:
175:                try {
176:                    spi = getSpiFromResource();
177:                } catch (IOException ioe) {
178:                    // rmi.1C=Unable to get RMIClassLoaderSpi name from resource {0}
179:                    throw new Error(
180:                            Messages.getString("rmi.1C", spiResource), ioe); //$NON-NLS-1$
181:                }
182:
183:                if (spi != null) {
184:                    try {
185:                        return (RMIClassLoaderSpi) (Class.forName(spi, true,
186:                                ClassLoader.getSystemClassLoader())
187:                                .newInstance());
188:                    } catch (Exception ex) {
189:                        // rmi.1D=Unable to initialize RMIClassLoaderSpi instance {0}, specified in {1} resource
190:                        throw new Error(Messages.getString(
191:                                "rmi.1D", spi, spiResource), ex); //$NON-NLS-1$
192:                    }
193:                }
194:                return defaultSpi;
195:            }
196:
197:            /*
198:             * Returns provider obtained from default resource.
199:             *
200:             * @return provider obtained from default resource
201:             *
202:             * @throws IOException if any I/O error occurred while trying to read
203:             *         provider name from default resource
204:             */
205:            private static String getSpiFromResource() throws IOException {
206:                InputStream in = ClassLoader.getSystemClassLoader()
207:                        .getResourceAsStream(spiResource);
208:
209:                if (in == null) {
210:                    // resource not found
211:                    return null;
212:                }
213:                Object obj = null;
214:                byte[] buf = new byte[in.available()];
215:                in.read(buf);
216:                String str = new String(buf, "UTF-8"); //$NON-NLS-1$
217:                StringTokenizer tok = new StringTokenizer(str, "\n\r"); //$NON-NLS-1$
218:
219:                while (tok.hasMoreTokens()) {
220:                    String spiName = tok.nextToken();
221:                    int idx = spiName.indexOf("#"); //$NON-NLS-1$
222:
223:                    if (idx != -1) {
224:                        // this is commented line
225:                        spiName = spiName.substring(0, idx);
226:                    }
227:                    spiName = spiName.trim();
228:
229:                    if (spiName.length() > 0) {
230:                        // not empty line
231:                        return spiName;
232:                    }
233:
234:                    // skip empty line
235:                }
236:
237:                // we did not found any uncommented non-empty lines
238:                return ""; //$NON-NLS-1$
239:            }
240:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.