org.springframework.roo.classpath.itd
Class AbstractItdMetadataProvider

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

public abstract class AbstractItdMetadataProvider
extends org.springframework.roo.metadata.AbstractHashCodeTrackingMetadataNotifier
implements ItdTriggerBasedMetadataProvider, org.springframework.roo.metadata.MetadataNotificationListener

Provides common functionality used by ITD-based generators.

This abstract class assumes:

Put differently, this abstract class assumes every ITD will have a corresponding "governor". A "governor" is defined as the type which will eventually receive the introduction. The abstract class assumes all metadata identification strings represent the name of the governor, albeit with a metadata class specific to the add-on. When an instance-specific metadata identification request is received, the governor will be obtained and in turn introspected for one of the trigger annotations. If these are detected, or if there is already an ITD file of the same name as would normally be created had a trigger annotation been found, the metadata will be created. The metadata creation method is expected to create, update or delete the ITD file as appropriate.

Since:
1.0
Author:
Ben Alex

Field Summary
protected  org.springframework.roo.process.manager.FileManager fileManager
           
protected  ItdDiscoveryService itdDiscoveryService
           
protected static Logger LOGGER
           
protected  MemberDetailsScanner memberDetailsScanner
           
protected  PersistenceMemberLocator persistenceMemberLocator
           
protected  TypeLocationService typeLocationService
           
 
Fields inherited from class org.springframework.roo.metadata.AbstractHashCodeTrackingMetadataNotifier
context, metadataDependencyRegistry, metadataService
 
Constructor Summary
AbstractItdMetadataProvider()
           
 
Method Summary
protected  void activate(org.osgi.service.component.ComponentContext cContext)
           
 void addMetadataTrigger(org.springframework.roo.model.JavaType javaType)
          Registers an additional JavaType that will trigger metadata registration.
 void addMetadataTriggers(org.springframework.roo.model.JavaType... triggerTypes)
          Registers the given JavaTypes as triggering metadata registration.
protected abstract  String createLocalIdentifier(org.springframework.roo.model.JavaType javaType, org.springframework.roo.project.LogicalPath path)
          Called whenever there is a requirement to produce a local identifier (ie an instance identifier consistent with MetadataProvider.getProvidesType()) for the indicated JavaType and Path.
 org.springframework.roo.metadata.MetadataItem get(String metadataIdentificationString)
           
 org.springframework.roo.process.manager.FileManager getFileManager()
           
protected abstract  String getGovernorPhysicalTypeIdentifier(String metadataIdentificationString)
          Called whenever there is a requirement to convert a local metadata identification string (ie an instance identifier consistent with MetadataProvider.getProvidesType()) into the corresponding governor physical type identifier.
 String getIdForPhysicalJavaType(String physicalJavaTypeIdentifier)
          Obtains an identifier that would be validly recognized by this ItdMetadataProvider instance.
 ItdDiscoveryService getItdDiscoveryService()
           
protected  String getLocalMid(MemberHoldingTypeDetails memberHoldingTypeDetails)
          Assists creating a local metadata identification string (MID) from any presented MemberHoldingTypeDetails implementation.
protected  MemberDetails getMemberDetails(ClassOrInterfaceTypeDetails cid)
          Returns details of the given class or interface type's members
protected  MemberDetails getMemberDetails(org.springframework.roo.model.JavaType type)
          Returns details of the given Java type's members
protected  MemberDetails getMemberDetails(PhysicalTypeMetadata physicalTypeMetadata)
          Returns details of the given physical type's members
 MemberDetailsScanner getMemberDetailsScanner()
           
protected abstract  ItdTypeDetailsProvidingMetadataItem getMetadata(String metadataIdentificationString, org.springframework.roo.model.JavaType aspectName, PhysicalTypeMetadata governorPhysicalTypeMetadata, String itdFilename)
          Called when it is time to create the actual metadata instance.
