// Include the classloader if it is a bean
ClassLoaderMetaData classLoaderMetaData = getClassLoader();
if (classLoaderMetaData != null)
{
ValueMetaData classLoader = classLoaderMetaData.getClassLoader();
if (classLoader instanceof BeanMetaData)
{
// Hack, if it doesn't have a classloader use the "null" classloader
// we don't want it to gain itself as the classloader
BeanMetaData classLoaderBean = (BeanMetaData) classLoader;
if (classLoaderBean.getClassLoader() == null)
classLoaderBean.setClassLoader(new AbstractClassLoaderMetaData(new AbstractValueMetaData()));
result.add((BeanMetaData) classLoader);
}
}
List<BeanMetaDataFactory> factories = getBeanFactories();
if (factories != null && factories.isEmpty() == false)
{
for (BeanMetaDataFactory factory : factories)
{
if (factory == null)
throw new IllegalArgumentException("BeanMetaDataFactory cannot be null.");
List<BeanMetaData> beans = factory.getBeans();
if (beans != null && beans.isEmpty() == false)
{
for (BeanMetaData bmd : beans)
{
if (bmd == null)
throw new IllegalArgumentException("Bean meta data cannot be null.");
// check annotations
if (annotations != null && annotations.isEmpty() == false)
{
Set<AnnotationMetaData> annotationsBMD = bmd.getAnnotations();
if (annotationsBMD == null)
{
annotationsBMD = new HashSet<AnnotationMetaData>();
bmd.setAnnotations(annotationsBMD);
}
annotationsBMD.addAll(annotations);
}
// impl specific
if (bmd instanceof AbstractBeanMetaData)
{
AbstractBeanMetaData bean = (AbstractBeanMetaData)bmd;
// set deployment defaults, if not already set per bean
if (bean.getCreate() == null && getCreate() != null)
{
bean.setCreate(getCreate());
}
if (bean.getStart() == null && getStart() != null)
{
bean.setStart(getStart());
}
if (bean.getStop() == null && getStop() != null)
{
bean.setStop(getStop());
}
if (bean.getDestroy() == null && getDestroy() != null)
{
bean.setDestroy(getDestroy());
}
// controller mode
if (bean.getMode() == null && getMode() != null)
{
bean.setMode(getMode());
}
}
// Use any deployment classloader if present and the bean doesn't have one
ClassLoaderMetaData beanClassLoader = bmd.getClassLoader();
if (beanClassLoader == null)
{
ClassLoaderMetaData deploymentClassLoader = getClassLoader();
if (deploymentClassLoader != null)
{
// If the deployment classloader is a bean, replace it with an injection
ValueMetaData classLoader = deploymentClassLoader.getClassLoader();
if (classLoader instanceof BeanMetaData)
{
classLoader = new AbstractDependencyValueMetaData(((BeanMetaData) classLoader).getName());
beanClassLoader = new AbstractClassLoaderMetaData(classLoader);
}