22427
|
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 |
*/
|
|
25 |
|
|
26 |
package com.sun.xml.internal.bind.v2.runtime;
|
|
27 |
|
|
28 |
import com.sun.xml.internal.bind.v2.model.nav.Navigator;
|
|
29 |
|
|
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;
|
|
36 |
|
|
37 |
/**
|
|
38 |
* Utils class.
|
|
39 |
* Has *package private* access to avoid inappropriate usage.
|
|
40 |
*/
|
|
41 |
/* package */ final class Utils {
|
|
42 |
|
|
43 |
private static final Logger LOGGER = Logger.getLogger(Utils.class.getName());
|
|
44 |
|
|
45 |
/**
|
|
46 |
* static ReflectionNavigator field to avoid usage of reflection every time we use it.
|
|
47 |
*/
|
|
48 |
/* package */ static final Navigator<Type, Class, Field, Method> REFLECTION_NAVIGATOR;
|
|
49 |
|
|
50 |
static { // we statically initializing REFLECTION_NAVIGATOR property
|
|
51 |
Class refNav = null;
|
|
52 |
try {
|
|
53 |
refNav = Class.forName("com.sun.xml.internal.bind.v2.model.nav.ReflectionNavigator");
|
|
54 |
//noinspection unchecked
|
|
55 |
Method getInstance = refNav.getDeclaredMethod("getInstance");
|
|
56 |
getInstance.setAccessible(true);
|
|
57 |
//noinspection unchecked
|
|
58 |
REFLECTION_NAVIGATOR = (Navigator<Type, Class, Field, Method>) getInstance.invoke(null);
|
|
59 |
} catch (ClassNotFoundException e) {
|
|
60 |
e.printStackTrace();
|
|
61 |
throw new IllegalStateException("Can't find ReflectionNavigator class");
|
|
62 |
} catch (InvocationTargetException e) {
|
|
63 |
e.printStackTrace();
|
|
64 |
throw new IllegalStateException("ReflectionNavigator.getInstance throws the exception");
|
|
65 |
} catch (NoSuchMethodException e) {
|
|
66 |
e.printStackTrace();
|
|
67 |
throw new IllegalStateException("ReflectionNavigator.getInstance can't be found");
|
|
68 |
} catch (IllegalAccessException e) {
|
|
69 |
e.printStackTrace();
|
|
70 |
throw new IllegalStateException("ReflectionNavigator.getInstance method is inaccessible");
|
|
71 |
} catch (SecurityException e) {
|
|
72 |
LOGGER.log(Level.FINE, "Unable to access ReflectionNavigator.getInstance", e);
|
|
73 |
throw e;
|
|
74 |
}
|
|
75 |
}
|
|
76 |
|
|
77 |
/**
|
|
78 |
* private constructor to avoid util class instantiating
|
|
79 |
*/
|
|
80 |
private Utils() {
|
|
81 |
}
|
|
82 |
}
|