Package org.springframework.roo.classpath.details

Examples of org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails


        // We need to abort if we couldn't find dependent metadata
        if (physicalTypeMetadata == null || !physicalTypeMetadata.isValid()) {
            return null;
        }

        final ClassOrInterfaceTypeDetails cid = physicalTypeMetadata
                .getMemberHoldingTypeDetails();
        if (cid == null) {
            // Abort if the type's class details aren't available (parse error
            // etc)
            return null;
View Full Code Here


     */
    @SuppressWarnings("unchecked")
    protected <T extends MetadataItem> T getParentMetadata(
            final ClassOrInterfaceTypeDetails child) {
        T parentMetadata = null;
        ClassOrInterfaceTypeDetails superCid = child.getSuperclass();
        while (parentMetadata == null && superCid != null) {
            final String superCidPhysicalTypeIdentifier = superCid
                    .getDeclaredByMetadataId();
            final LogicalPath path = PhysicalTypeIdentifier
                    .getPath(superCidPhysicalTypeIdentifier);
            final String superCidLocalIdentifier = createLocalIdentifier(
                    superCid.getName(), path);
            parentMetadata = (T) metadataService.get(superCidLocalIdentifier);
            superCid = superCid.getSuperclass();
        }
        return parentMetadata; // Could be null
    }
View Full Code Here

                    final JavaType innerType = new JavaType(
                            castMember.getName(), name);
                    final String innerTypeMetadataId = PhysicalTypeIdentifier
                            .createIdentifier(innerType, PhysicalTypeIdentifier
                                    .getPath(declaredByMetadataId));
                    final ClassOrInterfaceTypeDetails cid = new JavaParserClassOrInterfaceTypeDetailsBuilder(
                            compilationUnit, compilationUnitServices,
                            castMember, innerTypeMetadataId, innerType,
                            metadataService, typeLocationService).build();
                    cidBuilder.addInnerType(cid);
                }
View Full Code Here

    public void annotateType(final JavaType javaType, final String rootName,
            final boolean deepSerialize, final boolean iso8601Dates) {
        Validate.notNull(javaType, "Java type required");

        final ClassOrInterfaceTypeDetails cid = typeLocationService
                .getTypeDetails(javaType);
        if (cid == null) {
            throw new IllegalArgumentException("Cannot locate source for '"
                    + javaType.getFullyQualifiedTypeName() + "'");
        }

        if (MemberFindingUtils.getAnnotationOfType(cid.getAnnotations(),
                RooJavaType.ROO_JSON) == null) {
            final AnnotationMetadataBuilder annotationBuilder = new AnnotationMetadataBuilder(
                    RooJavaType.ROO_JSON);
            if (rootName != null && rootName.length() > 0) {
                annotationBuilder.addStringAttribute("rootName", rootName);
View Full Code Here

     * Sets up the mock {@link RepositoryMongoLocator} and
     * {@link PersistenceMemberLocator} to return a mock repository for our test
     * entity.
     */
    private void setUpMockRepository() {
        final ClassOrInterfaceTypeDetails mockRepositoryDetails = mock(ClassOrInterfaceTypeDetails.class);
        final FieldMetadata mockFieldMetadata = mock(FieldMetadata.class);
        final JavaType mockRepositoryType = mock(JavaType.class);
        when(mockRepositoryType.getSimpleTypeName()).thenReturn("ClinicRepo");
        when(mockIdType.getFullyQualifiedTypeName()).thenReturn(
                Long.class.getName());
        when(mockRepositoryDetails.getName()).thenReturn(mockRepositoryType);
        when(mockFieldMetadata.getFieldType()).thenReturn(mockIdType);
        when(mockRepositoryLocator.getRepositories(mockTargetEntity))
                .thenReturn(Arrays.asList(mockRepositoryDetails));
    }
View Full Code Here

        final ClassOrInterfaceTypeDetailsBuilder cidBuilder = new ClassOrInterfaceTypeDetailsBuilder(
                declaredByMetadataId, modifier, name,
                PhysicalTypeCategory.CLASS);

        if (!superclass.equals(OBJECT)) {
            final ClassOrInterfaceTypeDetails superclassClassOrInterfaceTypeDetails = typeLocationService
                    .getTypeDetails(superclass);
            if (superclassClassOrInterfaceTypeDetails != null) {
                cidBuilder
                        .setSuperclass(new ClassOrInterfaceTypeDetailsBuilder(
                                superclassClassOrInterfaceTypeDetails));
            }
        }

        cidBuilder.setExtendsTypes(Arrays.asList(superclass));

        if (implementsType != null) {
            final Set<JavaType> implementsTypes = new LinkedHashSet<JavaType>();
            final ClassOrInterfaceTypeDetails typeDetails = typeLocationService
                    .getTypeDetails(declaredByMetadataId);
            if (typeDetails != null) {
                implementsTypes.addAll(typeDetails.getImplementsTypes());
            }
            implementsTypes.add(implementsType);
            cidBuilder.setImplementsTypes(implementsTypes);
        }
View Full Code Here

                        pathResolver.getFocusedPath(Path.SRC_MAIN_JAVA)))) {
            // Type exists already - nothing to do
            return;
        }

        final ClassOrInterfaceTypeDetails entityTypeDetails = typeLocationService
                .getTypeDetails(entity);
        Validate.notNull(entityTypeDetails,
                "The type '%s' could not be resolved", entity);

        final PluralMetadata pluralMetadata = (PluralMetadata) metadataService
                .get(PluralMetadata.createIdentifier(entity,
                        PhysicalTypeIdentifier.getPath(entityTypeDetails
                                .getDeclaredByMetadataId())));
        Validate.notNull(pluralMetadata,
                "The plural for type '%s' could not be resolved", entity);

        // Create type annotation for new managed bean
