1 18 package org.objectweb.speedo.generation.mivisitor; 19 20 import org.objectweb.speedo.metadata.SpeedoPackage; 21 import org.objectweb.speedo.metadata.SpeedoExtension; 22 import org.objectweb.speedo.metadata.SpeedoElement; 23 import org.objectweb.speedo.metadata.SpeedoClass; 24 import org.objectweb.speedo.metadata.SpeedoField; 25 import org.objectweb.speedo.metadata.SpeedoMap; 26 import org.objectweb.speedo.metadata.SpeedoCollection; 27 import org.objectweb.speedo.api.SpeedoException; 28 import org.objectweb.speedo.api.SpeedoProperties; 29 import org.objectweb.util.monolog.api.BasicLevel; 30 31 import java.util.List ; 32 import java.util.Collections ; 33 import java.util.ArrayList ; 34 35 41 public class ExtensionVerifier 42 extends AbstractMetaInfoVisitor 43 implements SpeedoProperties { 44 45 protected String getLoggerName() { 46 return super.getLoggerName() + ".extensionverifier"; 47 } 48 49 public void visitPackage(SpeedoPackage sp) throws SpeedoException { 50 super.visitPackage(sp); 51 StringBuffer sb = new StringBuffer (); 52 sb.append("package "); 53 sb.append(sp.name); 54 sb.append(" in the .jdo file "); 55 sb.append(sp.jdoXMLDescriptor.xmlFile); 56 checkSpeedoElement(sp, EXTENSION_PACKAGE_IDX, sb.toString()); 57 } 58 59 public void visitClass(SpeedoClass sc) throws SpeedoException { 60 super.visitClass(sc); 61 StringBuffer sb = new StringBuffer (); 62 sb.append("class "); 63 sb.append(sc.getFQName()); 64 sb.append(" in the .jdo file "); 65 sb.append(sc.getJDOFileName()); 66 checkSpeedoElement(sc, EXTENSION_CLASS_IDX, sb.toString()); 67 } 68 69 public void visitField(SpeedoField sf) throws SpeedoException { 70 super.visitField(sf); 71 StringBuffer sb = new StringBuffer (); 72 sb.append("field "); 73 sb.append(sf.name); 74 sb.append("of class "); 75 sb.append(sf.jdoClass.getFQName()); 76 sb.append(" in the .jdo file "); 77 sb.append(sf.jdoClass.getJDOFileName()); 78 checkSpeedoElement(sf, EXTENSION_FIELD_IDX, sb.toString()); 79 if (sf.jdoTuple != null) { 80 if (sf.jdoTuple instanceof SpeedoMap) { 81 sb.insert(0, "map "); 82 checkSpeedoElement(sf.jdoTuple, EXTENSION_MAP_IDX, sb.toString()); 83 } else if (sf.jdoTuple instanceof SpeedoCollection) { 84 sb.insert(0, "collection "); 85 checkSpeedoElement(sf.jdoTuple, EXTENSION_COLLECTION_IDX, sb.toString()); 86 } 87 } 88 } 89 90 private void checkSpeedoElement(SpeedoElement element, 91 int nodeIdx, 92 String nodeName) { 93 List exts = getSpeedoExtension(element); 94 String unexpected = getUnexpectedExtensionStr(exts, nodeIdx); 95 if (unexpected != null) { 96 logger.log(BasicLevel.WARN, 97 "Unsupported speedo extension found for the " 98 + nodeName + unexpected); 99 } 100 } 101 102 private String getUnexpectedExtensionStr(List exts, int node) { 103 StringBuffer sb = new StringBuffer (); 104 String sep = ""; 105 boolean unexpectedFound = false; 106 List supported = (List ) SUPPORTED_EXTENSION.get(node); 107 for(int i=0; i<exts.size(); i++) { 108 SpeedoExtension se = (SpeedoExtension) exts.get(i); 109 boolean uf = supported.isEmpty() || !supported.contains(se.key); 110 if (uf) { 111 sb.append(sep); 112 sep = ", "; 113 unexpectedFound = true; 114 sb.append("("); 115 sb.append(se.key); 116 sb.append("=>"); 117 sb.append(se.value); 118 sb.append(")"); 119 } 120 } 121 if (unexpectedFound) { 122 sb.insert(0, "{"); 123 sb.append("}"); 124 return sb.toString(); 125 } else { 126 return null; 127 } 128 } 129 130 131 private List getSpeedoExtension(SpeedoElement element) { 132 List exts = element.jdoExtension; 133 if(exts.isEmpty()) { 134 return Collections.EMPTY_LIST; 135 } 136 ArrayList result = new ArrayList (exts.size()); 137 for(int i=0; i<exts.size(); i++) { 138 SpeedoExtension se = (SpeedoExtension) exts.get(i); 139 if (VENDOR_NAME.equals(se.vendorName)) { 140 result.add(se); 141 } 142 } 143 return result; 144 } 145 } 146 | Popular Tags |