protected static StructureMetaData assureStructure(PredeterminedManagedObjectAttachments context)
{
if (context == null)
throw new IllegalArgumentException("Null context");
MutableAttachments mutable;
Attachments attachments = context.getPredeterminedManagedObjects();
// Nothing predetermined yet
if (attachments == null)
{
mutable = AttachmentsFactory.createMutableAttachments();;
context.setPredeterminedManagedObjects(mutable);
}
// Some predetermined but needs to be made mutable
else if (attachments instanceof MutableAttachments == false)
{
mutable = AttachmentsFactory.createMutableAttachments();
Map<String, Object> map = attachments.getAttachments();
if (map != null)
mutable.setAttachments(map);
context.setPredeterminedManagedObjects(mutable);
}
else
{
mutable = (MutableAttachments) attachments;
}
StructureMetaData structure = mutable.getAttachment(StructureMetaData.class);
// No previous structure
if (structure == null)
{
structure = StructureMetaDataFactory.createStructureMetaData();
mutable.addAttachment(StructureMetaData.class, structure);
}
return structure;
}