use of org.springframework.roo.metadata.MetadataItem in project spring-roo by spring-projects.
the class AbstractMemberDiscoveringItdMetadataProvider method notifyForGenericListener.
/**
* Receives generic notification events arising from our calling of
* MetadataDependencyRegistry.addNotificationListener(this). You must still
* register in the activate method to receive these events, as described in
* the JavaDocs for the superclass method of the same name.
*
* @see AbstractItdMetadataProvider#notifyForGenericListener(String)
*/
@Override
protected final void notifyForGenericListener(final String upstreamDependency) {
if (MetadataIdentificationUtils.isIdentifyingClass(upstreamDependency)) {
// don't care about it
return;
}
// We have an instance-specific identifier; try to get its metadata
final MetadataItem metadata = getMetadataService().get(upstreamDependency);
// the relevant .java once the DOD governor is first detected
if (!(metadata instanceof ItdTypeDetailsProvidingMetadataItem) || !metadata.isValid()) {
// It's not for an ITD, or there's something wrong with it
return;
}
// Get the details of the ITD
final ItdTypeDetails itdTypeDetails = ((ItdTypeDetailsProvidingMetadataItem) metadata).getMemberHoldingTypeDetails();
if (itdTypeDetails == null) {
return;
}
// Ask the subclass if they'd like us to request a MetadataItem in
// response
final String localMid = getLocalMidToRequest(itdTypeDetails);
if (localMid != null) {
Validate.isTrue(MetadataIdentificationUtils.isIdentifyingInstance(localMid), "Metadata identification string '%s' should identify a specific instance to request", localMid);
Validate.isTrue(MetadataIdentificationUtils.getMetadataClass(localMid).equals(MetadataIdentificationUtils.getMetadataClass(getProvidesType())), "Metadata identification string '%s' is incompatible with this metadata provider's class '%s'", MetadataIdentificationUtils.getMetadataClass(localMid), MetadataIdentificationUtils.getMetadataClass(getProvidesType()));
getMetadataService().evictAndGet(localMid);
}
}
use of org.springframework.roo.metadata.MetadataItem in project spring-roo by spring-projects.
the class JspMetadataListener method notify.
public void notify(final String upstreamDependency, String downstreamDependency) {
if (MetadataIdentificationUtils.isIdentifyingClass(downstreamDependency)) {
// been
if (WebScaffoldMetadata.isValid(upstreamDependency)) {
final JavaType javaType = WebScaffoldMetadata.getJavaType(upstreamDependency);
final LogicalPath path = WebScaffoldMetadata.getPath(upstreamDependency);
downstreamDependency = JspMetadata.createIdentifier(javaType, path);
} else if (WebFinderMetadata.isValid(upstreamDependency)) {
final JavaType javaType = WebFinderMetadata.getJavaType(upstreamDependency);
final LogicalPath path = WebFinderMetadata.getPath(upstreamDependency);
downstreamDependency = JspMetadata.createIdentifier(javaType, path);
}
// later on)
if (getMetadataDependencyRegistry().getDownstream(upstreamDependency).contains(downstreamDependency)) {
return;
}
} else if (MetadataIdentificationUtils.isIdentifyingInstance(upstreamDependency)) {
// This is the generic fallback listener, ie from
// MetadataDependencyRegistry.addListener(this) in the activate()
// method
// Get the metadata that just changed
final MetadataItem metadataItem = getMetadataService().get(upstreamDependency);
// detected
if (metadataItem == null || !metadataItem.isValid() || !(metadataItem instanceof ItdTypeDetailsProvidingMetadataItem)) {
// let's gracefully abort
return;
}
// Let's ensure we have some ITD type details to actually work with
final ItdTypeDetailsProvidingMetadataItem itdMetadata = (ItdTypeDetailsProvidingMetadataItem) metadataItem;
final ItdTypeDetails itdTypeDetails = itdMetadata.getMemberHoldingTypeDetails();
if (itdTypeDetails == null) {
return;
}
final String localMid = formBackingObjectTypesToLocalMids.get(itdTypeDetails.getGovernor().getName());
if (localMid != null) {
getMetadataService().evictAndGet(localMid);
}
return;
}
if (MetadataIdentificationUtils.isIdentifyingInstance(downstreamDependency)) {
getMetadataService().evictAndGet(downstreamDependency);
}
}
use of org.springframework.roo.metadata.MetadataItem in project spring-roo by spring-projects.
the class MemberDetailsScannerImpl method getMemberDetails.
public final MemberDetails getMemberDetails(final String requestingClass, ClassOrInterfaceTypeDetails cid) {
if (metadataService == null) {
metadataService = getMetadataService();
}
if (providers.isEmpty()) {
bindProviders();
}
if (decorators.isEmpty()) {
bindDecorators();
}
if (cid == null) {
return null;
}
synchronized (lock) {
// Create a list of discovered members
final List<MemberHoldingTypeDetails> memberHoldingTypeDetails = new ArrayList<MemberHoldingTypeDetails>();
// Build a List representing the class hierarchy, where the first
// element is the absolute superclass
final List<ClassOrInterfaceTypeDetails> cidHierarchy = new ArrayList<ClassOrInterfaceTypeDetails>();
while (cid != null) {
// Note to the top of the list
cidHierarchy.add(0, cid);
cid = cid.getSuperclass();
}
// Now we add this governor, plus all of its superclasses
for (final ClassOrInterfaceTypeDetails currentClass : cidHierarchy) {
memberHoldingTypeDetails.add(currentClass);
// thus MemberHoldingTypeDetails information
for (final MetadataProvider mp : providers) {
// Skip non-ITD providers
if (!(mp instanceof ItdMetadataProvider)) {
continue;
}
// Skip myself
if (mp.getClass().getName().equals(requestingClass)) {
continue;
}
// Determine the key the ITD provider uses for this
// particular type
final String key = ((ItdMetadataProvider) mp).getIdForPhysicalJavaType(currentClass.getDeclaredByMetadataId());
Validate.isTrue(MetadataIdentificationUtils.isIdentifyingInstance(key), "ITD metadata provider '%s' returned an illegal key ('%s')", mp, key);
// Get the metadata and ensure we have ITD type details
// available
final MetadataItem metadataItem = metadataService.get(key);
if (metadataItem == null || !metadataItem.isValid()) {
continue;
}
Validate.isInstanceOf(ItdTypeDetailsProvidingMetadataItem.class, metadataItem, "ITD metadata provider '%s' failed to return the correct metadata type", mp);
final ItdTypeDetailsProvidingMetadataItem itdTypeDetailsMd = (ItdTypeDetailsProvidingMetadataItem) metadataItem;
if (itdTypeDetailsMd.getMemberHoldingTypeDetails() == null) {
continue;
}
// Capture the member details
memberHoldingTypeDetails.add(itdTypeDetailsMd.getMemberHoldingTypeDetails());
}
}
// Turn out list of discovered members into a result
MemberDetails result = new MemberDetailsImpl(memberHoldingTypeDetails);
// Loop until such time as we complete a full loop where no changes
// are made to the result
boolean additionalLoopRequired = true;
while (additionalLoopRequired) {
additionalLoopRequired = false;
for (final MemberDetailsDecorator decorator : decorators) {
final MemberDetails newResult = decorator.decorate(requestingClass, result);
Validate.isTrue(newResult != null, "Decorator '%s' returned an illegal result", decorator.getClass().getName());
if (newResult != null && !newResult.equals(result)) {
additionalLoopRequired = true;
}
result = newResult;
}
}
return result;
}
}
Aggregations