protected
<T extends org.springframework.roo.metadata.MetadataItem>
T
getParentMetadata(ClassOrInterfaceTypeDetails child)
          Looks up the given type's inheritance hierarchy for metadata of the given type, starting with the given type's parent and going upwards until the first such instance is found (i.e. lower level metadata takes priority over higher level metadata)
 PersistenceMemberLocator getPersistenceMemberLocator()
           
 TypeLocationService getTypeLocationService()
           
protected  boolean isGovernor(ClassOrInterfaceTypeDetails type)
          Indicates whether the given type is the governor for this provider.
protected  boolean isIgnoreTriggerAnnotations()
           
 void notify(String upstreamDependency, String downstreamDependency)
           
protected  void notifyForGenericListener(String upstreamDependency)
          Designed to handle events originating from a MetadataDependencyRegistry.addNotificationListener(MetadataNotificationListener) registration.
 void removeMetadataTrigger(org.springframework.roo.model.JavaType javaType)
          Removes a JavaType metadata trigger registration.
 void removeMetadataTriggers(org.springframework.roo.model.JavaType... triggerTypes)
          Removes the given JavaTypes as triggering metadata registration.
protected  String resolveDownstreamDependencyIdentifier(String upstreamDependency)
          Invoked whenever a "class-level" downstream dependency identifier is presented in a metadata notification.
 void setDependsOnGovernorBeingAClass(boolean dependsOnGovernorBeingAClass)
          If set to true (default is true), ensures the governor type details represent a class.
 void setDependsOnGovernorTypeDetailAvailability(boolean dependsOnGovernorTypeDetailAvailability)
          If set to true (default is true), ensures subclass not called unless the governor type details are available.
protected  void setIgnoreTriggerAnnotations(boolean ignoreTriggerAnnotations)
           
 
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
 

Field Detail

LOGGER

protected static final Logger LOGGER

fileManager

protected org.springframework.roo.process.manager.FileManager fileManager

itdDiscoveryService

protected ItdDiscoveryService itdDiscoveryService

memberDetailsScanner

protected MemberDetailsScanner memberDetailsScanner

persistenceMemberLocator

protected PersistenceMemberLocator persistenceMemberLocator

typeLocationService

protected TypeLocationService typeLocationService
Constructor Detail

AbstractItdMetadataProvider

public AbstractItdMetadataProvider()
Method Detail

activate

protected void activate(org.osgi.service.component.ComponentContext cContext)
Overrides:
activate in class org.springframework.roo.metadata.AbstractHashCodeTrackingMetadataNotifier

addMetadataTrigger

public void addMetadataTrigger(org.springframework.roo.model.JavaType javaType)
Registers an additional JavaType that will trigger metadata registration.

Specified by:
addMetadataTrigger in interface TriggerBasedMetadataProvider
Parameters:
javaType - the type-level annotation to detect that will cause metadata creation (required)

addMetadataTriggers

public void addMetadataTriggers(org.springframework.roo.model.JavaType... triggerTypes)
Registers the given JavaTypes as triggering metadata registration.

Parameters:
triggerTypes - the type-level annotations to detect that will cause metadata creation
Since:
1.2.0

createLocalIdentifier

protected abstract String createLocalIdentifier(org.springframework.roo.model.JavaType javaType,
                                                org.springframework.roo.project.LogicalPath path)
Called whenever there is a requirement to produce a local identifier (ie an instance identifier consistent with MetadataProvider.getProvidesType()) for the indicated JavaType and Path.

Parameters:
javaType - the type (required)
path - the path (required)
Returns:
an instance-specific identifier that is compatible with MetadataProvider.getProvidesType() (never null or empty)

get

public final org.springframework.roo.metadata.MetadataItem get(String metadataIdentificationString)
Specified by:
get in interface org.springframework.roo.metadata.MetadataProvider

getGovernorPhysicalTypeIdentifier

protected abstract String getGovernorPhysicalTypeIdentifier(String metadataIdentificationString)
Called whenever there is a requirement to convert a local metadata identification string (ie an instance identifier consistent with MetadataProvider.getProvidesType()) into the corresponding governor physical type identifier.

Parameters:
metadataIdentificationString - the local identifier (required)
Returns:
the physical type identifier of the governor (required)

