[ 1785001 ] Using ModelPackage of EntityType to Generate Model Class

http://sourceforge.net/tracker/index.php?func=detail&aid=1785001&group_id=176962&atid=879335
This commit is contained in:
vpj-cd 2007-08-30 17:54:18 +00:00
parent 0c3cbc3162
commit b348312efd
2 changed files with 75 additions and 9 deletions

View File

@ -32,10 +32,14 @@ import java.util.TreeSet;
import java.util.logging.Level;
import org.compiere.Adempiere;
import org.compiere.model.MEntityType;
import org.compiere.model.MTable;
import org.compiere.util.CLogMgt;
import org.compiere.util.CLogger;
import org.compiere.util.DB;
import org.compiere.util.DisplayType;
import org.compiere.util.Env;
import org.compiere.util.Util;
/**
* Generate Model Classes extending PO.
@ -49,6 +53,8 @@ import org.compiere.util.DisplayType;
* <li>FR [ 1781630 ] Generated class/interfaces have a lot of unused imports
* <li>BF [ 1781632 ] Generated class/interfaces should be UTF-8
* <li>better formating of generated source
* @author Victor Perez, e-Evolution
* <li>FR [ 1785001 ] Using ModelPackage of EntityType to Generate Model Class
*/
public class ModelClassGenerator
{
@ -103,6 +109,10 @@ public class ModelClassGenerator
/** Package Name */
private String packageName = "";
/** EntityType */
private static final MEntityType[] entityTypes = MEntityType.getEntityTypes(Env.getCtx());
/**
* Add Header info to buffer
* @param AD_Table_ID table
@ -431,10 +441,31 @@ public class ModelClassGenerator
// 1) Must understand which class to reference
if (DisplayType.isID(displayType) && !IsKey) {
if (displayType == DisplayType.TableDir) {
//begin [ 1785001 ] Using ModelPackage of EntityType to Generate Model Class - vpj-cd
String tableName = columnName.substring(0, columnName.length()-3);
String referenceClassName = "I_"+columnName.substring(0, columnName.length()-3);
MTable table = MTable.get(Env.getCtx(), tableName);
String entityType = table.getEntityType();
if (!"D".equals(entityType))
{
for (int i = 0; i < entityTypes.length; i++)
{
if (entityTypes[i].getEntityType().equals(entityType))
{
String modelpackage = entityTypes[i].getModelPackage();
if (modelpackage != null)
{
referenceClassName = modelpackage+".I_"+columnName.substring(0, columnName.length()-3);
break;
}
}
}
}
//end [ 1785001 ]
sb.append(NL)
.append("\tpublic "+referenceClassName+" get").append(referenceClassName).append("() throws Exception ").append(NL)
.append("\tpublic "+referenceClassName+" get").append(tableName).append("() throws Exception ").append(NL)
.append(" {").append(NL)
// TODO - here we can implement Lazy loading or Cache of class
.append(" Class<?> clazz = MTable.getClass("+referenceClassName+".Table_Name);").append(NL)
@ -934,7 +965,8 @@ public class ModelClassGenerator
log.info("Generate Model $Revision: 1.42 $");
log.info("----------------------------------");
// first parameter
String directory = "C:\\Compiere\\compiere-all\\extend\\src\\compiere\\model\\";
//String directory = "/Users/Horus/Documents/adempiere/clientes/adempiere_trunk/base/src/org/compiere/model/";
String directory = "/Users/Horus/Documents/adempiere/clientes/libero/src/org/eevolution/model/";
if (args.length > 0)
directory = args[0];
if (directory == null || directory.length() == 0)
@ -945,7 +977,7 @@ public class ModelClassGenerator
log.info("Directory: " + directory);
// second parameter
String packageName = "compiere.model";
String packageName = "org.eevolution.model";
if (args.length > 1)
packageName = args[1];
if (packageName == null || packageName.length() == 0)
@ -956,7 +988,8 @@ public class ModelClassGenerator
log.info("Package: " + packageName);
// third parameter
String entityType = "'U','A'"; // User, Application
//String entityType = "'U','A','D','EE01'"; // User, Application
String entityType = "'EE01'"; // User, Application
if (args.length > 2)
entityType = args[2];
if (entityType == null || entityType.length() == 0)

View File

@ -41,10 +41,13 @@ import java.util.TreeSet;
import java.util.logging.Level;
import org.compiere.Adempiere;
import org.compiere.model.MEntityType;
import org.compiere.model.MTable;
import org.compiere.util.CLogMgt;
import org.compiere.util.CLogger;
import org.compiere.util.DB;
import org.compiere.util.DisplayType;
import org.compiere.util.Env;
/**
* @author Trifon Trifonov
@ -55,6 +58,8 @@ import org.compiere.util.DisplayType;
* <li>FR [ 1781630 ] Generated class/interfaces have a lot of unused imports
* <li>BF [ 1781632 ] Generated class/interfaces should be UTF-8
* <li>better formating of generated source
* @author Victor Perez, e-Evolution
* <li>FR [ 1785001 ] Using ModelPackage of EntityType to Generate Model Class
*/
public class ModelInterfaceGenerator {
@ -99,6 +104,10 @@ public class ModelInterfaceGenerator {
/** Logger */
private static CLogger log = CLogger.getCLogger(ModelInterfaceGenerator.class);
/** EntityType */
private static final MEntityType[] entityTypes = MEntityType.getEntityTypes(Env.getCtx());
public ModelInterfaceGenerator(int AD_Table_ID, String directory, String packageName) {
this.packageName = packageName;
@ -377,9 +386,30 @@ public class ModelInterfaceGenerator {
if (DisplayType.isID(displayType) && !IsKey) {
if (displayType == DisplayType.TableDir) {
String referenceClassName = "I_"+columnName.substring(0, columnName.length()-3);
//begin [ 1785001 ] Using ModelPackage of EntityType to Generate Model Class - vpj-cd
String tableName = columnName.substring(0, columnName.length()-3);
MTable table = MTable.get(Env.getCtx(), tableName);
String entityType = table.getEntityType();
if (!"D".equals(entityType))
{
for (int i = 0; i < entityTypes.length; i++)
{
if (entityTypes[i].getEntityType().equals(entityType))
{
String modelpackage = entityTypes[i].getModelPackage();
if (modelpackage != null)
{
referenceClassName = modelpackage+".I_"+columnName.substring(0, columnName.length()-3);
break;
}
}
}
}
//end [ 1785001 ]
sb.append("\n")
.append("\tpublic "+referenceClassName+" get").append(referenceClassName).append("() throws Exception;")
.append("\tpublic "+referenceClassName+" get").append(tableName).append("() throws Exception;")
;
} else {
// TODO - Handle other types
@ -515,7 +545,8 @@ public class ModelInterfaceGenerator {
log.info("Generate Interface $Revision: 1.0 $");
log.info("----------------------------------");
// first parameter
String directory = "C:\\extend\\src\\compiere\\model\\";
//String directory = "/Users/Horus/Documents/adempiere/clientes/adempiere_trunk/base/src/org/compiere/model/";
String directory = "/Users/Horus/Documents/adempiere/clientes/libero/src/org/eevolution/model/";
if (args.length > 0)
directory = args[0];
if (directory == null || directory.length() == 0) {
@ -525,7 +556,8 @@ public class ModelInterfaceGenerator {
log.info("Directory: " + directory);
// second parameter
String packageName = "compiere.model";
//String packageName = "org.compiere.model";
String packageName = "org.eevolution.model";
if (args.length > 1)
packageName = args[1];
if (packageName == null || packageName.length() == 0) {
@ -535,7 +567,8 @@ public class ModelInterfaceGenerator {
log.info("Package: " + packageName);
// third parameter
String entityType = "'U','A'"; // User, Application
//String entityType = "'U','A','EE01','D'"; // User, Application
String entityType = "'EE01'"; // User, Application
if (args.length > 2)
entityType = args[2];
if (entityType == null || entityType.length() == 0) {