1 27 package org.objectweb.speedo.generation.enhancer; 28 29 import org.objectweb.speedo.api.SpeedoException; 30 import org.objectweb.speedo.api.SpeedoProperties; 31 import org.objectweb.speedo.metadata.SpeedoXMLDescriptor; 32 import org.objectweb.speedo.metadata.SpeedoPackage; 33 import org.objectweb.speedo.metadata.SpeedoClass; 34 import org.objectweb.speedo.generation.lib.NamingRules; 35 import org.objectweb.asm.ClassReader; 36 import org.objectweb.asm.ClassWriter; 37 import org.objectweb.asm.attrs.Attributes; 38 import org.objectweb.util.monolog.api.BasicLevel; 39 40 import java.util.Iterator ; 41 import java.util.Collection ; 42 import java.util.Set ; 43 import java.util.TreeSet ; 44 import java.io.File ; 45 46 public class PersistenceAwareEnhancer extends EnhancerComponent { 47 48 public final static String LOGGER_NAME 49 = SpeedoProperties.LOGGER_NAME + ".generation.enhancer.aware"; 50 51 54 public boolean init() { 55 logger = scp.loggerFactory.getLogger(LOGGER_NAME); 56 isSrcJar = false; 58 return !scp.getXmldescriptor().isEmpty(); 59 } 60 61 67 public void process() throws SpeedoException { 68 if (scp.getXmldescriptor() == null || scp.getXmldescriptor().isEmpty()) 69 return; 70 71 Set generatedClasses = computeGeneratedClasses(); 72 73 Collection xmls = scp.getXmldescriptor().values(); 74 Iterator i = scp.awareFiles.iterator(); 75 while (i.hasNext()) { 76 String awareFile = (String ) i.next(); 77 String name = awareFile.replace(File.separatorChar, '.'); 78 name = name.substring(0, name.length() - 6); 80 if (generatedClasses.contains(name)) { 81 continue; 83 } 84 85 logger.log( 86 BasicLevel.DEBUG, 87 "Enhancing persistent aware class '" + name + "'"); 88 89 ClassReader cr = loadJavaClass( 90 isSrcJar, 91 name, 92 scp.awareFilesDir, 93 false); 94 ClassWriter cw = new ClassWriter(false); 95 96 PersistenceAwareClassModifier awarecmodifier = 97 new PersistenceAwareClassModifier(cw, xmls, logger); 98 99 cr.accept(awarecmodifier, Attributes.getDefaultAttributes(), false); 100 101 writeJavaClass(name, cw, scp.output); 102 } 103 } 104 105 private Set computeGeneratedClasses() { 106 Set result = new TreeSet (); 107 Collection xmls = scp.getXmldescriptor().values(); 108 for (Iterator itDesc = xmls.iterator(); itDesc.hasNext();) { 109 SpeedoXMLDescriptor desc = (SpeedoXMLDescriptor) itDesc.next(); 110 for (Iterator itPack = desc.jdoPackage.values().iterator(); itPack.hasNext();) { 111 SpeedoPackage sp = (SpeedoPackage) itPack.next(); 112 for (Iterator itclass = sp.jdoClass.values().iterator(); itclass.hasNext();) { 113 SpeedoClass jdoClass = (SpeedoClass) itclass.next(); 114 String name = sp.name + '.' + jdoClass.name; 115 String proxyName = NamingRules.proxyName(name); 116 String accessorName = NamingRules.accessorName(name); 117 String bindingName = sp.name + '.' + scp.mapperName + '.' + NamingRules.bindingName(jdoClass.name); 118 String mappingName = sp.name + '.' + scp.mapperName + '.' + NamingRules.mappingName(jdoClass.name); 119 String iteratorName = sp.name + '.' + scp.mapperName + '.' + jdoClass.name + "ResultIterator"; 120 String fieldsName = NamingRules.fieldsName(name); 121 result.add(name); 122 result.add(proxyName); 123 result.add(accessorName); 124 result.add(bindingName); 125 result.add(mappingName); 126 result.add(iteratorName); 127 result.add(fieldsName); 128 } 129 } 130 } 131 return result; 132 } 133 } 134 | Popular Tags |