getIdForPhysicalJavaType

public final String getIdForPhysicalJavaType(String physicalJavaTypeIdentifier)
Description copied from interface: ItdMetadataProvider
Obtains an identifier that would be validly recognized by this ItdMetadataProvider instance. The identifier must represent the presented physical Java type identifier.

The presented physical Java type identifier need not presently exist in the MetadataService. Implementations must not rely on the metadata being available at this moment. Implementations by returning a value from this method do not guarantee that metadata for the returned identifier will subsequently made available. As such this method is a basic conversion method and shouldn't perform any analysis.

Specified by:
getIdForPhysicalJavaType in interface ItdMetadataProvider
Parameters:
physicalJavaTypeIdentifier - to convert into a local metadata identifier (required)
Returns:
an identifier acceptable to this provider (must not return null or an empty string)

getLocalMid

protected String getLocalMid(MemberHoldingTypeDetails memberHoldingTypeDetails)
Assists creating a local metadata identification string (MID) from any presented MemberHoldingTypeDetails implementation. This is achieved by extracting the IdentifiableJavaStructure.getDeclaredByMetadataId() and converting it into a JavaType and Path, then calling #createLocalIdentifier(JavaType, Path).

Parameters:
memberHoldingTypeDetails - the member holder from which the declaring type information should be extracted (required)
Returns:
a MID produced by #createLocalIdentifier(JavaType, Path) for the extracted Java type in the extract Path (never null)

getMemberDetails

protected MemberDetails getMemberDetails(ClassOrInterfaceTypeDetails cid)
Returns details of the given class or interface type's members

Parameters:
cid - the physical type for which to get the members (can be null)
Returns:
null if the member details are unavailable

getMemberDetails

protected MemberDetails getMemberDetails(org.springframework.roo.model.JavaType type)
Returns details of the given Java type's members

Parameters:
type - the type for which to get the members (required)
Returns:
null if the member details are unavailable

getMemberDetails

protected MemberDetails getMemberDetails(PhysicalTypeMetadata physicalTypeMetadata)
Returns details of the given physical type's members

Parameters:
physicalTypeMetadata - the physical type for which to get the members (can be null)
Returns:
null if the member details are unavailable

getMetadata

protected abstract ItdTypeDetailsProvidingMetadataItem getMetadata(String metadataIdentificationString,
                                                                   org.springframework.roo.model.JavaType aspectName,
                                                                   PhysicalTypeMetadata governorPhysicalTypeMetadata,
                                                                   String itdFilename)
Called when it is time to create the actual metadata instance.

Parameters:
metadataIdentificationString - the local identifier (non-null and consistent with MetadataProvider.getProvidesType())
aspectName - the Java type name for the ITD (non-null and obtained via PhysicalTypeMetadata.getItdJavaType(ItdMetadataProvider) )
governorPhysicalTypeMetadata - the governor metadata (non-null and obtained via getGovernorPhysicalTypeIdentifier(String))
itdFilename - the canonical filename for the ITD (non-null and obtained via PhysicalTypeMetadata.getItdCanoncialPath(ItdMetadataProvider) )
Returns:
the new metadata (may return null if there is a problem processing)

getParentMetadata

protected <T extends org.springframework.roo.metadata.MetadataItem> T getParentMetadata(ClassOrInterfaceTypeDetails child)
Looks up the given type's inheritance hierarchy for metadata of the given type, starting with the given type's parent and going upwards until the first such instance is found (i.e. lower level metadata takes priority over higher level metadata)

Type Parameters:
T - the type of metadata to look for
Parameters:
child - the child type whose parents to search (required)
Returns:
null if there is no such metadata

isGovernor

protected boolean isGovernor(ClassOrInterfaceTypeDetails type)
Indicates whether the given type is the governor for this provider. This implementation simply checks whether the given type is either a class or an interface, based on the value of dependsOnGovernorBeingAClass . A more sophisticated implementation could check for the presence of particular annotations or the implementation of particular interfaces.

Parameters:
type - can be null
Returns:
false if the given type is null

isIgnoreTriggerAnnotations

