01: package org.drools.objenesis.instantiator.sun;
02:
03: import java.io.ObjectInputStream;
04: import java.lang.reflect.Method;
05:
06: import org.drools.objenesis.ObjenesisException;
07: import org.drools.objenesis.instantiator.ObjectInstantiator;
08:
09: /**
10: * Base class for Sun 1.3 based instantiators. It initializes reflection access to static method
11: * ObjectInputStream.allocateNewObject.
12: *
13: * @author Leonardo Mesquita
14: */
15: public abstract class Sun13InstantiatorBase implements
16: ObjectInstantiator {
17: protected static Method allocateNewObjectMethod = null;
18:
19: private static void initialize() {
20: if (allocateNewObjectMethod == null) {
21: try {
22: allocateNewObjectMethod = ObjectInputStream.class
23: .getDeclaredMethod(
24: "allocateNewObject",
25: new Class[] { Class.class, Class.class });
26: allocateNewObjectMethod.setAccessible(true);
27: } catch (final Exception e) {
28: throw new ObjenesisException(e);
29: }
30: }
31: }
32:
33: protected final Class type;
34:
35: public Sun13InstantiatorBase(final Class type) {
36: this .type = type;
37: initialize();
38: }
39:
40: public abstract Object newInstance();
41:
42: }
|