src/share/jaxws_classes/com/sun/xml/internal/ws/model/Utils.java

Thu, 31 Aug 2017 15:18:52 +0800

author
aoqi
date
Thu, 31 Aug 2017 15:18:52 +0800
changeset 637
9c07ef4934dd
parent 567
7d8cd27f1543
parent 0
373ffda63c9a
child 760
e530533619ec
permissions
-rw-r--r--

merge

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

mercurial