protected boolean isIgnoreTriggerAnnotations()

notify

public final void notify(String upstreamDependency,
                         String downstreamDependency)
Specified by:
notify in interface org.springframework.roo.metadata.MetadataNotificationListener

notifyForGenericListener

protected void notifyForGenericListener(String upstreamDependency)
Designed to handle events originating from a MetadataDependencyRegistry.addNotificationListener(MetadataNotificationListener) registration. Such events are always presented with a non-null upstream dependency indicator and a null downstream dependency indicator. These events differ from events related to PhysicalTypeIdentifier registrations, as in those cases the downstream dependency indicator will be the class-level MetadataProvider.getProvidesType().

This method allows subclasses to specially handle generic MetadataDependencyRegistry events.

Parameters:
upstreamDependency - the upstream which was modified (guaranteed to be non-null, but could be class-level or instance-level)

removeMetadataTrigger

public void removeMetadataTrigger(org.springframework.roo.model.JavaType javaType)
Removes a JavaType metadata trigger registration. If the type was never registered, the method returns without an error.

Specified by:
removeMetadataTrigger in interface TriggerBasedMetadataProvider
Parameters:
javaType - to remove (required)

removeMetadataTriggers

public void removeMetadataTriggers(org.springframework.roo.model.JavaType... triggerTypes)
Removes the given JavaTypes as triggering metadata registration.

Parameters:
triggerTypes - the type-level annotations to remove as triggers
Since:
1.2.0

resolveDownstreamDependencyIdentifier

protected String resolveDownstreamDependencyIdentifier(String upstreamDependency)
Invoked whenever a "class-level" downstream dependency identifier is presented in a metadata notification. An "instance-specific" downstream dependency identifier is required so that a metadata request can ultimately be made. This method is responsible for evaluating the upstream dependency identifier and converting it into a valid downstream dependency identifier. The downstream dependency identifier must be of the same type as this metadata provider's MetadataProvider.getProvidesType(). The downstream dependency identifier must also be instance-specific.

The basic implementation offered in this class will only convert a PhysicalTypeIdentifier. If a subclass registers a dependency on an upstream (other than PhysicalTypeIdentifier.getMetadataIdentiferType()) and presents their MetadataProvider.getProvidesType() as the downstream (thus meaning only class-level downstream dependency identifiers will be presented), they must override this method and appropriately handle instance-specific downstream dependency identifier resolution.

This method may also return null if it wishes to abort processing of the notification. This may be appropriate if a determination cannot be made at this time for whatever reason (eg too early in a lifecycle etc).

Parameters:
upstreamDependency - the upstream (never null)
Returns:
an instance-specific MID of type MetadataProvider.getProvidesType() (or null if the metadata notification should be aborted)

setDependsOnGovernorBeingAClass

public void setDependsOnGovernorBeingAClass(boolean dependsOnGovernorBeingAClass)
If set to true (default is true), ensures the governor type details represent a class. Note that setDependsOnGovernorTypeDetailAvailability(boolean) must also be true to ensure this can be relied upon.

Parameters:
dependsOnGovernorBeingAClass - true means governor type detail must represent a class

setDependsOnGovernorTypeDetailAvailability

public void setDependsOnGovernorTypeDetailAvailability(boolean dependsOnGovernorTypeDetailAvailability)
If set to true (default is true), ensures subclass not called unless the governor type details are available.

Parameters:
dependsOnGovernorTypeDetailAvailability - true means governor type details must be available

setIgnoreTriggerAnnotations

protected void setIgnoreTriggerAnnotations(boolean ignoreTriggerAnnotations)

getFileManager

public org.springframework.roo.process.manager.FileManager getFileManager()

getItdDiscoveryService

public ItdDiscoveryService getItdDiscoveryService()

getMemberDetailsScanner

public MemberDetailsScanner getMemberDetailsScanner()

getTypeLocationService

public TypeLocationService getTypeLocationService()

getPersistenceMemberLocator

public PersistenceMemberLocator getPersistenceMemberLocator()


Copyright © 2009–2015. All rights reserved.