View Javadoc
1   package org.pojomatic.internal;
2   
3   public class ClassDefinerFactory {
4     private static volatile ClassDefiner CLASS_DEFINER;
5     private final static Object MUTEX = new Object();
6   
7     // Avoid initializing when the class is first loaded, so that any exceptions don't get masked as NoClassDefFoundErrors
8     public static ClassDefiner getDefiner() {
9       if (CLASS_DEFINER == null) {
10        synchronized (MUTEX) {
11          if (CLASS_DEFINER == null) {
12            CLASS_DEFINER = makeDefiner();
13          }
14        }
15      }
16      return CLASS_DEFINER;
17    }
18  
19    private static ClassDefiner makeDefiner() {
20      try {
21        return (ClassDefiner) ClassDefiner.class.getClassLoader().loadClass("org.pojomatic.internal.LookupClassDefiner")
22          .getConstructor()
23          .newInstance();
24      } catch (ReflectiveOperationException | UnsupportedClassVersionError e) {
25        return new ClassLoaderClassDefiner();
26      }
27    }
28  }