195 // any failure in invoking this method would be considered fatal 196 Object obj = instantiateProviderIfNecessary(spFactory); 197 context = m.invoke(obj, contextPath, classLoader, properties); 198 } catch (NoSuchMethodException ignored) { 199 // it's not an error for the provider not to have this method. 200 } 201 202 if (context == null) { 203 // try the old method that doesn't take properties. compatible with 1.0. 204 // it is an error for an implementation not to have both forms of the createContext method. 205 Method m = spFactory.getMethod("createContext", String.class, ClassLoader.class); 206 Object obj = instantiateProviderIfNecessary(spFactory); 207 // any failure in invoking this method would be considered fatal 208 context = m.invoke(obj, contextPath, classLoader); 209 } 210 211 if (!(context instanceof JAXBContext)) { 212 // the cast would fail, so generate an exception with a nice message 213 throw handleClassCastException(context.getClass(), JAXBContext.class); 214 } 215 return (JAXBContext) context; 216 } catch (InvocationTargetException x) { 217 // throw if it is exception not to be wrapped 218 // otherwise, wrap with a JAXBException 219 Throwable e = handleInvocationTargetException(x); 220 throw new JAXBException(Messages.format(Messages.COULD_NOT_INSTANTIATE, spFactory, e), e); 221 222 } catch (Exception x) { 223 // can't catch JAXBException because the method is hidden behind 224 // reflection. Root element collisions detected in the call to 225 // createContext() are reported as JAXBExceptions - just re-throw it 226 // some other type of exception - just wrap it 227 throw new JAXBException(Messages.format(Messages.COULD_NOT_INSTANTIATE, spFactory, x), x); 228 } 229 } 230 231 private static Object instantiateProviderIfNecessary(final Class<?> implClass) throws JAXBException { 232 try { 233 if (JAXBContextFactory.class.isAssignableFrom(implClass)) { 234 return AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() { | 195 // any failure in invoking this method would be considered fatal 196 Object obj = instantiateProviderIfNecessary(spFactory); 197 context = m.invoke(obj, contextPath, classLoader, properties); 198 } catch (NoSuchMethodException ignored) { 199 // it's not an error for the provider not to have this method. 200 } 201 202 if (context == null) { 203 // try the old method that doesn't take properties. compatible with 1.0. 204 // it is an error for an implementation not to have both forms of the createContext method. 205 Method m = spFactory.getMethod("createContext", String.class, ClassLoader.class); 206 Object obj = instantiateProviderIfNecessary(spFactory); 207 // any failure in invoking this method would be considered fatal 208 context = m.invoke(obj, contextPath, classLoader); 209 } 210 211 if (!(context instanceof JAXBContext)) { 212 // the cast would fail, so generate an exception with a nice message 213 throw handleClassCastException(context.getClass(), JAXBContext.class); 214 } 215 216 ModuleUtil.delegateAddOpensToImplModule(ModuleUtil.getClassesFromContextPath(contextPath, classLoader), spFactory); 217 218 return (JAXBContext) context; 219 } catch (InvocationTargetException x) { 220 // throw if it is exception not to be wrapped 221 // otherwise, wrap with a JAXBException 222 Throwable e = handleInvocationTargetException(x); 223 throw new JAXBException(Messages.format(Messages.COULD_NOT_INSTANTIATE, spFactory, e), e); 224 225 } catch (Exception x) { 226 // can't catch JAXBException because the method is hidden behind 227 // reflection. Root element collisions detected in the call to 228 // createContext() are reported as JAXBExceptions - just re-throw it 229 // some other type of exception - just wrap it 230 throw new JAXBException(Messages.format(Messages.COULD_NOT_INSTANTIATE, spFactory, x), x); 231 } 232 } 233 234 private static Object instantiateProviderIfNecessary(final Class<?> implClass) throws JAXBException { 235 try { 236 if (JAXBContextFactory.class.isAssignableFrom(implClass)) { 237 return AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() { |