[ 1784588 ] Use ModelPackage of EntityType to Find Model Class

http://sourceforge.net/tracker/index.php?func=detail&aid=1784588&group_id=176962&atid=879335
This commit is contained in:
vpj-cd 2007-08-30 06:13:46 +00:00
parent 6b5a794b77
commit 5e10616432
1 changed files with 39 additions and 5 deletions

View File

@ -34,7 +34,9 @@ import org.compiere.util.*;
* <ul> * <ul>
* <li>2007-02-01 - teo_sarca - [ 1648850 ] MTable.getClass works incorrect for table "Fact_Acct" * <li>2007-02-01 - teo_sarca - [ 1648850 ] MTable.getClass works incorrect for table "Fact_Acct"
* </ul> * </ul>
* * <ul>
* <li>2007-08-30 - vpj-cd - [ 1784588 ] Use ModelPackage of EntityType to Find Model Class
* </ul>
* @author Jorg Janke * @author Jorg Janke
* @version $Id: MTable.java,v 1.3 2006/07/30 00:58:04 jjanke Exp $ * @version $Id: MTable.java,v 1.3 2006/07/30 00:58:04 jjanke Exp $
*/ */
@ -134,11 +136,12 @@ public class MTable extends X_AD_Table
/** Packages for Model Classes */ /** Packages for Model Classes */
private static final String[] s_packages = new String[] { private static final String[] s_packages = new String[] {
"org.compiere.model", "org.compiere.wf",
"org.compiere.print", "org.compiere.impexp",
"compiere.model", // globalqss allow compatibility with other plugins "compiere.model", // globalqss allow compatibility with other plugins
"adempiere.model", // Extensions "adempiere.model", // Extensions
"org.adempiere.model", "org.adempiere.model"
"org.compiere.model", "org.compiere.wf",
"org.compiere.print", "org.compiere.impexp"
}; };
/** Special Classes */ /** Special Classes */
@ -155,6 +158,9 @@ public class MTable extends X_AD_Table
// AD_Attribute_Value, AD_TreeNode // AD_Attribute_Value, AD_TreeNode
}; };
/** EntityType */
private static final MEntityType[] entityTypes = MEntityType.getEntityTypes(Env.getCtx());
/** /**
* Get Persistency Class for Table * Get Persistency Class for Table
* @param tableName table name * @param tableName table name
@ -176,6 +182,8 @@ public class MTable extends X_AD_Table
return null; return null;
} }
//check cache //check cache
Class cache = s_classCache.get(tableName); Class cache = s_classCache.get(tableName);
if (cache != null) if (cache != null)
@ -202,6 +210,31 @@ public class MTable extends X_AD_Table
} }
} }
//begin [ 1784588 ] Use ModelPackage of EntityType to Find Model Class - vpj-cd
MTable table = MTable.get(Env.getCtx(), tableName);
String entityType = table.getEntityType();
if (!MEntityType.ENTITYTYPE_Dictionary.equals(entityType))
{
for (int i = 0; i < entityTypes.length; i++)
{
if (entityTypes[i].getEntityType().equals(entityType))
{
String modelpackage = entityTypes[i].getModelPackage();
if (modelpackage != null)
{
Class clazz = getPOclass(entityTypes[i].getModelPackage() + ".M" + Util.replace(tableName, "_", ""));
if (clazz != null)
return clazz;
clazz = getPOclass(entityTypes[i].getModelPackage() + ".X_" + tableName);
if (clazz != null)
return clazz;
s_log.warning("No class for table with it entity: " + tableName);
}
}
}
}
//end [ 1784588 ]
// Strip table name prefix (e.g. AD_) Customizations are 3/4 // Strip table name prefix (e.g. AD_) Customizations are 3/4
String className = tableName; String className = tableName;
int index = className.indexOf('_'); int index = className.indexOf('_');
@ -233,6 +266,7 @@ public class MTable extends X_AD_Table
} }
} }
// Adempiere Extension // Adempiere Extension
Class clazz = getPOclass("adempiere.model.X_" + tableName); Class clazz = getPOclass("adempiere.model.X_" + tableName);
if (clazz != null) if (clazz != null)