Java Code Examples for sun.reflect.ReflectionFactory#getReflectionFactory()

The following examples show how to use sun.reflect.ReflectionFactory#getReflectionFactory() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PluginConfigFactory.java    From sylph with Apache License 2.0 6 votes vote down vote up
public static <T extends PluginConfig> T pluginConfigInstance(Class<T> type)
        throws IllegalAccessException, InvocationTargetException, InstantiationException, NoSuchMethodException
{
    checkState(!Modifier.isAbstract(type.getModifiers()), "%s is Interface or Abstract, unable to inject", type);

    //Ignore the constructor in the configuration class
    try {
        Constructor<T> pluginConfigConstructor = type.getDeclaredConstructor();
        logger.debug("find 'no parameter' constructor with [{}]", type);
        pluginConfigConstructor.setAccessible(true);
        return pluginConfigConstructor.newInstance();
    }
    catch (NoSuchMethodException e) {
        logger.warn("Not find 'no parameter' constructor, use javassist inject with [{}]", type);
        // copy proxyConfig field value to pluginConfig ...
        Constructor superCons = Object.class.getConstructor();
        ReflectionFactory reflFactory = ReflectionFactory.getReflectionFactory();
        Constructor<?> c = reflFactory.newConstructorForSerialization(type, superCons);
        // or use unsafe, demo: PluginConfig pluginConfig = (PluginConfig) unsafe.allocateInstance(type)
        @SuppressWarnings("unchecked")
        T pluginConfig = (T) c.newInstance();
        return pluginConfig;
    }
}
 
Example 2
Source File: UnsafeHelper.java    From gadtry with Apache License 2.0 5 votes vote down vote up
public static <T> T allocateInstance2(Class<T> tClass)
        throws InstantiationException, NoSuchMethodException, InvocationTargetException, IllegalAccessException
{
    Constructor superCons = Object.class.getConstructor();
    ReflectionFactory reflFactory = ReflectionFactory.getReflectionFactory();
    Constructor c = reflFactory.newConstructorForSerialization(tClass, superCons);
    return (T) c.newInstance();
}
 
Example 3
Source File: MirrorValuesApp.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static URL createPristineURL() {
    // Creates a pristine, incomplete URL object, that gets created when we
    // step into new URL(), for instance.
    ReflectionFactory rf = ReflectionFactory.getReflectionFactory();
    try {
        Constructor constructor = rf.newConstructorForSerialization(URL.class, Object.class.getDeclaredConstructor());
        Object newInstance = constructor.newInstance();
        return (URL) newInstance;
    } catch (Exception ex) {
        ex.printStackTrace();
        return null;
    }
}
 
Example 4
Source File: CreateObject.java    From objenesis with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private Constructor<Object> getConstructor() {
   try {
      ReflectionFactory factory = ReflectionFactory.getReflectionFactory();
      Constructor<Object> objectConstructor =type.getConstructor((Class[]) null);
      Constructor<Object> c = (Constructor<Object>) factory.newConstructorForSerialization(type, objectConstructor);
      return c;
   } catch (Exception e) {
      throw new RuntimeException(e);
   }
}
 
Example 5
Source File: ReflectionFactoryTest.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
@BeforeClass
static void init() {
    factory = ReflectionFactory.getReflectionFactory();
}
 
Example 6
Source File: ReflectionFactoryTest.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
@BeforeClass
static void init() {
    factory = ReflectionFactory.getReflectionFactory();
}
 
Example 7
Source File: ReflectionFactoryTest.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
@BeforeClass
static void init() {
    factory = ReflectionFactory.getReflectionFactory();
}
 
Example 8
Source File: ReflectionFactoryTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
@BeforeClass
static void init() {
    factory = ReflectionFactory.getReflectionFactory();
}
 
Example 9
Source File: Bridge.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
private Bridge() {
    reflectionFactory = ReflectionFactory.getReflectionFactory();
    stackWalker  = StackWalker.getInstance(
                        StackWalker.Option.RETAIN_CLASS_REFERENCE);
}
 
Example 10
Source File: ReflectionFactoryTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@BeforeClass
static void init() {
    factory = ReflectionFactory.getReflectionFactory();
}
 
Example 11
Source File: ReflectionFactoryTest.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
@BeforeClass
static void init() {
    factory = ReflectionFactory.getReflectionFactory();
}
 
Example 12
Source File: ObjectFactoryBuilderReflection.java    From baratine with GNU General Public License v2.0 4 votes vote down vote up
ObjectFactoryBuilderReflection() throws NoSuchMethodException
{
  _reflectionFactory = ReflectionFactory.getReflectionFactory();
  _baseConstructor = Object.class.getDeclaredConstructor();
}
 
Example 13
Source File: ReflectionFactoryTest.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
@BeforeClass
static void init() {
    factory = ReflectionFactory.getReflectionFactory();
}