org.springframework.roo.classpath.itd
Class AbstractItdMetadataProvider

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

public abstract class AbstractItdMetadataProvider
extends Object
implements ItdRoleAwareMetadataProvider, 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  org.springframework.roo.metadata.MetadataDependencyRegistry metadataDependencyRegistry
           
protected  org.springframework.roo.metadata.MetadataService metadataService
           
 
Constructor Summary
AbstractItdMetadataProvider()
           
 
Method Summary
 void addMetadataTrigger(org.springframework.roo.model.JavaType javaType)
          Registers an additional JavaType that will trigger metadata registration.
protected  void addProviderRole(ItdProviderRole role)
           
protected abstract  String createLocalIdentifier(org.springframework.roo.model.JavaType javaType, org.springframework.roo.project.Path 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)
           
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.
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.
 Set<ItdProviderRole> getRoles()
           
protected  boolean isIgnoreTriggerAnnotations()
           
 void notify(String upstreamDependency, String downstreamDependency)
           
 void removeMetadataTrigger(org.springframework.roo.model.JavaType javaType)
          Removes a JavaType metadata trigger registration.
protected  void removeProviderRole(ItdProviderRole role)
           
 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 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

metadataDependencyRegistry

@Reference
protected org.springframework.roo.metadata.MetadataDependencyRegistry metadataDependencyRegistry

fileManager

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

metadataService

@Reference
protected org.springframework.roo.metadata.MetadataService metadataService
Constructor Detail

AbstractItdMetadataProvider

public AbstractItdMetadataProvider()
Method Detail

notify

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

createLocalIdentifier

protected abstract String createLocalIdentifier(org.springframework.roo.model.JavaType javaType,
                                                org.springframework.roo.project.Path 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)

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)

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)

addMetadataTrigger

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

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

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 ItdRoleAwareMetadataProvider
Parameters:
javaType - to remove (required)

addProviderRole

protected final void addProviderRole(ItdProviderRole role)

removeProviderRole

protected final void removeProviderRole(ItdProviderRole role)

isIgnoreTriggerAnnotations

protected boolean isIgnoreTriggerAnnotations()

setIgnoreTriggerAnnotations

protected void setIgnoreTriggerAnnotations(boolean ignoreTriggerAnnotations)

get

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

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)

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

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

getRoles

public final Set<ItdProviderRole> getRoles()
Specified by:
getRoles in interface ItdRoleAwareMetadataProvider
Returns:
the roles this provider offers (never null, but may be empty)


Copyright © 2009-2010 VMware, Inc. All Rights Reserved.