49 */ |
52 */ |
50 static final Navigator<Type, Class, Field, Method> REFLECTION_NAVIGATOR; |
53 static final Navigator<Type, Class, Field, Method> REFLECTION_NAVIGATOR; |
51 |
54 |
52 static { // we statically initializing REFLECTION_NAVIGATOR property |
55 static { // we statically initializing REFLECTION_NAVIGATOR property |
53 try { |
56 try { |
54 Class refNav = Class.forName("com.sun.xml.internal.bind.v2.model.nav.ReflectionNavigator"); |
57 final Class refNav = Class.forName("com.sun.xml.internal.bind.v2.model.nav.ReflectionNavigator"); |
55 //noinspection unchecked |
|
56 final Method getInstance = refNav.getDeclaredMethod("getInstance"); |
|
57 |
58 |
58 // requires accessClassInPackage privilege |
59 // requires accessClassInPackage privilege |
59 AccessController.doPrivileged( |
60 final Method getInstance = AccessController.doPrivileged( |
60 new PrivilegedAction<Object>() { |
61 new PrivilegedAction<Method>() { |
61 @Override |
62 @Override |
62 public Object run() { |
63 public Method run() { |
63 getInstance.setAccessible(true); |
64 try { |
64 return null; |
65 Method getInstance = refNav.getDeclaredMethod("getInstance"); |
|
66 getInstance.setAccessible(true); |
|
67 return getInstance; |
|
68 } catch (NoSuchMethodException e) { |
|
69 throw new IllegalStateException("ReflectionNavigator.getInstance can't be found"); |
|
70 } |
65 } |
71 } |
66 } |
72 } |
67 ); |
73 ); |
68 |
74 |
69 //noinspection unchecked |
75 //noinspection unchecked |
70 REFLECTION_NAVIGATOR = (Navigator<Type, Class, Field, Method>) getInstance.invoke(null); |
76 REFLECTION_NAVIGATOR = (Navigator<Type, Class, Field, Method>) getInstance.invoke(null); |
71 } catch (ClassNotFoundException e) { |
77 } catch (ClassNotFoundException e) { |
72 e.printStackTrace(); |
|
73 throw new IllegalStateException("Can't find ReflectionNavigator class"); |
78 throw new IllegalStateException("Can't find ReflectionNavigator class"); |
74 } catch (InvocationTargetException e) { |
79 } catch (InvocationTargetException e) { |
75 e.printStackTrace(); |
|
76 throw new IllegalStateException("ReflectionNavigator.getInstance throws the exception"); |
80 throw new IllegalStateException("ReflectionNavigator.getInstance throws the exception"); |
77 } catch (NoSuchMethodException e) { |
|
78 e.printStackTrace(); |
|
79 throw new IllegalStateException("ReflectionNavigator.getInstance can't be found"); |
|
80 } catch (IllegalAccessException e) { |
81 } catch (IllegalAccessException e) { |
81 e.printStackTrace(); |
|
82 throw new IllegalStateException("ReflectionNavigator.getInstance method is inaccessible"); |
82 throw new IllegalStateException("ReflectionNavigator.getInstance method is inaccessible"); |
83 } catch (SecurityException e) { |
83 } catch (SecurityException e) { |
84 LOGGER.log(Level.FINE, "Unable to access ReflectionNavigator.getInstance", e); |
84 LOGGER.log(Level.FINE, "Unable to access ReflectionNavigator.getInstance", e); |
85 throw e; |
85 throw e; |
86 } |
86 } |