equal
deleted
inserted
replaced
1 /* |
1 /* |
2 * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
156 |
156 |
157 try { |
157 try { |
158 Class spFactory = ServiceLoaderUtil.safeLoadClass(className, PLATFORM_DEFAULT_FACTORY_CLASS, classLoader); |
158 Class spFactory = ServiceLoaderUtil.safeLoadClass(className, PLATFORM_DEFAULT_FACTORY_CLASS, classLoader); |
159 return newInstance(contextPath, spFactory, classLoader, properties); |
159 return newInstance(contextPath, spFactory, classLoader, properties); |
160 } catch (ClassNotFoundException x) { |
160 } catch (ClassNotFoundException x) { |
161 throw new JAXBException(Messages.format(Messages.PROVIDER_NOT_FOUND, className), x); |
161 throw new JAXBException(Messages.format(Messages.DEFAULT_PROVIDER_NOT_FOUND), x); |
162 |
162 |
163 } catch (RuntimeException | JAXBException x) { |
163 } catch (RuntimeException | JAXBException x) { |
164 // avoid wrapping RuntimeException to JAXBException, |
164 // avoid wrapping RuntimeException to JAXBException, |
165 // because it indicates a bug in this code. |
165 // because it indicates a bug in this code. |
166 // JAXBException re-thrown as is |
166 // JAXBException re-thrown as is |
226 // some other type of exception - just wrap it |
226 // some other type of exception - just wrap it |
227 throw new JAXBException(Messages.format(Messages.COULD_NOT_INSTANTIATE, spFactory, x), x); |
227 throw new JAXBException(Messages.format(Messages.COULD_NOT_INSTANTIATE, spFactory, x), x); |
228 } |
228 } |
229 } |
229 } |
230 |
230 |
231 private static Object instantiateProviderIfNecessary(Class<?> implClass) throws JAXBException { |
231 private static Object instantiateProviderIfNecessary(final Class<?> implClass) throws JAXBException { |
232 try { |
232 try { |
233 if (JAXBContextFactory.class.isAssignableFrom(implClass)) { |
233 if (JAXBContextFactory.class.isAssignableFrom(implClass)) { |
234 return AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() { |
234 return AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() { |
235 @Override |
235 @Override |
236 public Object run() throws Exception { |
236 public Object run() throws Exception { |
252 |
252 |
253 Class spi; |
253 Class spi; |
254 try { |
254 try { |
255 spi = ServiceLoaderUtil.safeLoadClass(className, PLATFORM_DEFAULT_FACTORY_CLASS, getContextClassLoader()); |
255 spi = ServiceLoaderUtil.safeLoadClass(className, PLATFORM_DEFAULT_FACTORY_CLASS, getContextClassLoader()); |
256 } catch (ClassNotFoundException e) { |
256 } catch (ClassNotFoundException e) { |
257 throw new JAXBException(e); |
257 throw new JAXBException(Messages.format(Messages.DEFAULT_PROVIDER_NOT_FOUND), e); |
258 } |
258 } |
259 |
259 |
260 if (logger.isLoggable(Level.FINE)) { |
260 if (logger.isLoggable(Level.FINE)) { |
261 // extra check to avoid costly which operation if not logged |
261 // extra check to avoid costly which operation if not logged |
262 logger.log(Level.FINE, "loaded {0} from {1}", new Object[]{className, which(spi)}); |
262 logger.log(Level.FINE, "loaded {0} from {1}", new Object[]{className, which(spi)}); |
523 if (System.getSecurityManager() == null) { |
523 if (System.getSecurityManager() == null) { |
524 return Thread.currentThread().getContextClassLoader(); |
524 return Thread.currentThread().getContextClassLoader(); |
525 } else { |
525 } else { |
526 return (ClassLoader) java.security.AccessController.doPrivileged( |
526 return (ClassLoader) java.security.AccessController.doPrivileged( |
527 new java.security.PrivilegedAction() { |
527 new java.security.PrivilegedAction() { |
|
528 @Override |
528 public java.lang.Object run() { |
529 public java.lang.Object run() { |
529 return Thread.currentThread().getContextClassLoader(); |
530 return Thread.currentThread().getContextClassLoader(); |
530 } |
531 } |
531 }); |
532 }); |
532 } |
533 } |
537 if (System.getSecurityManager() == null) { |
538 if (System.getSecurityManager() == null) { |
538 return c.getClassLoader(); |
539 return c.getClassLoader(); |
539 } else { |
540 } else { |
540 return (ClassLoader) java.security.AccessController.doPrivileged( |
541 return (ClassLoader) java.security.AccessController.doPrivileged( |
541 new java.security.PrivilegedAction() { |
542 new java.security.PrivilegedAction() { |
|
543 @Override |
542 public java.lang.Object run() { |
544 public java.lang.Object run() { |
543 return c.getClassLoader(); |
545 return c.getClassLoader(); |
544 } |
546 } |
545 }); |
547 }); |
546 } |
548 } |
550 if (System.getSecurityManager() == null) { |
552 if (System.getSecurityManager() == null) { |
551 return ClassLoader.getSystemClassLoader(); |
553 return ClassLoader.getSystemClassLoader(); |
552 } else { |
554 } else { |
553 return (ClassLoader) java.security.AccessController.doPrivileged( |
555 return (ClassLoader) java.security.AccessController.doPrivileged( |
554 new java.security.PrivilegedAction() { |
556 new java.security.PrivilegedAction() { |
|
557 @Override |
555 public java.lang.Object run() { |
558 public java.lang.Object run() { |
556 return ClassLoader.getSystemClassLoader(); |
559 return ClassLoader.getSystemClassLoader(); |
557 } |
560 } |
558 }); |
561 }); |
559 } |
562 } |