1 30 package com.genimen.djeneric.tools.strongtyper; 31 32 import java.util.ArrayList ; 33 import java.util.Arrays ; 34 35 import com.genimen.djeneric.repository.DjDomain; 36 import com.genimen.djeneric.repository.DjExtent; 37 import com.genimen.djeneric.repository.DjPersistenceManager; 38 import com.genimen.djeneric.repository.DjProperty; 39 import com.genimen.djeneric.repository.DjRelation; 40 41 public class InterfaceGenerator extends Generator 42 { 43 DjExtent _extent; 44 45 DjPersistenceManager _mgr; 46 47 public String getPackageName() 48 { 49 return getItfPackageName(); 50 } 51 52 public InterfaceGenerator(DjPersistenceManager mgr) 53 { 54 _mgr = mgr; 55 } 56 57 public DjExtent getExtent() 58 { 59 return _extent; 60 } 61 62 public void setExtent(DjExtent extent) 63 { 64 _extent = extent; 65 } 66 67 public String getClassName() 68 { 69 return getInterfaceName(getExtent()) + (isAbstract() ? getGeneratedSuffix() : ""); 70 } 71 72 public String getInterfaceName() 73 { 74 return getInterfaceName(getExtent()); 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 if (getExtent().getSuper() != null) 87 { 88 code.append(" extends " + getInterfaceName(getExtent().getSuper())); 89 } 90 else 91 { 92 code.append(" extends " + getParentInterfaceClassName()); 93 } 94 95 code.append("\n{\n"); 96 97 code.append(" public long determineObjectId() throws " + getExceptionClassName() + ";\n"); 98 99 for (int i = 0; i < _extent.getPropertyCount(); i++) 100 { 101 DjProperty prop = _extent.getProperty(i); 102 if (_extent.isInherited(prop)) continue; 103 104 String propInitcap = initCap(prop.getName()); 105 106 if (prop.getType() instanceof DjDomain) 107 { 108 code.append(" public " + translateNativeType(prop.getNativeType()) + " get" + propInitcap + "();\n"); 109 code.append(" public boolean isNull" + propInitcap + "();\n"); 110 if (_extent.getIdProperty() != prop) 111 { 112 code.append(" public void set" + propInitcap + "(" + translateNativeType(prop.getNativeType()) 113 + " value) throws " + getExceptionClassName() + ";\n"); 114 code.append(" public void setNull" + propInitcap + "() throws " + getExceptionClassName() + ";\n"); 115 } 116 } 117 else 118 { 119 DjExtent extent = (DjExtent) prop.getType(); 120 code.append(" public " + getInterfaceName(extent) + " get" + propInitcap + "() throws " 121 + getExceptionClassName() + ";\n"); 122 code.append(" public boolean isNull" + propInitcap + "();\n"); 123 code.append(" public void set" + propInitcap + "(" + getInterfaceName(extent) + " value) throws " 124 + getExceptionClassName() + ";\n"); 125 code.append(" public void setNull" + propInitcap + "() throws " + getExceptionClassName() + ";\n"); 126 } 127 code.append("\n"); 128 } 129 130 DjRelation[] rels = _extent.getDetailRelations(); 131 boolean first = true; 132 for (int i = 0; i < rels.length; i++) 133 { 134 if (_extent.isInherited(rels[i])) continue; 135 136 if (!isInSelectedSet(rels[i].getDetailExtent())) continue; 137 138 if (first) code.append("\n // Set operations:\n\n"); 139 first = false; 140 String propInitcap = initCap(rels[i].getName()); 141 String varName = propInitcap.toLowerCase(); 142 143 code.append(" public " + getInterfaceName(rels[i].getDetailExtent()) + "[] get" + propInitcap + "() throws " 144 + getExceptionClassName() + ";\n" + " public " + getInterfaceName(rels[i].getDetailExtent()) 145 + "[] get" + propInitcap + "(" + getQbeInterfaceName(rels[i].getDetailExtent()) + " qbe) throws " 146 + getExceptionClassName() + ";\n" + " public " + getCursorInterfaceName(rels[i].getDetailExtent()) 147 + " get" + propInitcap + "Cursor() throws " + getExceptionClassName() + ";\n" + " public " 148 + getCursorInterfaceName(rels[i].getDetailExtent()) + " get" + propInitcap + "Cursor(" 149 + getQbeInterfaceName(rels[i].getDetailExtent()) + " qbe) throws " + getExceptionClassName() + ";\n"); 150 151 ArrayList allDetailsList = new ArrayList (); 152 allDetailsList.add(rels[i].getDetailExtent()); 153 allDetailsList.addAll(Arrays.asList(_mgr.getSubExtentsOf(rels[i].getDetailExtent()))); 154 DjExtent[] allDetails = (DjExtent[]) allDetailsList.toArray(new DjExtent[0]); 155 156 for (int d = 0; d < allDetails.length; d++) 157 { 158 if (!isInSelectedSet(allDetails[d])) continue; 159 160 code.append(" public " + getInterfaceName(allDetails[d]) + " create" + allDetails[d].getObjectType() + "In" 161 + propInitcap + "() throws " + getExceptionClassName() + ";\n"); 162 } 163 } 164 165 code.append(StrongTyper.getRegenerationTags(0)); 166 code.append("}\n"); 167 return code.toString(); 168 } 169 170 } | Popular Tags |