* them into the MetaDataManager, returning the associated FileMetaData.
* @return The FileMetaData for the registered components.
*/
protected Collection<FileMetaData> getFileMetadataForInput()
{
MetaDataManager metadataMgr = getMetaDataManager();
Iterator<EnhanceComponent> iter = componentsToEnhance.iterator();
Collection<FileMetaData> fileMetaData = new ArrayList<FileMetaData>();
while (iter.hasNext())
{
EnhanceComponent comp = iter.next();
FileMetaData[] filemds = null;
switch (comp.getType())
{
case EnhanceComponent.CLASS : // Of the form "mydomain.MyClass"
if (comp.getValue() instanceof String)
{
// Single class
String className = (String)comp.getValue();
if (bytesForClassesToEnhanceByClassName != null &&
bytesForClassesToEnhanceByClassName.get(className) != null)
{
// Retrieve the meta-data "file"
AbstractClassMetaData cmd = metadataMgr.getMetaDataForClass(className, clr);
if (cmd != null)
{
filemds = new FileMetaData[] {cmd.getPackageMetaData().getFileMetaData()};
}
else
{
// No meta-data has been registered for this byte-defined class!
}
}
else
{
filemds = metadataMgr.loadClasses(new String[] {(String)comp.getValue()},
userClassLoader);
}
}
else
{
// Multiple classes
filemds = metadataMgr.loadClasses((String[])comp.getValue(), userClassLoader);
}
break;
case EnhanceComponent.CLASS_FILE : // Absolute/relative filename(s)
if (comp.getValue() instanceof String)
{
// Single class file
String className = null;
String classFilename = (String)comp.getValue();
if (!StringUtils.getFileForFilename(classFilename).exists())
{
String msg = LOCALISER.msg("Enhancer.InputFiles.Invalid", classFilename);
addMessage(msg, true);
}
else
{
className = getClassNameForFilename(classFilename);
}
if (className != null)
{
filemds = metadataMgr.loadClasses(new String[] {className}, userClassLoader);
}
}
else
{
// Multiple class files
Collection<String> classNames = new ArrayList<String>();
String[] classFilenames = (String[])comp.getValue();
for (int i=0;i<classFilenames.length;i++)
{
String className = null;
if (!StringUtils.getFileForFilename(classFilenames[i]).exists())
{
String msg = LOCALISER.msg("Enhancer.InputFiles.Invalid", classFilenames[i]);
addMessage(msg, true);
}
else
{
className = getClassNameForFilename(classFilenames[i]);
}
if (className != null)
{
classNames.add(className);
}
}
filemds = metadataMgr.loadClasses(classNames.toArray(new String[classNames.size()]),
userClassLoader);
}
break;
case EnhanceComponent.MAPPING_FILE : // Absolute/relative filename(s)
if (comp.getValue() instanceof String)
{
// Single mapping file
filemds = metadataMgr.loadMetadataFiles(new String[] {(String)comp.getValue()},
userClassLoader);
}
else
{
// Multiple mapping files
filemds = metadataMgr.loadMetadataFiles((String[])comp.getValue(), userClassLoader);
}
break;
case EnhanceComponent.JAR_FILE : // Absolute/relative filename(s)
if (comp.getValue() instanceof String)
{
// Single jar file
filemds = metadataMgr.loadJar((String)comp.getValue(), userClassLoader);
}
else
{
// Multiple jar files
String[] jarFilenames = (String[])comp.getValue();
Collection<FileMetaData> filemdsColl = new HashSet<FileMetaData>();
for (int i=0;i<jarFilenames.length;i++)
{
FileMetaData[] fmds = metadataMgr.loadJar(jarFilenames[i], userClassLoader);
for (int j=0;j<fmds.length;j++)
{
filemdsColl.add(fmds[j]);
}
}
filemds = filemdsColl.toArray(new FileMetaData[filemdsColl.size()]);
}
break;
case EnhanceComponent.PERSISTENCE_UNIT :
PersistenceUnitMetaData pumd = null;
try
{
pumd = getMetaDataManager().getMetaDataForPersistenceUnit((String)comp.getValue());
}
catch (NucleusException ne)
{
// No "persistence.xml" files found yet they have specified a persistence-unit name!
throw new NucleusEnhanceException(
LOCALISER.msg("Enhancer.PersistenceUnit.NoPersistenceFiles", comp.getValue()));
}
if (pumd == null)
{
throw new NucleusEnhanceException(
LOCALISER.msg("Enhancer.PersistenceUnit.NoSuchUnit", comp.getValue()));
}
filemds = metadataMgr.loadPersistenceUnit(pumd, userClassLoader);
break;
default :
break;
}