/** * Generates the class */ public void buildClassDefinition() { if (!classGenerated) { synchronized (this) { if (!classGenerated) { generateClass(); cleanup(); classGenerated = true; } } } }
/** * Checks if the proxy class is defined in the factories class loader * * @return true if the proxy class already exists */ public boolean isProxyClassDefined() { return isProxyClassDefined(classLoader); }
/** * Returns the {@link Class} object for the generated class, creating it if it does not exist * * @return the generated class */ @SuppressWarnings("unchecked") public Class<? extends T> defineClass() { if (generatedClass == null) { synchronized (this) { if (generatedClass == null) { try { // first check that the proxy has not already been created generatedClass = (Class<? extends T>) classLoader.loadClass(this.className); } catch (ClassNotFoundException e) { buildClassDefinition(); if (protectionDomain == null) { generatedClass = (Class<? extends T>) classFile.define(classLoader); } else { generatedClass = (Class<? extends T>) classFile.define(classLoader, protectionDomain); } afterClassLoad(generatedClass); } classFile = null; } } } return generatedClass; }
/** * Creates a new instance of the generated class by invoking the default constructor. * <p/> * If the generated class has not been defined it will be created. * * @return the new instance * @throws InstantiationException if the new instance could not be created * @throws IllegalAccessException if the new constructor is inaccessible for some reason */ public T newInstance() throws InstantiationException, IllegalAccessException { return defineClass().newInstance(); }