Fri, 14 Feb 2014 11:13:45 +0100
8026188: Enhance envelope factory
Summary: Avoiding caching data initialized via TCCL in static context; fix also reviewed by Alexander Fomin
Reviewed-by: ahgross, mgrebac, skoivu
1 /*
2 * Copyright (c) 2013, 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.util.logging.Level;
35 import java.util.logging.Logger;
37 /**
38 * Utils class.
39 *
40 * WARNING: If you are doing any changes don't forget to change other Utils classes in different packages.
41 *
42 * Has *package private* access to avoid inappropriate usage.
43 */
44 /* package */ final class Utils {
46 private static final Logger LOGGER = Logger.getLogger(Utils.class.getName());
48 /**
49 * static ReflectionNavigator field to avoid usage of reflection every time we use it.
50 */
51 /* package */ static final Navigator<Type, Class, Field, Method> REFLECTION_NAVIGATOR;
53 static { // we statically initializing REFLECTION_NAVIGATOR property
54 Class refNav = null;
55 try {
56 refNav = Class.forName("com.sun.xml.internal.bind.v2.model.nav.ReflectionNavigator");
57 //noinspection unchecked
58 Method getInstance = refNav.getDeclaredMethod("getInstance");
59 getInstance.setAccessible(true);
60 //noinspection unchecked
61 REFLECTION_NAVIGATOR = (Navigator<Type, Class, Field, Method>) getInstance.invoke(null);
62 } catch (ClassNotFoundException e) {
63 e.printStackTrace();
64 throw new IllegalStateException("Can't find ReflectionNavigator class");
65 } catch (InvocationTargetException e) {
66 e.printStackTrace();
67 throw new IllegalStateException("ReflectionNavigator.getInstance throws the exception");
68 } catch (NoSuchMethodException e) {
69 e.printStackTrace();
70 throw new IllegalStateException("ReflectionNavigator.getInstance can't be found");
71 } catch (IllegalAccessException e) {
72 e.printStackTrace();
73 throw new IllegalStateException("ReflectionNavigator.getInstance method is inaccessible");
74 } catch (SecurityException e) {
75 LOGGER.log(Level.FINE, "Unable to access ReflectionNavigator.getInstance", e);
76 throw e;
77 }
78 }
80 /**
81 * private constructor to avoid util class instantiating
82 */
83 private Utils() {
84 }
85 }