Search in sources :

Example 1 with ItdMetadataProvider

use of org.springframework.roo.classpath.itd.ItdMetadataProvider in project spring-roo by spring-projects.

the class DefaultPhysicalTypeMetadataTest method testGetItdCanonicalPath.

@Test
public void testGetItdCanonicalPath() {
    // Set up
    final ItdMetadataProvider mockItdMetadataProvider = mock(ItdMetadataProvider.class);
    when(mockItdMetadataProvider.getItdUniquenessFilenameSuffix()).thenReturn("MySuffix");
    // Invoke
    final String itdCanonicalPath = metadata.getItdCanonicalPath(mockItdMetadataProvider);
    // Check
    assertEquals("/usr/bob/projects/foo/Foo_Roo_MySuffix.aj", itdCanonicalPath);
}
Also used : ItdMetadataProvider(org.springframework.roo.classpath.itd.ItdMetadataProvider) Test(org.junit.Test)

Example 2 with ItdMetadataProvider

use of org.springframework.roo.classpath.itd.ItdMetadataProvider in project spring-roo by spring-projects.

the class MemberDetailsScannerImpl method getMemberDetails.

public final MemberDetails getMemberDetails(final String requestingClass, ClassOrInterfaceTypeDetails cid) {
    if (metadataService == null) {
        metadataService = getMetadataService();
    }
    if (providers.isEmpty()) {
        bindProviders();
    }
    if (decorators.isEmpty()) {
        bindDecorators();
    }
    if (cid == null) {
        return null;
    }
    synchronized (lock) {
        // Create a list of discovered members
        final List<MemberHoldingTypeDetails> memberHoldingTypeDetails = new ArrayList<MemberHoldingTypeDetails>();
        // Build a List representing the class hierarchy, where the first
        // element is the absolute superclass
        final List<ClassOrInterfaceTypeDetails> cidHierarchy = new ArrayList<ClassOrInterfaceTypeDetails>();
        while (cid != null) {
            // Note to the top of the list
            cidHierarchy.add(0, cid);
            cid = cid.getSuperclass();
        }
        // Now we add this governor, plus all of its superclasses
        for (final ClassOrInterfaceTypeDetails currentClass : cidHierarchy) {
            memberHoldingTypeDetails.add(currentClass);
            // thus MemberHoldingTypeDetails information
            for (final MetadataProvider mp : providers) {
                // Skip non-ITD providers
                if (!(mp instanceof ItdMetadataProvider)) {
                    continue;
                }
                // Skip myself
                if (mp.getClass().getName().equals(requestingClass)) {
                    continue;
                }
                // Determine the key the ITD provider uses for this
                // particular type
                final String key = ((ItdMetadataProvider) mp).getIdForPhysicalJavaType(currentClass.getDeclaredByMetadataId());
                Validate.isTrue(MetadataIdentificationUtils.isIdentifyingInstance(key), "ITD metadata provider '%s' returned an illegal key ('%s')", mp, key);
                // Get the metadata and ensure we have ITD type details
                // available
                final MetadataItem metadataItem = metadataService.get(key);
                if (metadataItem == null || !metadataItem.isValid()) {
                    continue;
                }
                Validate.isInstanceOf(ItdTypeDetailsProvidingMetadataItem.class, metadataItem, "ITD metadata provider '%s' failed to return the correct metadata type", mp);
                final ItdTypeDetailsProvidingMetadataItem itdTypeDetailsMd = (ItdTypeDetailsProvidingMetadataItem) metadataItem;
                if (itdTypeDetailsMd.getMemberHoldingTypeDetails() == null) {
                    continue;
                }
                // Capture the member details
                memberHoldingTypeDetails.add(itdTypeDetailsMd.getMemberHoldingTypeDetails());
            }
        }
        // Turn out list of discovered members into a result
        MemberDetails result = new MemberDetailsImpl(memberHoldingTypeDetails);
        // Loop until such time as we complete a full loop where no changes
        // are made to the result
        boolean additionalLoopRequired = true;
        while (additionalLoopRequired) {
            additionalLoopRequired = false;
            for (final MemberDetailsDecorator decorator : decorators) {
                final MemberDetails newResult = decorator.decorate(requestingClass, result);
                Validate.isTrue(newResult != null, "Decorator '%s' returned an illegal result", decorator.getClass().getName());
                if (newResult != null && !newResult.equals(result)) {
                    additionalLoopRequired = true;
                }
                result = newResult;
            }
        }
        return result;
    }
}
Also used : ItdTypeDetailsProvidingMetadataItem(org.springframework.roo.classpath.itd.ItdTypeDetailsProvidingMetadataItem) ArrayList(java.util.ArrayList) ItdMetadataProvider(org.springframework.roo.classpath.itd.ItdMetadataProvider) MetadataProvider(org.springframework.roo.metadata.MetadataProvider) MemberHoldingTypeDetails(org.springframework.roo.classpath.details.MemberHoldingTypeDetails) ItdMetadataProvider(org.springframework.roo.classpath.itd.ItdMetadataProvider) ClassOrInterfaceTypeDetails(org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails) MetadataItem(org.springframework.roo.metadata.MetadataItem) ItdTypeDetailsProvidingMetadataItem(org.springframework.roo.classpath.itd.ItdTypeDetailsProvidingMetadataItem)

Example 3 with ItdMetadataProvider

use of org.springframework.roo.classpath.itd.ItdMetadataProvider in project spring-roo by spring-projects.

the class DefaultPhysicalTypeMetadataTest method testGetItdCanoncialPath.

@Test
public void testGetItdCanoncialPath() {
    // Set up
    final ItdMetadataProvider mockItdMetadataProvider = mock(ItdMetadataProvider.class);
    when(mockItdMetadataProvider.getItdUniquenessFilenameSuffix()).thenReturn("MySuffix");
    // Invoke
    final String itdCanonicalPath = metadata.getItdCanoncialPath(mockItdMetadataProvider);
    // Check
    assertEquals("/usr/bob/projects/foo/Foo_Roo_MySuffix.aj", itdCanonicalPath);
}
Also used : ItdMetadataProvider(org.springframework.roo.classpath.itd.ItdMetadataProvider) Test(org.junit.Test)

Aggregations

ItdMetadataProvider (org.springframework.roo.classpath.itd.ItdMetadataProvider)3 Test (org.junit.Test)2 ArrayList (java.util.ArrayList)1 ClassOrInterfaceTypeDetails (org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails)1 MemberHoldingTypeDetails (org.springframework.roo.classpath.details.MemberHoldingTypeDetails)1 ItdTypeDetailsProvidingMetadataItem (org.springframework.roo.classpath.itd.ItdTypeDetailsProvidingMetadataItem)1 MetadataItem (org.springframework.roo.metadata.MetadataItem)1 MetadataProvider (org.springframework.roo.metadata.MetadataProvider)1