String msg = null;
ClassLoaderResolver clr = omfContext.getClassLoaderResolver(null);
// Obtain a MetaDataManager to work with
MetaDataManager metaDataMgr = omfContext.getMetaDataManager();
metaDataMgr.setEnhancing();
String metadataFactory = getClassEnhancerMetadataFactoryName();
if (!StringUtils.isWhitespace(metadataFactory))
{
try
{
Class factoryCls = clr.classForName(metadataFactory);
MetaDataFactory factory = (MetaDataFactory)ClassUtils.newInstance(factoryCls,
new Class[] {MetaDataManager.class}, new Object[] {metaDataMgr});
metaDataMgr.setMetaDataFactory(factory);
}
catch (Exception e)
{
throw new JPOXUserException(e.getMessage(), e);
}
}
// Obtain MetaData for all classes to be processed
long startTime = System.currentTimeMillis();
FileMetaData[] filemds = null;
String puName = getStringProperty("org.jpox.PersistenceUnitName");
if (puName != null)
{
// Enhancement via "persistence-unit"
if (isVerbose())
{
msg = LOCALISER.msg("Enhancer.PersistenceUnit", puName);
addMessage(msg);
}
PersistenceUnitMetaData pumd = null;
try
{
pumd = metaDataMgr.getMetaDataForPersistenceUnit(puName);
}
catch (JPOXException jpe)
{
// No "persistence.xml" files found yet they have specified a persistence-unit name!
throw new JPOXUserException(LOCALISER.msg("Enhancer.PersistenceUnit.NoPersistenceFiles", puName));
}
if (pumd == null)
{
throw new JPOXUserException(LOCALISER.msg("Enhancer.PersistenceUnit.NoSuchUnit", puName));
}
// Initialise the MetaDataManager using the mapping files and classes
filemds = metaDataMgr.initialise(pumd, clr);
}
else
{
// Enhancement via "Input Files" (jdo/class) on command line
String[] inputfiles = getDefaultArgs();
if (inputfiles == null)
{
msg = LOCALISER.msg("Enhancer.NoInputFilesError");
JPOXLogger.ENHANCER.error(msg);
throw new JPOXUserException(msg);
}
if (isVerbose())
{
msg = LOCALISER.msg("Enhancer.InputFiles");
addMessage(msg);
for (int i = 0; i < inputfiles.length; i++)
{
String entry = LOCALISER.msg("Enhancer.InputFiles.Entry", inputfiles[i]);
JPOXLogger.ENHANCER.info(entry);
System.out.println(entry);
}
addMessage("");
}
// Read in the specified MetaData files - errors in MetaData will return exceptions and so we stop
Class classEnhancerClass = getClassEnhancerClass(clr);
try
{
// Split the input files into MetaData files and classes
JPOXLogger.ENHANCER.debug(LOCALISER.msg("Enhancer.ReadInputFilesStart", "" + inputfiles.length));
HashSet metadataFiles = new HashSet();
HashSet classNames = new HashSet();
for (int i=0;i<inputfiles.length;i++)
{
if (inputfiles[i].endsWith(".class"))
{
if (!StringUtils.getFileForFilename(inputfiles[i]).exists())
{
msg = LOCALISER.msg("Enhancer.InputFiles.Invalid", inputfiles[i]);
if (systemOut)
{
System.out.println(msg);
}
JPOXLogger.ENHANCER.error(msg);
}
else
{
// Class file so get the name of the class for this file
try
{
Method method = classEnhancerClass.getMethod("getClassNameForFileName",
new Class[] {String.class});
String className = (String)method.invoke(null, new String[] {inputfiles[i]});
classNames.add(className);
}
catch (InvocationTargetException ex)
{
msg = LOCALISER.msg("Enhancer.ClassEnhancer.MethodNotFound",
enhancerName, classEnhancerClass.getName(), "getClassNameForFileName", ex.getTargetException());
if (systemOut)
{
System.out.println(msg);
}
JPOXLogger.ENHANCER.error(msg);
}
catch (Exception e)
{
msg = LOCALISER.msg("Enhancer.ClassEnhancer.MethodNotFound",
enhancerName, classEnhancerClass.getName(), "getClassNameForFileName", e);
if (systemOut)
{
System.out.println(msg);
}
JPOXLogger.ENHANCER.error(msg);
}
}
}
else
{
// MetaData file
metadataFiles.add(inputfiles[i]);
}
}
// Initialise the MetaDataManager using the mapping files and class names
filemds = metaDataMgr.initialise((String[])metadataFiles.toArray(new String[metadataFiles.size()]),
(String[])classNames.toArray(new String[classNames.size()]), clr);
JPOXLogger.ENHANCER.debug(LOCALISER.msg("Enhancer.ReadInputFilesEnd", "" + inputfiles.length));
}
catch (JPOXException jpe)
{