1 16 17 package org.springframework.orm.jpa.persistenceunit; 18 19 import javax.persistence.spi.ClassTransformer; 20 21 import org.springframework.instrument.classloading.LoadTimeWeaver; 22 import org.springframework.instrument.classloading.SimpleThrowawayClassLoader; 23 import org.springframework.util.ClassUtils; 24 25 39 class SpringPersistenceUnitInfo extends MutablePersistenceUnitInfo { 40 41 private LoadTimeWeaver loadTimeWeaver; 42 43 44 48 public void setLoadTimeWeaver(LoadTimeWeaver loadTimeWeaver) { 49 this.loadTimeWeaver = loadTimeWeaver; 50 } 51 52 public ClassLoader getClassLoader() { 53 if (this.loadTimeWeaver != null) { 54 return this.loadTimeWeaver.getInstrumentableClassLoader(); 55 } 56 else { 57 return ClassUtils.getDefaultClassLoader(); 58 } 59 } 60 61 65 public void addTransformer(ClassTransformer classTransformer) { 66 if (this.loadTimeWeaver == null) { 67 throw new IllegalStateException ("Cannot apply class transformer without LoadTimeWeaver specified"); 68 } 69 this.loadTimeWeaver.addTransformer(new ClassFileTransformerAdapter(classTransformer)); 70 } 71 72 public ClassLoader getNewTempClassLoader() { 73 if (this.loadTimeWeaver != null) { 74 return this.loadTimeWeaver.getThrowawayClassLoader(); 75 } 76 else { 77 return new SimpleThrowawayClassLoader(ClassUtils.getDefaultClassLoader()); 78 } 79 } 80 81 } 82 | Popular Tags |