View Full Code Here

            // that was found but could not be parsed
            return null;
        }
        final JavaType javaType = PhysicalTypeIdentifier
                .getJavaType(metadataIdentificationString);
        final ClassOrInterfaceTypeDetails typeDetails = typeParsingService
                .getTypeAtLocation(canonicalPath, metadataIdentificationString,
                        javaType);
        if (typeDetails == null) {
            return null;
        }
        final PhysicalTypeMetadata result = new DefaultPhysicalTypeMetadata(
                metadataIdentificationString, canonicalPath, typeDetails);
        final ClassOrInterfaceTypeDetails details = result
                .getMemberHoldingTypeDetails();
        if (details != null
                && details.getPhysicalTypeCategory() == PhysicalTypeCategory.CLASS
                && details.getExtendsTypes().size() == 1) {
            // This is a class, and it extends another class
            if (details.getSuperclass() != null) {
                // We have a dependency on the superclass, and there is metadata
                // available for the superclass
                // We won't implement the full MetadataNotificationListener
                // here, but rely on MetadataService's fallback
                // (which is to evict from cache and call get again given
                // JavaParserMetadataProvider doesn't implement
                // MetadataNotificationListener, then notify everyone we've
                // changed)
                final String superclassId = details.getSuperclass()
                        .getDeclaredByMetadataId();
                metadataDependencyRegistry.registerDependency(superclassId,
                        result.getId());
            }
            else {
                // We have a dependency on the superclass, but no metadata is
                // available
                // We're left with no choice but to register for every physical
                // type change, in the hope we discover our parent someday
                for (final LogicalPath sourcePath : projectOperations
                        .getPathResolver().getSourcePaths()) {
                    final String possibleSuperclass = PhysicalTypeIdentifier
                            .createIdentifier(details.getExtendsTypes().get(0),
                                    sourcePath);
                    metadataDependencyRegistry.registerDependency(
                            possibleSuperclass, result.getId());
                }
            }
View Full Code Here

     */
    public void generateTest(final JavaType controller, String name,
            String serverURL) {
        Validate.notNull(controller, "Controller type required");

        final ClassOrInterfaceTypeDetails controllerTypeDetails = typeLocationService
                .getTypeDetails(controller);
        Validate.notNull(
                controllerTypeDetails,
                "Class or interface type details for type '%s' could not be resolved",
                controller);

        final LogicalPath path = PhysicalTypeIdentifier
                .getPath(controllerTypeDetails.getDeclaredByMetadataId());
        final String webScaffoldMetadataIdentifier = WebScaffoldMetadata
                .createIdentifier(controller, path);
        final WebScaffoldMetadata webScaffoldMetadata = (WebScaffoldMetadata) metadataService
                .get(webScaffoldMetadataIdentifier);
        Validate.notNull(
                webScaffoldMetadata,
                "Web controller '%s' does not appear to be an automatic, scaffolded controller",
                controller.getFullyQualifiedTypeName());

        // We abort the creation of a selenium test if the controller does not
        // allow the creation of new instances for the form backing object
        if (!webScaffoldMetadata.getAnnotationValues().isCreate()) {
            LOGGER.warning("The controller you specified does not allow the creation of new instances of the form backing object. No Selenium tests created.");
            return;
        }

        if (!serverURL.endsWith("/")) {
            serverURL = serverURL + "/";
        }

        final JavaType formBackingType = webScaffoldMetadata
                .getAnnotationValues().getFormBackingObject();
        final String relativeTestFilePath = "selenium/test-"
                + formBackingType.getSimpleTypeName().toLowerCase() + ".xhtml";
        final String seleniumPath = pathResolver.getFocusedIdentifier(
                Path.SRC_MAIN_WEBAPP, relativeTestFilePath);

        final InputStream templateInputStream = FileUtils.getInputStream(
                getClass(), "selenium-template.xhtml");
        Validate.notNull(templateInputStream,
                "Could not acquire selenium.xhtml template");
        final Document document = XmlUtils.readXml(templateInputStream);

        final Element root = (Element) document.getLastChild();
        if (root == null || !"html".equals(root.getNodeName())) {
            throw new IllegalArgumentException(
                    "Could not parse selenium test case template file!");
        }

        name = name != null ? name : "Selenium test for "
                + controller.getSimpleTypeName();
        XmlUtils.findRequiredElement("/html/head/title", root).setTextContent(
                name);

        XmlUtils.findRequiredElement("/html/body/table/thead/tr/td", root)
                .setTextContent(name);

        final Element tbody = XmlUtils.findRequiredElement(
                "/html/body/table/tbody", root);
        tbody.appendChild(openCommand(
                document,
                serverURL
                        + projectOperations.getProjectName(projectOperations
                                .getFocusedModuleName()) + "/"
                        + webScaffoldMetadata.getAnnotationValues().getPath()
                        + "?form"));

        final ClassOrInterfaceTypeDetails formBackingTypeDetails = typeLocationService
                .getTypeDetails(formBackingType);
        Validate.notNull(
                formBackingType,
                "Class or interface type details for type '%s' could not be resolved",
                formBackingType);
View Full Code Here

        if (CollectionUtils.isEmpty(repositories)) {
            return null;
        }

        // Use the first such repository (could refine this later)
        final ClassOrInterfaceTypeDetails repository = repositories.iterator()
                .next();

        // Return the additions the caller needs to make
        return getMethodAdditions(callerMID, method, repository.getName(),
                Arrays.asList(callerParameters));
    }
View Full Code Here

TOP

Related Classes of org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.