1 30 package com.genimen.djeneric.tools.strongtyper; 31 32 import com.genimen.djeneric.repository.DjDomain; 33 import com.genimen.djeneric.repository.DjExtent; 34 import com.genimen.djeneric.repository.DjPersistenceManager; 35 import com.genimen.djeneric.repository.DjProperty; 36 37 public class QbeInterfaceGenerator extends Generator 38 { 39 DjExtent _extent; 40 DjPersistenceManager _mgr; 41 42 public String getPackageName() 43 { 44 return getItfPackageName(); 45 } 46 47 public QbeInterfaceGenerator(DjPersistenceManager mgr) 48 { 49 _mgr = mgr; 50 } 51 52 public DjExtent getExtent() 53 { 54 return _extent; 55 } 56 57 public void setExtent(DjExtent extent) 58 { 59 _extent = extent; 60 } 61 62 public String getQbeInterfaceName() 63 { 64 return getQbeInterfaceName(getExtent()); 65 } 66 67 public String getClassName() 68 { 69 return getClassName(getExtent()) + (isAbstract() ? getGeneratedSuffix() : ""); 70 } 71 72 public String getClassName(DjExtent extent) 73 { 74 return getQbeInterfaceName(extent); 75 } 76 77 public String getCode() throws Exception 78 { 79 StringBuffer code = new StringBuffer (5000); 80 if (getPackageName().trim().length() > 0) code.append("package " + getPackageName() + ";\n\n"); 81 82 if (containsBigDecimal(getExtent())) code.append("import java.math.*;\n"); 83 code.append(StrongTyper.getRegenerationTags(1)); 84 85 code.append("public interface " + getClassName()); 86 87 if (getExtent().getSuper() != null) 88 { 89 code.append(" extends " + getClassName(getExtent().getSuper())); 90 } 91 92 code.append("\n"); 93 94 code.append("{\n"); 95 96 code.append(" public void setQueryOperator(String propertyName, String operator) throws " 97 + getExceptionClassName() + ";\n"); 98 for (int i = 0; i < _extent.getPropertyCount(); i++) 99 { 100 DjProperty prop = _extent.getProperty(i); 101 if (_extent.isInherited(prop)) continue; 102 103 String propInitcap = initCap(prop.getName()); 104 105 if (prop.getType() instanceof DjDomain) 106 { 107 code.append(" public " + translateNativeType(prop.getNativeType()) + " get" + propInitcap + "();\n"); 108 code.append(" public void set" + propInitcap + "(" + translateNativeType(prop.getNativeType()) 109 + " value) throws " + getExceptionClassName() + ";\n"); 110 } 111 else 112 { 113 DjExtent extent = (DjExtent) prop.getType(); 114 code.append(" public " + getInterfaceName(extent) + " get" + propInitcap + "() throws " 115 + getExceptionClassName() + ";\n"); 116 code.append(" public void set" + propInitcap + "(" + getInterfaceName(extent) + " value) throws " 117 + getExceptionClassName() + ";\n"); 118 } 119 } 120 121 code.append(StrongTyper.getRegenerationTags(0)); 122 code.append("}\n"); 123 return code.toString(); 124 } 125 126 } | Popular Tags |