I can get them by name which does not always serve the purpose.
Or do I need to do the following:
I think the call to unit.getAttachment(Class) works only if the attachment has been added to the unit without any name, because of the following pattern in AS trunk:
// The ServiceConstructorMetaData is not serializable due to its args unit.addAttachment(ServiceMetaData.class, webModule); .... // Get the war URL WebMetaData metaData = di.getAttachment(WebMetaData.class);
The getAttachment(class) call walks through the various type of attachments. What deployment is not showing the metadata that should?
Right, the key for the getAttachment(class) call is the class name. If a different name was used, you need to use the getAttachment(String name, Class expectedType) method.