protected static GenModel generatePackages(Collection packageList, String targetDirectory, Hashtable packageInfoTable, int genOptions, boolean allNamespaces )
{
ResourceSet resourceSet = DataObjectUtil.createResourceSet();
List usedGenPackages = new ArrayList();
GenModel genModel = null;
ArrayList packagesToModel = new ArrayList();
for (Iterator iter = packageList.iterator(); iter.hasNext();)
{
EPackage currentEPackage = (EPackage)iter.next();
String packageNamespace = currentEPackage.getNsURI();
PackageInfo packageInfo = (PackageInfo)packageInfoTable.get(packageNamespace);
boolean bTargetPackage = allNamespaces;
String javaPackage = null;
String prefix = null;
String shortName = null;
if( packageInfo != null )
{
bTargetPackage = true;
javaPackage = packageInfo.getBasePackage();
prefix = packageInfo.getPrefix();
shortName = packageInfo.getShortName();
}
String currentBasePackage = extractBasePackageName(currentEPackage, bTargetPackage ? javaPackage : null);
String currentPrefix = bTargetPackage && prefix != null ? prefix : CodeGenUtil.capName(shortName != null ? shortName : currentEPackage.getName());
packageInfoTable.put(currentEPackage, new PackageInfo(currentBasePackage, currentPrefix, null, null ));
if( allNamespaces || packageInfo != null )
packagesToModel.add(currentEPackage);
else
{
GenPackage currentGenPackage = createGenPackage(currentEPackage, currentBasePackage, currentPrefix, genOptions, resourceSet);
usedGenPackages.add(currentGenPackage);
}
}
genModel = createGenPackages(packagesToModel, packageInfoTable, genOptions, resourceSet);
if (genModel == null) return null; // nothing to generate
//TODO Figure out which predefined packages are really "used"
usedGenPackages.add(createGenPackage(SDOPackageImpl.eINSTANCE, "org.apache.tuscany", "SDO", 0, resourceSet));
usedGenPackages.add(createGenPackage((EPackage)ModelFactory.INSTANCE, "org.apache.tuscany.sdo", "Model", 0, resourceSet));
usedGenPackages.add(createGenPackage((EPackage)InternalFactory.INSTANCE, "org.apache.tuscany.sdo.model", "Internal", 0, resourceSet));
//usedGenPackages.add(createGenPackage((EPackage)JavaFactory.INSTANCE, "org.apache.tuscany.sdo.model", "Java", 0, resourceSet));
//usedGenPackages.add(createGenPackage((EPackage)XMLFactory.INSTANCE, "org.apache.tuscany.sdo.model", "XML", 0, resourceSet));
genModel.getUsedGenPackages().addAll(usedGenPackages);
// If the display namespace option is selected, Don't generate
if( (genOptions & OPTION_NO_GENERATE) == 0)
{
// Invoke the SDO JavaGenerator to generate the SDO classes