1 19 package org.apache.cayenne.enhancer; 20 21 import java.util.HashMap ; 22 import java.util.Map ; 23 24 import org.apache.cayenne.map.EntityResolver; 25 import org.apache.cayenne.map.ObjEntity; 26 import org.objectweb.asm.ClassVisitor; 27 import org.objectweb.asm.commons.SerialVersionUIDAdder; 28 29 35 public class CayenneEnhancerVisitorFactory implements EnhancerVisitorFactory { 36 37 protected Map <String , ObjEntity> entitiesByClass; 38 39 public CayenneEnhancerVisitorFactory(EntityResolver entityResolver) { 40 indexEntities(entityResolver); 41 } 42 43 protected void indexEntities(EntityResolver entityResolver) { 44 48 this.entitiesByClass = new HashMap <String , ObjEntity>(); 49 for (Object object : entityResolver.getObjEntities()) { 50 ObjEntity entity = (ObjEntity) object; 51 entitiesByClass.put(entity.getClassName(), entity); 52 } 53 } 54 55 public ClassVisitor createVisitor(String className, ClassVisitor out) { 56 ObjEntity entity = entitiesByClass.get(className.replace('/', '.')); 57 if (entity == null) { 58 return null; 59 } 60 61 PersistentInterfaceVisitor e1 = new PersistentInterfaceVisitor(out); 63 PersistentAccessorVisitor e2 = new PersistentAccessorVisitor(e1, entity); 64 65 SerialVersionUIDAdder e3 = new SerialVersionUIDAdder(e2); 68 return e3; 69 } 70 } 71 | Popular Tags |