org.springframework.roo.classpath.itd
Class AbstractMemberDiscoveringItdMetadataProvider

java.lang.Object
  extended by org.springframework.roo.metadata.AbstractHashCodeTrackingMetadataNotifier
      extended by org.springframework.roo.classpath.itd.AbstractItdMetadataProvider
          extended by org.springframework.roo.classpath.itd.AbstractMemberDiscoveringItdMetadataProvider
All Implemented Interfaces:
ItdMetadataProvider, ItdTriggerBasedMetadataProvider, TriggerBasedMetadataProvider, org.springframework.roo.metadata.MetadataNotificationListener, org.springframework.roo.metadata.MetadataProvider

public abstract class AbstractMemberDiscoveringItdMetadataProvider
extends AbstractItdMetadataProvider

Simplifies the development of ItdMetadataProviders that wish to automatically discover new ItdTypeDetails that become available elsewhere in the system, even if the ItdMetadataProvider is not registered as a downstream dependency.

This class helps solves the common requirement of not knowing which other add-ons might be providing metadata you are interested in. While MemberDetailsScanner will locate all metadata presently available in the system, this is a snapshot of metadata at that moment in time. While it's simple (and normal practice) to register as a downstream dependency of scanned metadata that you wish to monitor, this approach is insufficient to discover new metadata that subsequently becomes available (or even discover metadata that previously was available but did not contain members of interest at that moment in time and were therefore not registered as a dependency to monitor).

The practical solution to these problems is to subclass this class, implement the abstract getLocalMidToRequest(ItdTypeDetails), and in the activate method register a generic listener as described in the documentation for notifyForGenericListener(String). This class will then receive all generic notifications, determine if they relate to an ITD, extract the ItdTypeDetails, and present it to getLocalMidToRequest(ItdTypeDetails). The latter method allows the subclass to decide if they want to be formally asked for new metadata, in which case this class will do so. Importantly the subclass can decide the exact metadata identification string to request, allowing flexibility in implementation (eg a subclass could monitor for new ITD metadata related to types other than simply their normal governor types).

Since:
1.1.1
Author:
Ben Alex

Field Summary
 
Fields inherited from class org.springframework.roo.classpath.itd.AbstractItdMetadataProvider
fileManager, itdDiscoveryService, LOGGER, memberDetailsScanner, persistenceMemberLocator, typeLocationService
 
Fields inherited from class org.springframework.roo.metadata.AbstractHashCodeTrackingMetadataNotifier
context, metadataDependencyRegistry, metadataService
 
Constructor Summary
AbstractMemberDiscoveringItdMetadataProvider()
           
 
Method Summary
protected abstract  String getLocalMidToRequest(ItdTypeDetails itdTypeDetails)
          Allows a subclass to assess a recently updated ItdTypeDetails and decide whether they are interested in a metadata request being made in response.
protected  void notifyForGenericListener(String upstreamDependency)
          Receives generic notification events arising from our calling of MetadataDependencyRegistry.addNotificationListener(this).
 
Methods inherited from class org.springframework.roo.classpath.itd.AbstractItdMetadataProvider
activate, addMetadataTrigger, addMetadataTriggers, createLocalIdentifier, get, getFileManager, getGovernorPhysicalTypeIdentifier, getIdForPhysicalJavaType, getItdDiscoveryService, getLocalMid, getMemberDetails, getMemberDetails, getMemberDetails, getMemberDetailsScanner, getMetadata, getParentMetadata, getPersistenceMemberLocator, getTypeLocationService, isGovernor, isIgnoreTriggerAnnotations, notify, removeMetadataTrigger, removeMetadataTriggers, resolveDownstreamDependencyIdentifier, setDependsOnGovernorBeingAClass, setDependsOnGovernorTypeDetailAvailability, setIgnoreTriggerAnnotations
 
Methods inherited from class org.springframework.roo.metadata.AbstractHashCodeTrackingMetadataNotifier
getMetadataDependencyRegistry, getMetadataService, notifyIfRequired
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.springframework.roo.classpath.itd.ItdMetadataProvider
getItdUniquenessFilenameSuffix
 
Methods inherited from interface org.springframework.roo.metadata.MetadataProvider
getProvidesType
 

Constructor Detail

AbstractMemberDiscoveringItdMetadataProvider

public AbstractMemberDiscoveringItdMetadataProvider()
Method Detail

getLocalMidToRequest

protected abstract String getLocalMidToRequest(ItdTypeDetails itdTypeDetails)
Allows a subclass to assess a recently updated ItdTypeDetails and decide whether they are interested in a metadata request being made in response. Subclasses will generally iterate over the passed ITD details and search for members of interest. If any members of interest are located, subclasses will return an instance-specific metadata identification string (MID) consistent with the subclass' MetadataProvider.getProvidesType() The requested MID will be cleared from the cache and formally requested. This process allows subclasses to effectively discover new ITD members that appear over time without needing to process every request themselves.

Parameters:
itdTypeDetails - a valid ItdTypeDetails from which member information is available (never null)
Returns:
null if the subclass is not interested in the type, or a MID if it is

notifyForGenericListener

protected final void notifyForGenericListener(String upstreamDependency)
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.

Overrides:
notifyForGenericListener in class AbstractItdMetadataProvider
Parameters:
upstreamDependency - the upstream which was modified (guaranteed to be non-null, but could be class-level or instance-level)
See Also:
AbstractItdMetadataProvider.notifyForGenericListener(String)


Copyright © 2009–2015. All rights reserved.