src/share/jaxws_classes/com/sun/xml/internal/bind/v2/runtime/reflect/Utils.java

changeset 721
06807f9a6835
parent 567
7d8cd27f1543
child 760
e530533619ec
equal deleted inserted replaced
718:246d7e4f3c9f 721:06807f9a6835
36 import java.util.logging.Level; 36 import java.util.logging.Level;
37 import java.util.logging.Logger; 37 import java.util.logging.Logger;
38 38
39 /** 39 /**
40 * Utils class. 40 * Utils class.
41 *
42 * WARNING: If you are doing any changes don't forget to change other Utils classes in different packages.
43 *
41 * Has *package private* access to avoid inappropriate usage. 44 * Has *package private* access to avoid inappropriate usage.
42 */ 45 */
43 final class Utils { 46 final class Utils {
44 47
45 private static final Logger LOGGER = Logger.getLogger(Utils.class.getName()); 48 private static final Logger LOGGER = Logger.getLogger(Utils.class.getName());
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 }

mercurial