1 30 package com.genimen.djeneric.tools.strongtyper; 31 32 import com.genimen.djeneric.repository.DjDomain; 33 import com.genimen.djeneric.repository.DjDomainValue; 34 import com.genimen.djeneric.repository.DjExtent; 35 36 public class SessionInterfaceGenerator extends Generator 37 { 38 DjExtent[] _extents = null; 39 DjDomain[] _domains = null; 40 41 public String getPackageName() 42 { 43 return getItfPackageName(); 44 } 45 46 public SessionInterfaceGenerator(DjExtent[] extents, DjDomain[] domains) throws Exception 47 { 48 _extents = extents; 49 _domains = domains; 50 if (extents == null || extents.length == 0) throw new Exception ( 51 "Can not generate a session without any Extents selected"); 52 } 53 54 public String getClassName() 55 { 56 return getSessionInterfaceName() + (isAbstract() ? getGeneratedSuffix() : ""); 57 } 58 59 public String getCode() throws Exception 60 { 61 StringBuffer code = new StringBuffer (5000); 62 if (getPackageName().trim().length() > 0) code.append("package " + getPackageName() + ";\n\n"); 63 64 code.append("import java.util.*;\n"); 65 code.append(StrongTyper.getRegenerationTags(1)); 69 70 code.append("public interface " + getClassName() + "\n{\n"); 71 72 code.append(" public final static String DOMAIN_NAME = \"name\";\n"); 73 code.append(" public final static String DOMAIN_TYPE = \"type\";\n"); 74 code.append(" public final static String DOMAIN_LENGTH = \"length\";\n"); 75 code.append(" public final static String DOMAIN_DECIMALS = \"decimals\";\n"); 76 code.append(" public final static String DOMAIN_ENFORCE = \"enforce\";\n"); 77 code.append(" public final static String DOMAIN_FORMAT_MASK = \"formatmask\";\n"); 78 code.append(" public final static String DOMAIN_DESCRIPTION = \"description\";\n"); 79 code.append(" public final static String DOMAIN_VALUES = \"values\";\n"); 80 code.append(" public final static String DOMAIN_VALUE_DESCRIPTIONS = \"valuedescriptions\";\n\n"); 81 82 for (int i = 0; i < _domains.length; i++) 83 { 84 85 if (_domains[i].isDynamic()) continue; 86 87 String name = _domains[i].getName(); 88 if (name.equals("byte[]")) name = "bytes"; 89 90 code.append(" public final static String TYPE_" + name.toUpperCase() + " = \"" + name + "\";\n"); 91 92 DjDomainValue[] values = _domains[i].getValidValues(); 93 for (int v = 0; v < values.length; v++) 94 { 95 if (values[v].isDynamic()) continue; 96 code.append(" public final static String VV_" + name.toUpperCase() + "_" + values[v].getValue().toString() 97 + " = \"" + values[v].getValue().toString() + "\";\n"); 98 } 99 100 } 101 102 code.append("\n public HashMap[] getDomains() throws " + getExceptionClassName() + ";\n"); 103 code.append(" public HashMap getDomain(String domainName) throws " + getExceptionClassName() + ";\n"); 104 code.append("\n"); 105 106 for (int i = 0; i < _extents.length; i++) 107 { 108 code.append(" public " + getInterfaceName(_extents[i]) + " create" + _extents[i].getObjectType() + "() throws " 109 + getExceptionClassName() + ";\n"); 110 code.append(" public " + getQbeInterfaceName(_extents[i]) + " create" + _extents[i].getObjectType() 111 + "Qbe() throws " + getExceptionClassName() + ";\n"); 112 code.append(" public " + getOqlInterfaceName() + " create" + _extents[i].getObjectType() + "Oql() throws " 113 + getExceptionClassName() + ";\n"); 114 115 code.append(" public " + getInterfaceName(_extents[i]) + " get" + _extents[i].getObjectType() 116 + "(long objectId) throws " + getExceptionClassName() + ";\n"); 117 code.append(" public " + getInterfaceName(_extents[i]) + "[] get" + _extents[i].getObjectType() 118 + "Set() throws " + getExceptionClassName() + ";\n"); 119 code.append(" public " + getInterfaceName(_extents[i]) + "[] get" + _extents[i].getObjectType() + "Set(" 120 + getQbeInterfaceName(_extents[i]) + " qbe) throws " + getExceptionClassName() + ";\n"); 121 code.append(" public " + getInterfaceName(_extents[i]) + " get" + _extents[i].getObjectType() + "(" 122 + getQbeInterfaceName(_extents[i]) + " qbe) throws " + getExceptionClassName() + ";\n"); 123 code.append(" public " + getCursorInterfaceName(_extents[i]) + " get" + _extents[i].getObjectType() 124 + "Cursor() throws " + getExceptionClassName() + ";\n"); 125 code.append(" public " + getCursorInterfaceName(_extents[i]) + " get" + _extents[i].getObjectType() + "Cursor(" 126 + getQbeInterfaceName(_extents[i]) + " qbe) throws " + getExceptionClassName() + ";\n"); 127 128 code.append(" public " + getInterfaceName(_extents[i]) + "[] get" + _extents[i].getObjectType() + "Set(" 129 + getOqlInterfaceName() + " oql) throws " + getExceptionClassName() + ";\n"); 130 code.append(" public " + getInterfaceName(_extents[i]) + " get" + _extents[i].getObjectType() + "(" 131 + getOqlInterfaceName() + " oql) throws " + getExceptionClassName() + ";\n"); 132 code.append(" public " + getCursorInterfaceName(_extents[i]) + " get" + _extents[i].getObjectType() + "Cursor(" 133 + getOqlInterfaceName() + " oql) throws " + getExceptionClassName() + ";\n"); 134 code.append("\n"); 135 } 136 137 code.append("\n" + " public boolean isValid();\n" + " public boolean hasOutstandingChanges();\n" 138 + " public void setCommitAllowed(boolean b);\n" + " public boolean isCommitAllowed();\n" 139 + " public void commit() throws Exception;\n" + " public void close();\n"); 140 141 code.append(StrongTyper.getRegenerationTags(0)); 142 code.append("}\n"); 143 144 return code.toString(); 145 } 146 147 } | Popular Tags |