src/share/jaxws_classes/com/sun/xml/internal/bind/api/Utils.java

Fri, 24 Oct 2014 15:02:28 +0200

author
mkos
date
Fri, 24 Oct 2014 15:02:28 +0200
changeset 721
06807f9a6835
parent 567
7d8cd27f1543
child 760
e530533619ec
permissions
-rw-r--r--

8054367: More references for endpoints
Summary: fix also reviewed by Iaroslav.Savytskyi@oracle.com, Alexander.Fomin@oracle.com
Reviewed-by: mullan, skoivu

mkos@450 1 /*
mkos@567 2 * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
mkos@450 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
mkos@450 4 *
mkos@450 5 * This code is free software; you can redistribute it and/or modify it
mkos@450 6 * under the terms of the GNU General Public License version 2 only, as
mkos@450 7 * published by the Free Software Foundation. Oracle designates this
mkos@450 8 * particular file as subject to the "Classpath" exception as provided
mkos@450 9 * by Oracle in the LICENSE file that accompanied this code.
mkos@450 10 *
mkos@450 11 * This code is distributed in the hope that it will be useful, but WITHOUT
mkos@450 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
mkos@450 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
mkos@450 14 * version 2 for more details (a copy is included in the LICENSE file that
mkos@450 15 * accompanied this code).
mkos@450 16 *
mkos@450 17 * You should have received a copy of the GNU General Public License version
mkos@450 18 * 2 along with this work; if not, write to the Free Software Foundation,
mkos@450 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
mkos@450 20 *
mkos@450 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
mkos@450 22 * or visit www.oracle.com if you need additional information or have any
mkos@450 23 * questions.
mkos@450 24 */
mkos@450 25
mkos@450 26 package com.sun.xml.internal.bind.api;
mkos@450 27
mkos@450 28 import com.sun.xml.internal.bind.v2.model.nav.Navigator;
mkos@450 29
mkos@450 30 import java.lang.reflect.Field;
mkos@450 31 import java.lang.reflect.InvocationTargetException;
mkos@450 32 import java.lang.reflect.Method;
mkos@450 33 import java.lang.reflect.Type;
mkos@567 34 import java.security.AccessController;
mkos@567 35 import java.security.PrivilegedAction;
mkos@450 36 import java.util.logging.Level;
mkos@450 37 import java.util.logging.Logger;
mkos@450 38
mkos@450 39 /**
mkos@450 40 * Utils class.
mkos@721 41 *
mkos@721 42 * WARNING: If you are doing any changes don't forget to change other Utils classes in different packages.
mkos@721 43 *
mkos@450 44 * Has *package private* access to avoid inappropriate usage.
mkos@450 45 */
mkos@567 46 final class Utils {
mkos@450 47
mkos@450 48 private static final Logger LOGGER = Logger.getLogger(Utils.class.getName());
mkos@450 49
mkos@450 50 /**
mkos@450 51 * static ReflectionNavigator field to avoid usage of reflection every time we use it.
mkos@450 52 */
mkos@567 53 static final Navigator<Type, Class, Field, Method> REFLECTION_NAVIGATOR;
mkos@450 54
mkos@450 55 static { // we statically initializing REFLECTION_NAVIGATOR property
mkos@450 56 try {
mkos@721 57 final Class refNav = Class.forName("com.sun.xml.internal.bind.v2.model.nav.ReflectionNavigator");
mkos@567 58
mkos@567 59 // requires accessClassInPackage privilege
mkos@721 60 final Method getInstance = AccessController.doPrivileged(
mkos@721 61 new PrivilegedAction<Method>() {
mkos@567 62 @Override
mkos@721 63 public Method run() {
mkos@721 64 try {
mkos@721 65 Method getInstance = refNav.getDeclaredMethod("getInstance");
mkos@721 66 getInstance.setAccessible(true);
mkos@721 67 return getInstance;
mkos@721 68 } catch (NoSuchMethodException e) {
mkos@721 69 throw new IllegalStateException("ReflectionNavigator.getInstance can't be found");
mkos@721 70 }
mkos@567 71 }
mkos@567 72 }
mkos@567 73 );
mkos@567 74
mkos@450 75 //noinspection unchecked
mkos@450 76 REFLECTION_NAVIGATOR = (Navigator<Type, Class, Field, Method>) getInstance.invoke(null);
mkos@450 77 } catch (ClassNotFoundException e) {
mkos@450 78 throw new IllegalStateException("Can't find ReflectionNavigator class");
mkos@450 79 } catch (InvocationTargetException e) {
mkos@450 80 throw new IllegalStateException("ReflectionNavigator.getInstance throws the exception");
mkos@450 81 } catch (IllegalAccessException e) {
mkos@450 82 throw new IllegalStateException("ReflectionNavigator.getInstance method is inaccessible");
mkos@450 83 } catch (SecurityException e) {
mkos@450 84 LOGGER.log(Level.FINE, "Unable to access ReflectionNavigator.getInstance", e);
mkos@450 85 throw e;
mkos@450 86 }
mkos@450 87 }
mkos@450 88
mkos@450 89 /**
mkos@450 90 * private constructor to avoid util class instantiating
mkos@450 91 */
mkos@450 92 private Utils() {
mkos@450 93 }
mkos@450 94 }

mercurial