src/share/jaxws_classes/com/sun/xml/internal/bind/v2/model/impl/Utils.java

changeset 567
7d8cd27f1543
parent 450
b0c2840e2513
child 637
9c07ef4934dd
child 721
06807f9a6835
equal deleted inserted replaced
564:c2c073f04f05 567:7d8cd27f1543
1 /* 1 /*
2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 2 * Copyright (c) 2013, 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
29 29
30 import java.lang.reflect.Field; 30 import java.lang.reflect.Field;
31 import java.lang.reflect.InvocationTargetException; 31 import java.lang.reflect.InvocationTargetException;
32 import java.lang.reflect.Method; 32 import java.lang.reflect.Method;
33 import java.lang.reflect.Type; 33 import java.lang.reflect.Type;
34 import java.security.AccessController;
35 import java.security.PrivilegedAction;
34 import java.util.logging.Level; 36 import java.util.logging.Level;
35 import java.util.logging.Logger; 37 import java.util.logging.Logger;
36 38
37 /** 39 /**
38 * Utils class. 40 * Utils class.
39 * Has *package private* access to avoid inappropriate usage. 41 * Has *package private* access to avoid inappropriate usage.
40 */ 42 */
41 /* package */ final class Utils { 43 final class Utils {
42 44
43 private static final Logger LOGGER = Logger.getLogger(Utils.class.getName()); 45 private static final Logger LOGGER = Logger.getLogger(Utils.class.getName());
44 46
45 /** 47 /**
46 * static ReflectionNavigator field to avoid usage of reflection every time we use it. 48 * static ReflectionNavigator field to avoid usage of reflection every time we use it.
47 */ 49 */
48 /* package */ static final Navigator<Type, Class, Field, Method> REFLECTION_NAVIGATOR; 50 static final Navigator<Type, Class, Field, Method> REFLECTION_NAVIGATOR;
49 51
50 static { // we statically initializing REFLECTION_NAVIGATOR property 52 static { // we statically initializing REFLECTION_NAVIGATOR property
51 Class refNav = null;
52 try { 53 try {
53 refNav = Class.forName("com.sun.xml.internal.bind.v2.model.nav.ReflectionNavigator"); 54 Class refNav = Class.forName("com.sun.xml.internal.bind.v2.model.nav.ReflectionNavigator");
54 //noinspection unchecked 55 //noinspection unchecked
55 Method getInstance = refNav.getDeclaredMethod("getInstance"); 56 final Method getInstance = refNav.getDeclaredMethod("getInstance");
56 getInstance.setAccessible(true); 57
58 // requires accessClassInPackage privilege
59 AccessController.doPrivileged(
60 new PrivilegedAction<Object>() {
61 @Override
62 public Object run() {
63 getInstance.setAccessible(true);
64 return null;
65 }
66 }
67 );
68
57 //noinspection unchecked 69 //noinspection unchecked
58 REFLECTION_NAVIGATOR = (Navigator<Type, Class, Field, Method>) getInstance.invoke(null); 70 REFLECTION_NAVIGATOR = (Navigator<Type, Class, Field, Method>) getInstance.invoke(null);
59 } catch (ClassNotFoundException e) { 71 } catch (ClassNotFoundException e) {
60 e.printStackTrace(); 72 e.printStackTrace();
61 throw new IllegalStateException("Can't find ReflectionNavigator class"); 73 throw new IllegalStateException("Can't find ReflectionNavigator class");

mercurial