1 18 package org.objectweb.speedo.generation.mivisitor; 19 20 import org.objectweb.speedo.api.SpeedoException; 21 import org.objectweb.speedo.api.SpeedoProperties; 22 import org.objectweb.speedo.metadata.SpeedoClass; 23 import org.objectweb.speedo.metadata.SpeedoExtension; 24 import org.objectweb.speedo.metadata.SpeedoField; 25 import org.objectweb.speedo.metadata.SpeedoMap; 26 import org.objectweb.util.monolog.api.BasicLevel; 27 28 34 public class KeyFieldChecker 35 extends AbstractMetaInfoVisitor 36 implements SpeedoProperties { 37 38 public KeyFieldChecker() { 39 } 40 41 public KeyFieldChecker(MetaInfoVisitor mim) { 42 super(mim); 43 } 44 45 protected String getLoggerName() { 46 return AbstractMetaInfoVisitor.LOGGER_NAME + ".keyField"; 47 } 48 49 public void visitExtension(SpeedoExtension se) throws SpeedoException { 50 debug = logger.isLoggable(BasicLevel.DEBUG); 51 if (!VENDOR_NAME.equals(se.vendorName) 52 || !KEY_FIELD.equals(se.key)) { 53 super.visitExtension(se); 54 return; 55 } 56 57 if (!(se.jdoElement instanceof SpeedoField)) { 59 SpeedoClass sc = getSpeedoClass(se.jdoElement); 60 logger.log(BasicLevel.ERROR, "You have specified the key field ('" 61 + se.value + "') in other thing than a field tag ('" 62 + se.jdoElement.toString() + "')" + 63 (sc == null 64 ? "" 65 : " in class '" + sc.getFQName() + "' of the descriptor '" 66 + sc.jdoPackage.jdoXMLDescriptor.xmlFile)); 67 super.visitExtension(se); 68 return; 69 } 70 71 SpeedoField sf = (SpeedoField) se.jdoElement; 73 if (!(sf.jdoTuple instanceof SpeedoMap)) { 74 SpeedoClass sc = getSpeedoClass(se.jdoElement); 75 logger.log(BasicLevel.ERROR, "You have specified the key field ('" 76 + se.value + "') for the field '" + sf.name 77 + "' which is not Map" + 78 (sc == null 79 ? "" 80 : ", in class '" + sc.getFQName() + "' of the descriptor '" 81 + sc.jdoPackage.jdoXMLDescriptor.xmlFile)); 82 super.visitExtension(se); 83 return; 84 } 85 SpeedoField keyfield = ReverseFieldAdder.getReverseField(sf, se.value); 87 if (keyfield == null) { 88 ReverseFieldAdder.throwError("No key field '" + se.value + "' found for the", sf); 89 super.visitExtension(se); 90 return; 91 } 92 SpeedoMap sm = (SpeedoMap) sf.jdoTuple; 93 if (sm.keyType != null && ((String ) sm.keyType).length() > 0) { 94 if (keyfield.type().equalsIgnoreCase((String ) sm.keyType)) { 96 ReverseFieldAdder.throwError("No key field '" + se.value + "' found for the", sf); 97 super.visitExtension(se); 98 return; 99 } 100 } else { 101 sm.keyType = keyfield.type(); 103 } 104 105 SpeedoExtension _se = keyfield.getExtensionByKey(SQL_NAME); 108 if (_se != null) { 109 _se = new SpeedoExtension(_se.vendorName, INDEX, _se.value, sf); 110 sf.addExtension(_se); 111 } 112 113 _se = keyfield.getExtensionByKey(SQL_TYPE); 116 if (_se != null) { 117 _se = new SpeedoExtension(_se.vendorName, INDEX_TYPE, _se.value, sf); 118 sf.addExtension(_se); 119 } 120 super.visitExtension(se); 121 } 122 } 123 | Popular Tags |