Package org.drools.objenesis.instantiator.gcj

Source Code of org.drools.objenesis.instantiator.gcj.GCJInstantiatorBase

package org.drools.objenesis.instantiator.gcj;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.lang.reflect.Method;

import org.drools.objenesis.ObjenesisException;
import org.drools.objenesis.instantiator.ObjectInstantiator;

/**
* Base class for GCJ-based instantiators. It initializes reflection access to method
* ObjectInputStream.newObject, as well as creating a dummy ObjectInputStream to be used as the
* "this" argument for the method.
*
* @author Leonardo Mesquita
*/
public abstract class GCJInstantiatorBase
    implements
    ObjectInstantiator {
    protected static Method            newObjectMethod = null;
    protected static ObjectInputStream dummyStream;

    private static class DummyStream extends ObjectInputStream {
        public DummyStream() throws IOException {
            super();
        }
    }

    private static void initialize() {
        if ( newObjectMethod == null ) {
            try {
                newObjectMethod = ObjectInputStream.class.getDeclaredMethod( "newObject",
                                                                             new Class[]{Class.class, Class.class} );
                newObjectMethod.setAccessible( true );
                dummyStream = new DummyStream();
            } catch ( final Exception e ) {
                throw new ObjenesisException( e );
            }
        }
    }

    protected final Class type;

    public GCJInstantiatorBase(final Class type) {
        this.type = type;
        initialize();
    }

    public abstract Object newInstance();
}
TOP

Related Classes of org.drools.objenesis.instantiator.gcj.GCJInstantiatorBase

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.
m/analytics.js','ga'); ga('create', 'UA-20639858-1', 'auto'); ga('send', 'pageview');