1 /* |
1 /* |
2 * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 1997, 2014, 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 |
334 private static final Class FI_STAX_READER_CLASS = initFIStAXReaderClass(); |
334 private static final Class FI_STAX_READER_CLASS = initFIStAXReaderClass(); |
335 private static final Constructor<? extends StAXConnector> FI_CONNECTOR_CTOR = initFastInfosetConnectorClass(); |
335 private static final Constructor<? extends StAXConnector> FI_CONNECTOR_CTOR = initFastInfosetConnectorClass(); |
336 |
336 |
337 private static Class initFIStAXReaderClass() { |
337 private static Class initFIStAXReaderClass() { |
338 try { |
338 try { |
339 ClassLoader cl = getClassLoader(); |
339 Class<?> fisr = Class.forName("com.sun.xml.internal.org.jvnet.fastinfoset.stax.FastInfosetStreamReader"); |
340 Class fisr = cl.loadClass("com.sun.xml.internal.org.jvnet.fastinfoset.stax.FastInfosetStreamReader"); |
340 Class<?> sdp = Class.forName("com.sun.xml.internal.fastinfoset.stax.StAXDocumentParser"); |
341 Class sdp = cl.loadClass("com.sun.xml.internal.fastinfoset.stax.StAXDocumentParser"); |
|
342 // Check if StAXDocumentParser implements FastInfosetStreamReader |
341 // Check if StAXDocumentParser implements FastInfosetStreamReader |
343 if (fisr.isAssignableFrom(sdp)) |
342 if (fisr.isAssignableFrom(sdp)) |
344 return sdp; |
343 return sdp; |
345 else |
344 else |
346 return null; |
345 return null; |
352 private static Constructor<? extends StAXConnector> initFastInfosetConnectorClass() { |
351 private static Constructor<? extends StAXConnector> initFastInfosetConnectorClass() { |
353 try { |
352 try { |
354 if (FI_STAX_READER_CLASS == null) |
353 if (FI_STAX_READER_CLASS == null) |
355 return null; |
354 return null; |
356 |
355 |
357 Class c = getClassLoader().loadClass( |
356 Class c = Class.forName( |
358 "com.sun.xml.internal.bind.v2.runtime.unmarshaller.FastInfosetConnector"); |
357 "com.sun.xml.internal.bind.v2.runtime.unmarshaller.FastInfosetConnector"); |
359 return c.getConstructor(FI_STAX_READER_CLASS,XmlVisitor.class); |
358 return c.getConstructor(FI_STAX_READER_CLASS,XmlVisitor.class); |
360 } catch (Throwable e) { |
359 } catch (Throwable e) { |
361 return null; |
360 return null; |
362 } |
361 } |
368 private static final Class STAX_EX_READER_CLASS = initStAXExReader(); |
367 private static final Class STAX_EX_READER_CLASS = initStAXExReader(); |
369 private static final Constructor<? extends StAXConnector> STAX_EX_CONNECTOR_CTOR = initStAXExConnector(); |
368 private static final Constructor<? extends StAXConnector> STAX_EX_CONNECTOR_CTOR = initStAXExConnector(); |
370 |
369 |
371 private static Class initStAXExReader() { |
370 private static Class initStAXExReader() { |
372 try { |
371 try { |
373 return getClassLoader().loadClass("com.sun.xml.internal.org.jvnet.staxex.XMLStreamReaderEx"); |
372 return Class.forName("com.sun.xml.internal.org.jvnet.staxex.XMLStreamReaderEx"); |
374 } catch (Throwable e) { |
373 } catch (Throwable e) { |
375 return null; |
374 return null; |
376 } |
375 } |
377 } |
376 } |
378 |
377 |
379 private static Constructor<? extends StAXConnector> initStAXExConnector() { |
378 private static Constructor<? extends StAXConnector> initStAXExConnector() { |
380 try { |
379 try { |
381 Class c = getClassLoader().loadClass("com.sun.xml.internal.bind.v2.runtime.unmarshaller.StAXExConnector"); |
380 Class c = Class.forName("com.sun.xml.internal.bind.v2.runtime.unmarshaller.StAXExConnector"); |
382 return c.getConstructor(STAX_EX_READER_CLASS,XmlVisitor.class); |
381 return c.getConstructor(STAX_EX_READER_CLASS,XmlVisitor.class); |
383 } catch (Throwable e) { |
382 } catch (Throwable e) { |
384 return null; |
383 return null; |
385 } |
384 } |
386 } |
385 } |
387 |
386 |
388 private static ClassLoader getClassLoader() { |
|
389 ClassLoader cl = SecureLoader.getClassClassLoader(UnmarshallerImpl.class); |
|
390 if (cl == null) { |
|
391 cl = SecureLoader.getContextClassLoader(); |
|
392 } |
|
393 return cl; |
|
394 } |
|
395 |
|
396 } |
387 } |