// Compute the identifier for the Physical Type Metadata we're
// correlated with
final String governorPhysicalTypeIdentifier = getGovernorPhysicalTypeIdentifier(metadataIdentificationString);
// Obtain the physical type
final PhysicalTypeMetadata governorPhysicalTypeMetadata = (PhysicalTypeMetadata) metadataService
.get(governorPhysicalTypeIdentifier);
if (governorPhysicalTypeMetadata == null
|| !governorPhysicalTypeMetadata.isValid()) {
// We can't get even basic information about the physical type, so
// abort (the ITD will be deleted by ItdFileDeletionService)
return null;
}
// Flag to indicate whether we'll even try to create this metadata
boolean produceMetadata = false;
// Determine if we should generate the metadata on the basis of it
// containing a trigger annotation
final ClassOrInterfaceTypeDetails cid = governorPhysicalTypeMetadata
.getMemberHoldingTypeDetails();
if (cid != null) {
// Only create metadata if the type is annotated with one of the
// metadata triggers
for (final JavaType trigger : metadataTriggers) {
if (cid.getAnnotation(trigger) != null) {
produceMetadata = true;
break;
}
}
}
// Fall back to ignoring trigger annotations
if (ignoreTriggerAnnotations) {
produceMetadata = true;
}
// Cancel production if the governor type details are required, but
// aren't available
if (dependsOnGovernorTypeDetailAvailability && cid == null) {
produceMetadata = false;
}
// Cancel production if the governor is not a class, and the subclass
// only wants to know about classes
if (cid != null && dependsOnGovernorBeingAClass
&& cid.getPhysicalTypeCategory() != PhysicalTypeCategory.CLASS) {
produceMetadata = false;
}
final String itdFilename = governorPhysicalTypeMetadata
.getItdCanonicalPath(this);
if (!produceMetadata && isGovernor(cid)
&& fileManager.exists(itdFilename)) {
// We don't seem to want metadata anymore, yet the ITD physically
// exists, so get rid of it
// This might be because the trigger annotation has been removed,
// the governor is missing a class declaration, etc.
deleteItd(metadataIdentificationString, itdFilename,
"not required for governor " + cid.getName(), true);
return null;
}
if (produceMetadata) {
// This type contains an annotation we were configured to detect, or
// there is an ITD (which may need deletion), so we need to produce
// the metadata
final JavaType aspectName = governorPhysicalTypeMetadata
.getItdJavaType(this);
final ItdTypeDetailsProvidingMetadataItem metadata = getMetadata(
metadataIdentificationString, aspectName,
governorPhysicalTypeMetadata, itdFilename);