public ManagedDeployment build(DeploymentUnit unit,
Map<String, ManagedObject> unitMOs,
ManagedDeployment parent)
{
DeploymentPhase phase = unit.getAttachment(DeploymentPhase.class);
ManagementDeployment mdAnnotation = null;
HashMap<String, ManagedObject> validUnitMOs = new HashMap<String, ManagedObject>();
for(String name : unitMOs.keySet())
{
// TODO: why should there be null ManagedObjects?
ManagedObject mo = unitMOs.get(name);
if(mo == null)
continue;
validUnitMOs.put(name, mo);
Map<String, Annotation> annotations = mo.getAnnotations();
if(annotations != null && mdAnnotation == null)
mdAnnotation = (ManagementDeployment) annotations.get(ManagementDeployment.class.getName());
}
String simpleName = unit.getSimpleName();
String[] types = {};
if(mdAnnotation != null)
{
if(phase == null)
phase = mdAnnotation.phase();
String mdaSimpleName = mdAnnotation.simpleName();
if(mdaSimpleName.length() > 0 && ManagementConstants.GENERATED.equals(mdaSimpleName) == false)
simpleName = mdAnnotation.simpleName();
types = mdAnnotation.types();
}
if( phase == null )
phase = DeploymentPhase.APPLICATION;
ManagedDeployment md = new ManagedDeploymentImpl(unit.getName(), simpleName, phase, parent, validUnitMOs);