1 18 package org.objectweb.speedo.generation.mivisitor; 19 20 import java.util.ArrayList ; 21 import java.util.List ; 22 23 import org.objectweb.speedo.api.SpeedoException; 24 import org.objectweb.speedo.api.SpeedoProperties; 25 import org.objectweb.speedo.metadata.SpeedoClass; 26 import org.objectweb.speedo.metadata.SpeedoExtension; 27 import org.objectweb.util.monolog.api.BasicLevel; 28 29 33 public class InheritanceVisitor 34 extends AbstractMetaInfoVisitor 35 implements SpeedoProperties { 36 37 private final static String DEFAULT_INHERITANCE_MAPPING 38 = INHERITANCE_FILTERED_MAPPING; 39 40 protected String getLoggerName() { 41 return super.getLoggerName() + ".inheritance"; 42 } 43 44 public void visitClass(SpeedoClass sc) throws SpeedoException { 45 if (sc.superClassName == null || sc.superClassName.length() == 0) { 46 sc.superClassName = null; 47 super.visitClass(sc); 48 return; 49 } 50 SpeedoClass supersc = sc.getSpeedoClassFromContext(sc.superClassName); 52 sc.superClassName = supersc.getFQName(); 53 if (debug) { 54 logger.log(BasicLevel.DEBUG, "class " + sc.getFQName() 55 + " extends " + sc.superClassName); 56 } 57 SpeedoExtension se = sc.getExtensionByKey(INHERITANCE_MAPPING); 58 if (se == null) { 59 se = new SpeedoExtension(VENDOR_NAME, 60 INHERITANCE_MAPPING, 61 DEFAULT_INHERITANCE_MAPPING, sc); 62 sc.addExtension(se); 63 } 64 List family = new ArrayList (); 66 getFamily(sc, family); 67 SpeedoClass ancestor = (SpeedoClass) family.get(0); 68 List extensions = findExtensions(ancestor, new String [] { 69 ID, SQL_SEQ_ALLOCATOR, SQL_SEQ_CACHE, SQL_SEQ_INC, SQL_SEQ_NAME, 70 SQL_SEQ_START}); 71 boolean detachable = ancestor.isDetachable; 72 for(int i=1; i<family.size(); i++) { 73 SpeedoClass anAncestor = (SpeedoClass) family.get(i); 74 anAncestor.identityType = ancestor.identityType; 76 anAncestor.objectidClass = ancestor.objectidClass; 77 assignExtension(extensions, anAncestor); 78 detachable |= anAncestor.isDetachable; 80 if (!anAncestor.isDetachable && detachable) { 81 if (debug) { 82 logger.log(BasicLevel.DEBUG, "\tThe class " + anAncestor.name 83 + " becomes detachable by inheritance."); 84 } 85 anAncestor.isDetachable = true; 86 } 87 anAncestor.datastoreSequence = ancestor.datastoreSequence; 89 } 90 super.visitClass(sc); 91 } 92 93 private List findExtensions(SpeedoClass sc, String [] keynames) { 94 ArrayList res = new ArrayList (); 95 SpeedoExtension se; 96 for(int i=0; i<keynames.length; i++) { 97 se = sc.getExtensionByKey(keynames[i]); 98 if (se != null) { 99 res.add(se); 100 } 101 } 102 return res; 103 } 104 105 private void assignExtension(List extensions, SpeedoClass sc) { 106 for(int i=extensions.size()-1; i>=0; i--) { 107 SpeedoExtension se = (SpeedoExtension) extensions.get(i); 108 sc.addExtension( 109 new SpeedoExtension(se.vendorName, se.key, se.value, sc)); 110 } 111 } 112 113 private void getFamily(SpeedoClass sc, List result) { 114 result.add(0, sc); 115 if (sc.superClassName == null || sc.superClassName.length() == 0) { 116 return; 117 } 118 SpeedoClass supersc = sc.getSpeedoClassFromContext(sc.superClassName); 119 getFamily(supersc, result); 120 } 121 122 } 123 | Popular Tags |