Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/hibernate/bytecode/cglib/InstantiationOptimizerAdapter.java


1   package org.hibernate.bytecode.cglib;
2   
3   import org.hibernate.bytecode.ReflectionOptimizer;
4   import net.sf.cglib.reflect.FastClass;
5   import org.hibernate.InstantiationException;
6   
7   import java.io.Serializable;
8   import java.io.ObjectOutputStream;
9   import java.io.IOException;
10  import java.io.ObjectInputStream;
11  
12  /**
13   * The {@link ReflectionOptimizer.InstantiationOptimizer} implementation for CGLIB
14   * which simply acts as an adpater to the {@link FastClass} class.
15   *
16   * @author Steve Ebersole
17   */
18  public class InstantiationOptimizerAdapter implements ReflectionOptimizer.InstantiationOptimizer, Serializable {
19    private FastClass fastClass;
20  
21    public InstantiationOptimizerAdapter(FastClass fastClass) {
22      this.fastClass = fastClass;
23    }
24  
25    public Object newInstance() {
26      try {
27        return fastClass.newInstance();
28      }
29      catch ( Throwable t ) {
30        throw new InstantiationException(
31            "Could not instantiate entity with CGLIB optimizer: ",
32                fastClass.getJavaClass(),
33                t
34        );
35      }
36    }
37  
38    private void writeObject(ObjectOutputStream out) throws IOException {
39      out.writeObject( fastClass.getJavaClass() );
40    }
41  
42    private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
43      Class beanClass = ( Class ) in.readObject();
44      fastClass = FastClass.create( beanClass );
45    }
46  }