ClassOrInterfaceTypeDetails serviceInterface = null;
for (final JavaType implementedType : serviceClass.getImplementsTypes()) {
final ClassOrInterfaceTypeDetails potentialServiceInterfaceTypeDetails = typeLocationService
.getTypeDetails(implementedType);
if (potentialServiceInterfaceTypeDetails != null) {
final LogicalPath path = PhysicalTypeIdentifier
.getPath(potentialServiceInterfaceTypeDetails
.getDeclaredByMetadataId());
final String implementedTypeId = ServiceInterfaceMetadata
.createIdentifier(implementedType, path);
if ((serviceInterfaceMetadata = (ServiceInterfaceMetadata) metadataService
.get(implementedTypeId)) != null) {
// Found the metadata for the service interface
serviceInterface = potentialServiceInterfaceTypeDetails;
break;
}
}
}
if (serviceInterface == null || serviceInterfaceMetadata == null
|| !serviceInterfaceMetadata.isValid()) {
return null;
}
// Register this provider for changes to the service interface // TODO
// move this down in case we return null early below?
metadataDependencyRegistry.registerDependency(
serviceInterfaceMetadata.getId(), metadataIdentificationString);
final ServiceAnnotationValues serviceAnnotationValues = serviceInterfaceMetadata
.getServiceAnnotationValues();
final JavaType[] domainTypes = serviceAnnotationValues.getDomainTypes();
if (domainTypes == null) {
return null;
}
/*
* For each domain type, collect (1) the plural and (2) the additions to
* make to the service class for calling a lower layer when implementing
* each service layer method. We use LinkedHashMaps for the latter
* nested map to ensure repeatable order of code generation.
*/
final Map<JavaType, String> domainTypePlurals = new HashMap<JavaType, String>();
final Map<JavaType, JavaType> domainTypeToIdTypeMap = new HashMap<JavaType, JavaType>();
// Collect the additions for each method for each supported domain type
final Map<JavaType, Map<ServiceLayerMethod, MemberTypeAdditions>> allCrudAdditions = new LinkedHashMap<JavaType, Map<ServiceLayerMethod, MemberTypeAdditions>>();
for (final JavaType domainType : domainTypes) {
final JavaType idType = persistenceMemberLocator
.getIdentifierType(domainType);
if (idType == null) {
return null;
}
domainTypeToIdTypeMap.put(domainType, idType);
// Collect the plural for this domain type
final ClassOrInterfaceTypeDetails domainTypeDetails = typeLocationService
.getTypeDetails(domainType);
if (domainTypeDetails == null) {
return null;
}
final LogicalPath path = PhysicalTypeIdentifier
.getPath(domainTypeDetails.getDeclaredByMetadataId());
final String pluralId = PluralMetadata.createIdentifier(domainType,
path);
final PluralMetadata pluralMetadata = (PluralMetadata) metadataService
.get(pluralId);