Skip to content

Commit

Permalink
ROO-2745: Post 1.2.0.M1 code refactor and clean up - added MemberHold…
Browse files Browse the repository at this point in the history
…ingTypeDetails.getLayerEntities() and updated calling code
  • Loading branch information
Andrew Swan committed Oct 5, 2011
1 parent fed3d0e commit 91b7a2e
Show file tree
Hide file tree
Showing 9 changed files with 87 additions and 100 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,12 @@ protected void deactivate(ComponentContext context) {

protected String getLocalMidToRequest(ItdTypeDetails itdTypeDetails) {
// Determine the governor for this ITD, and whether any DOD metadata is even hoping to hear about changes to that JavaType and its ITDs
JavaType governor = itdTypeDetails.getName();
final JavaType governor = itdTypeDetails.getName();

Object layerTypeValue = itdTypeDetails.getGovernor().getCustomData().get(CustomDataKeys.LAYER_TYPE);
if (layerTypeValue != null) {
@SuppressWarnings("unchecked")
List<JavaType> domainTypes = (List<JavaType>) layerTypeValue;
for (JavaType type : domainTypes) {
String localMidType = entityToDodMidMap.get(type);
if (localMidType != null) {
return localMidType;
}
for (final JavaType type : itdTypeDetails.getGovernor().getLayerEntities()) {
String localMidType = entityToDodMidMap.get(type);
if (localMidType != null) {
return localMidType;
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package org.springframework.roo.addon.gwt.request;

import static org.springframework.roo.model.RooJavaType.ROO_GWT_PROXY;
import static org.springframework.roo.model.RooJavaType.ROO_GWT_REQUEST;
import static org.springframework.roo.model.RooJavaType.ROO_SERVICE;

import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Arrays;
Expand All @@ -16,7 +20,6 @@
import org.springframework.roo.addon.gwt.GwtUtils;
import org.springframework.roo.classpath.PhysicalTypeIdentifier;
import org.springframework.roo.classpath.TypeLocationService;
import org.springframework.roo.classpath.customdata.CustomDataKeys;
import org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails;
import org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetailsBuilder;
import org.springframework.roo.classpath.details.MemberFindingUtils;
Expand All @@ -35,7 +38,6 @@
import org.springframework.roo.metadata.MetadataItem;
import org.springframework.roo.model.DataType;
import org.springframework.roo.model.JavaType;
import org.springframework.roo.model.RooJavaType;
import org.springframework.roo.project.Path;
import org.springframework.roo.project.ProjectMetadata;
import org.springframework.roo.project.ProjectOperations;
Expand Down Expand Up @@ -77,7 +79,7 @@ public MetadataItem get(String metadataIdentificationString) {
return null;
}

AnnotationMetadata mirrorAnnotation = MemberFindingUtils.getAnnotationOfType(request.getAnnotations(), RooJavaType.ROO_GWT_REQUEST);
AnnotationMetadata mirrorAnnotation = MemberFindingUtils.getAnnotationOfType(request.getAnnotations(), ROO_GWT_REQUEST);
if (mirrorAnnotation == null) {
return null;
}
Expand Down Expand Up @@ -118,24 +120,24 @@ public MetadataItem get(String metadataIdentificationString) {
}

private List<String> getMethodExclusions(ClassOrInterfaceTypeDetails request) {
List<String> exclusionList = GwtUtils.getAnnotationValues(request, RooJavaType.ROO_GWT_REQUEST, "exclude");
List<String> exclusionList = GwtUtils.getAnnotationValues(request, ROO_GWT_REQUEST, "exclude");
ClassOrInterfaceTypeDetails proxy = gwtTypeService.lookupProxyFromRequest(request);
if (proxy != null) {
Boolean ignoreProxyExclusions = GwtUtils.getBooleanAnnotationValue(request, RooJavaType.ROO_GWT_REQUEST, "ignoreProxyExclusions", false);
Boolean ignoreProxyExclusions = GwtUtils.getBooleanAnnotationValue(request, ROO_GWT_REQUEST, "ignoreProxyExclusions", false);
if (!ignoreProxyExclusions) {
for (String exclusion : GwtUtils.getAnnotationValues(proxy, RooJavaType.ROO_GWT_PROXY, "exclude")) {
for (String exclusion : GwtUtils.getAnnotationValues(proxy, ROO_GWT_PROXY, "exclude")) {
exclusionList.add("set" + StringUtils.capitalize(exclusion));
exclusionList.add("get" + StringUtils.capitalize(exclusion));
}
exclusionList.addAll(GwtUtils.getAnnotationValues(proxy, RooJavaType.ROO_GWT_PROXY, "exclude"));
exclusionList.addAll(GwtUtils.getAnnotationValues(proxy, ROO_GWT_PROXY, "exclude"));
}
Boolean ignoreProxyReadOnly = GwtUtils.getBooleanAnnotationValue(request, RooJavaType.ROO_GWT_REQUEST, "ignoreProxyReadOnly", false);
Boolean ignoreProxyReadOnly = GwtUtils.getBooleanAnnotationValue(request, ROO_GWT_REQUEST, "ignoreProxyReadOnly", false);
if (!ignoreProxyReadOnly) {
for (String exclusion : GwtUtils.getAnnotationValues(proxy, RooJavaType.ROO_GWT_PROXY, "readOnly")) {
for (String exclusion : GwtUtils.getAnnotationValues(proxy, ROO_GWT_PROXY, "readOnly")) {
exclusionList.add("set" + StringUtils.capitalize(exclusion));
}
}
Boolean dontIncludeProxyMethods = GwtUtils.getBooleanAnnotationValue(proxy, RooJavaType.ROO_GWT_REQUEST, "ignoreProxyReadOnly", true);
Boolean dontIncludeProxyMethods = GwtUtils.getBooleanAnnotationValue(proxy, ROO_GWT_REQUEST, "ignoreProxyReadOnly", true);
if (dontIncludeProxyMethods) {
for (MethodMetadata methodMetadata : proxy.getDeclaredMethods()) {
exclusionList.add(methodMetadata.getMethodName().getSymbolName());
Expand Down Expand Up @@ -175,9 +177,9 @@ public String updateRequest(ClassOrInterfaceTypeDetails request, List<MethodMeta
AnnotationMetadataBuilder annotationMetadataBuilder = new AnnotationMetadataBuilder(annotationMetadata);
annotationMetadataBuilder.addStringAttribute("value", entity.getName().getFullyQualifiedTypeName());
annotationMetadataBuilder.removeAttribute("locator");
Set<ClassOrInterfaceTypeDetails> services = typeLocationService.findClassesOrInterfaceDetailsWithAnnotation(RooJavaType.ROO_SERVICE);
Set<ClassOrInterfaceTypeDetails> services = typeLocationService.findClassesOrInterfaceDetailsWithAnnotation(ROO_SERVICE);
for (ClassOrInterfaceTypeDetails serviceLayer : services) {
AnnotationMetadata serviceAnnotation = serviceLayer.getTypeAnnotation(RooJavaType.ROO_SERVICE);
AnnotationMetadata serviceAnnotation = serviceLayer.getTypeAnnotation(ROO_SERVICE);
AnnotationAttributeValue<List<ClassAttributeValue>> domainTypesAnnotation = serviceAnnotation.getAttribute("domainTypes");
for (ClassAttributeValue classAttributeValue : domainTypesAnnotation.getValue()) {
if (classAttributeValue.getValue().equals(entity.getName())) {
Expand Down Expand Up @@ -229,37 +231,36 @@ private MethodMetadataBuilder getRequestMethod(ClassOrInterfaceTypeDetails reque
return new MethodMetadataBuilder(request.getDeclaredByMetadataId(), Modifier.ABSTRACT, methodMetadata.getMethodName(), methodReturnType, paramaterTypes, methodMetadata.getParameterNames(), new InvocableMemberBodyBuilder());
}

public void notify(String upstreamDependency, String downstreamDependency) {
ProjectMetadata projectMetadata = projectOperations.getProjectMetadata();
public void notify(final String upstreamDependency, String downstreamDependency) {
final ProjectMetadata projectMetadata = projectOperations.getProjectMetadata();
if (projectMetadata == null) {
return;
}

if (MetadataIdentificationUtils.isIdentifyingClass(downstreamDependency)) {
Assert.isTrue(MetadataIdentificationUtils.getMetadataClass(upstreamDependency).equals(MetadataIdentificationUtils.getMetadataClass(PhysicalTypeIdentifier.getMetadataIdentiferType())), "Expected class-level notifications only for PhysicalTypeIdentifier (not '" + upstreamDependency + "')");

ClassOrInterfaceTypeDetails cid = typeLocationService.getTypeForIdentifier(upstreamDependency);
final ClassOrInterfaceTypeDetails cid = typeLocationService.getTypeForIdentifier(upstreamDependency);
if (cid == null) {
return;
}
boolean processed = false;
if (cid.getCustomData().get(CustomDataKeys.LAYER_TYPE) != null) {
@SuppressWarnings("unchecked")
List<JavaType> layerTypes = (List<JavaType>) cid.getCustomData().get(CustomDataKeys.LAYER_TYPE);
for (ClassOrInterfaceTypeDetails request : typeLocationService.findClassesOrInterfaceDetailsWithAnnotation(RooJavaType.ROO_GWT_REQUEST)) {
ClassOrInterfaceTypeDetails entity = gwtTypeService.lookupEntityFromRequest(request);
final List<JavaType> layerTypes = cid.getLayerEntities();
if (!layerTypes.isEmpty()) {
for (final ClassOrInterfaceTypeDetails request : typeLocationService.findClassesOrInterfaceDetailsWithAnnotation(ROO_GWT_REQUEST)) {
final ClassOrInterfaceTypeDetails entity = gwtTypeService.lookupEntityFromRequest(request);
if (entity != null && layerTypes.contains(entity.getName())) {
JavaType typeName = PhysicalTypeIdentifier.getJavaType(request.getDeclaredByMetadataId());
Path typePath = PhysicalTypeIdentifier.getPath(request.getDeclaredByMetadataId());
final JavaType typeName = PhysicalTypeIdentifier.getJavaType(request.getDeclaredByMetadataId());
final Path typePath = PhysicalTypeIdentifier.getPath(request.getDeclaredByMetadataId());
downstreamDependency = GwtRequestMetadata.createIdentifier(typeName, typePath);
processed = true;
break;
}
}
}
if (!processed && MemberFindingUtils.getAnnotationOfType(cid.getAnnotations(), RooJavaType.ROO_GWT_REQUEST) == null) {
if (!processed && MemberFindingUtils.getAnnotationOfType(cid.getAnnotations(), ROO_GWT_REQUEST) == null) {
boolean found = false;
for (ClassOrInterfaceTypeDetails classOrInterfaceTypeDetails : typeLocationService.findClassesOrInterfaceDetailsWithAnnotation(RooJavaType.ROO_GWT_REQUEST)) {
for (ClassOrInterfaceTypeDetails classOrInterfaceTypeDetails : typeLocationService.findClassesOrInterfaceDetailsWithAnnotation(ROO_GWT_REQUEST)) {
AnnotationMetadata annotationMetadata = GwtUtils.getFirstAnnotation(classOrInterfaceTypeDetails, GwtUtils.REQUEST_ANNOTATIONS);
if (annotationMetadata != null) {
AnnotationAttributeValue<?> attributeValue = annotationMetadata.getAttribute("value");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,12 @@ protected String getLocalMidToRequest(final ItdTypeDetails itdTypeDetails) {
return localMid;
}

MemberHoldingTypeDetails memberHoldingTypeDetails = typeLocationService.findClassOrInterface(itdTypeDetails.getGovernor().getName());
if (memberHoldingTypeDetails != null && memberHoldingTypeDetails.getCustomData().get(CustomDataKeys.LAYER_TYPE) != null) {
@SuppressWarnings("unchecked")
List<JavaType> domainTypes = (List<JavaType>) memberHoldingTypeDetails.getCustomData().get(CustomDataKeys.LAYER_TYPE);
if (domainTypes != null) {
for (JavaType type : domainTypes) {
String localMidType = entityToConverterMidMap.get(type);
if (localMidType != null) {
return localMidType;
}
final MemberHoldingTypeDetails memberHoldingTypeDetails = typeLocationService.findClassOrInterface(itdTypeDetails.getGovernor().getName());
if (memberHoldingTypeDetails != null) {
for (final JavaType type : memberHoldingTypeDetails.getLayerEntities()) {
String localMidType = entityToConverterMidMap.get(type);
if (localMidType != null) {
return localMidType;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,16 +97,12 @@ protected String getLocalMidToRequest(final ItdTypeDetails itdTypeDetails) {
return localMid;
}

MemberHoldingTypeDetails memberHoldingTypeDetails = typeLocationService.findClassOrInterface(itdTypeDetails.getGovernor().getName());
if (memberHoldingTypeDetails != null && memberHoldingTypeDetails.getCustomData().get(CustomDataKeys.LAYER_TYPE) != null) {
@SuppressWarnings("unchecked")
List<JavaType> domainTypes = (List<JavaType>) memberHoldingTypeDetails.getCustomData().get(CustomDataKeys.LAYER_TYPE);
if (domainTypes != null) {
for (JavaType type : domainTypes) {
String localMidType = entityToManagedBeanMidMap.get(type);
if (localMidType != null) {
return localMidType;
}
final MemberHoldingTypeDetails memberHoldingTypeDetails = typeLocationService.findClassOrInterface(itdTypeDetails.getGovernor().getName());
if (memberHoldingTypeDetails != null) {
for (final JavaType type : memberHoldingTypeDetails.getLayerEntities()) {
final String localMidType = entityToManagedBeanMidMap.get(type);
if (localMidType != null) {
return localMidType;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import org.apache.felix.scr.annotations.Component;
Expand All @@ -14,7 +13,6 @@
import org.springframework.roo.classpath.PhysicalTypeIdentifier;
import org.springframework.roo.classpath.PhysicalTypeMetadata;
import org.springframework.roo.classpath.TypeLocationService;
import org.springframework.roo.classpath.customdata.CustomDataKeys;
import org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails;
import org.springframework.roo.classpath.details.ItdTypeDetails;
import org.springframework.roo.classpath.details.MemberHoldingTypeDetails;
Expand Down Expand Up @@ -61,24 +59,20 @@ protected void deactivate(ComponentContext context) {
}

@Override
protected String getLocalMidToRequest(ItdTypeDetails itdTypeDetails) {
protected String getLocalMidToRequest(final ItdTypeDetails itdTypeDetails) {
// Determine the governor for this ITD, and whether any metadata is even hoping to hear about changes to that JavaType and its ITDs
JavaType governor = itdTypeDetails.getName();
String localMid = managedEntityTypes.get(governor);
final JavaType governor = itdTypeDetails.getName();
final String localMid = managedEntityTypes.get(governor);
if (localMid != null) {
return localMid;
}

MemberHoldingTypeDetails memberHoldingTypeDetails = typeLocationService.findClassOrInterface(governor);
if (memberHoldingTypeDetails != null && memberHoldingTypeDetails.getCustomData().get(CustomDataKeys.LAYER_TYPE) != null) {
@SuppressWarnings("unchecked")
List<JavaType> domainTypes = (List<JavaType>) memberHoldingTypeDetails.getCustomData().get(CustomDataKeys.LAYER_TYPE);
if (domainTypes != null) {
for (JavaType type : domainTypes) {
String localMidType = managedEntityTypes.get(type);
if (localMidType != null) {
return localMidType;
}
final MemberHoldingTypeDetails memberHoldingTypeDetails = typeLocationService.findClassOrInterface(governor);
if (memberHoldingTypeDetails != null) {
for (final JavaType type : memberHoldingTypeDetails.getLayerEntities()) {
final String localMidType = managedEntityTypes.get(type);
if (localMidType != null) {
return localMidType;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import static org.springframework.roo.model.RooJavaType.ROO_SERVICE;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.felix.scr.annotations.Component;
Expand Down Expand Up @@ -60,24 +59,20 @@ protected void deactivate(ComponentContext context) {
}

@Override
protected String getLocalMidToRequest(ItdTypeDetails itdTypeDetails) {
protected String getLocalMidToRequest(final ItdTypeDetails itdTypeDetails) {
// Determine the governor for this ITD, and whether any metadata is even hoping to hear about changes to that JavaType and its ITDs
JavaType governor = itdTypeDetails.getName();
String localMid = managedEntityTypes.get(governor);
final JavaType governor = itdTypeDetails.getName();
final String localMid = managedEntityTypes.get(governor);
if (localMid != null) {
return localMid;
}

MemberHoldingTypeDetails memberHoldingTypeDetails = typeLocationService.findClassOrInterface(governor);
if (memberHoldingTypeDetails != null && memberHoldingTypeDetails.getCustomData().get(CustomDataKeys.LAYER_TYPE) != null) {
@SuppressWarnings("unchecked")
List<JavaType> domainTypes = (List<JavaType>) memberHoldingTypeDetails.getCustomData().get(CustomDataKeys.LAYER_TYPE);
if (domainTypes != null) {
for (JavaType type : domainTypes) {
String localMidType = managedEntityTypes.get(type);
if (localMidType != null) {
return localMidType;
}
final MemberHoldingTypeDetails memberHoldingTypeDetails = typeLocationService.findClassOrInterface(governor);
if (memberHoldingTypeDetails != null) {
for (final JavaType type : memberHoldingTypeDetails.getLayerEntities()) {
final String localMidType = managedEntityTypes.get(type);
if (localMidType != null) {
return localMidType;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import static org.springframework.roo.classpath.customdata.CustomDataKeys.FIND_METHOD;
import static org.springframework.roo.classpath.customdata.CustomDataKeys.FLUSH_METHOD;
import static org.springframework.roo.classpath.customdata.CustomDataKeys.IDENTIFIER_ACCESSOR_METHOD;
import static org.springframework.roo.classpath.customdata.CustomDataKeys.LAYER_TYPE;
import static org.springframework.roo.classpath.customdata.CustomDataKeys.MERGE_METHOD;
import static org.springframework.roo.classpath.customdata.CustomDataKeys.PERSIST_METHOD;
import static org.springframework.roo.classpath.customdata.CustomDataKeys.REMOVE_METHOD;
Expand All @@ -17,7 +16,6 @@

import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

Expand Down Expand Up @@ -102,15 +100,11 @@ protected void notifyForGenericListener(final String upstreamDependency) {
// We do need to be informed if a new layer is available to see if we should use that
if (PhysicalTypeIdentifier.isValid(upstreamDependency)) {
final MemberHoldingTypeDetails memberHoldingTypeDetails = typeLocationService.findClassOrInterface(PhysicalTypeIdentifier.getJavaType(upstreamDependency));
if (memberHoldingTypeDetails != null && memberHoldingTypeDetails.getCustomData().get(LAYER_TYPE) != null) {
@SuppressWarnings("unchecked")
final List<JavaType> domainTypes = (List<JavaType>) memberHoldingTypeDetails.getCustomData().get(LAYER_TYPE);
if (domainTypes != null) {
for (final JavaType type : domainTypes) {
final String localMidType = managedEntityTypes.get(type);
if (localMidType != null) {
metadataService.get(localMidType);
}
if (memberHoldingTypeDetails != null) {
for (final JavaType type : memberHoldingTypeDetails.getLayerEntities()) {
final String localMidType = managedEntityTypes.get(type);
if (localMidType != null) {
metadataService.get(localMidType);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package org.springframework.roo.classpath.details;

import static org.springframework.roo.classpath.customdata.CustomDataKeys.LAYER_TYPE;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

import org.springframework.roo.classpath.details.annotations.AnnotatedJavaType;
Expand Down Expand Up @@ -42,12 +45,6 @@ public ConstructorMetadata getDeclaredConstructor(final List<JavaType> parameter
return null;
}

/**
* Locates the specified field.
*
* @param fieldName to locate (required)
* @return the field, or <code>null</code> if not found
*/
public FieldMetadata getDeclaredField(final JavaSymbolName fieldName) {
Assert.notNull(fieldName, "Field name required");
for (FieldMetadata field : getDeclaredFields()) {
Expand Down Expand Up @@ -175,4 +172,13 @@ public JavaSymbolName getUniqueFieldName(final String proposedName, final boolea
// We've derived a unique name
return new JavaSymbolName(candidateName);
}

@SuppressWarnings("unchecked")
public List<JavaType> getLayerEntities() {
final Object entities = getCustomData().get(LAYER_TYPE);
if (entities == null) {
return Collections.emptyList();
}
return (List<JavaType>) entities;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,16 @@ public interface MemberHoldingTypeDetails extends PhysicalTypeDetails, Identifia
*/
List<JavaType> getImplementsTypes();

/**
* If this is a layering component, for example a service or repository,
* returns the domain entities managed by this component, otherwise returns
* an empty list.
*
* @return a non-<code>null</code> list (may be empty)
* @since 1.2.0
*/
List<JavaType> getLayerEntities();

/**
* Searches up the inheritance hierarchy until the first method with the
* specified name is located; method parameters are not taken into account.
Expand Down

0 comments on commit 91b7a2e

Please sign in to comment.