Package org.springframework.roo.model

Examples of org.springframework.roo.model.JavaType


    private void installBean(final String templateName,
            final JavaPackage destinationPackage) {
        final String beanName = templateName.substring(0,
                templateName.indexOf("-template"));
        final JavaType javaType = new JavaType(
                destinationPackage.getFullyQualifiedPackageName() + "."
                        + beanName);
        final String physicalTypeIdentifier = PhysicalTypeIdentifier
                .createIdentifier(javaType,
                        pathResolver.getFocusedPath(Path.SRC_MAIN_JAVA));
        final String physicalPath = typeLocationService
                .getPhysicalTypeCanonicalPath(physicalTypeIdentifier);
        if (fileManager.exists(physicalPath)) {
            return;
        }

        InputStream inputStream = null;
        try {
            inputStream = FileUtils.getInputStream(getClass(), templateName);
            String input = IOUtils.toString(inputStream);
            input = input.replace("__PACKAGE__",
                    destinationPackage.getFullyQualifiedPackageName());
            fileManager.createOrUpdateTextFileIfRequired(physicalPath, input,
                    false);

            shell.flash(Level.FINE,
                    "Created " + javaType.getFullyQualifiedTypeName(),
                    JsfOperationsImpl.class.getName());
            shell.flash(Level.FINE, "", JsfOperationsImpl.class.getName());
        }
        catch (final IOException e) {
            throw new IllegalStateException("Unable to create '" + physicalPath
View Full Code Here


            final JavaType aspectName,
            final PhysicalTypeMetadata governorPhysicalType,
            final String itdFilename) {
        final MongoEntityAnnotationValues annotationValues = new MongoEntityAnnotationValues(
                governorPhysicalType);
        final JavaType identifierType = annotationValues.getIdentifierType();
        if (!annotationValues.isAnnotationFound() || identifierType == null) {
            return null;
        }

        // Get the governor's member details
View Full Code Here

        if (!fileManager.exists(canonicalPath)) {
            // Couldn't find the file, so return null to distinguish from a file
            // 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) {
View Full Code Here

        typeManagementService.createOrUpdateTypeOnDisk(cidBuilder.build());

        if (testAutomatically) {
            integrationTestOperations.newIntegrationTest(classType, false);
            dataOnDemandOperations.newDod(classType,
                    new JavaType(classType.getFullyQualifiedTypeName()
                            + "DataOnDemand"));
        }
    }
View Full Code Here

                interfaceType, pathResolver.getPath(interfaceIdentifier));
        final ClassOrInterfaceTypeDetailsBuilder cidBuilder = new ClassOrInterfaceTypeDetailsBuilder(
                interfaceMdId, Modifier.PUBLIC, interfaceType,
                PhysicalTypeCategory.INTERFACE);
        cidBuilder.addAnnotation(interfaceAnnotationMetadata.build());
        final JavaType listType = new JavaType(List.class.getName(), 0,
                DataType.TYPE, null, Arrays.asList(domainType));
        cidBuilder.addMethod(new MethodMetadataBuilder(interfaceMdId, 0,
                new JavaSymbolName("findAll"), listType,
                new InvocableMemberBodyBuilder()));
        typeManagementService.createOrUpdateTypeOnDisk(cidBuilder.build());
View Full Code Here

                    .getAttribute(new JavaSymbolName("value"));
            if (value != null) {
                index = new Short(value.getValue().toString());
            }
        }
        final JavaType fieldType = field.getFieldType();
        if (field.getFieldName().getSymbolName().contains("email")
                || field.getFieldName().getSymbolName().contains("Email")) {
            initializer = "some@email.com";
        }
        else if (fieldType.equals(JavaType.STRING)) {
            initializer = "some"
                    + field.getFieldName()
                            .getSymbolNameCapitalisedFirstLetter() + index;
        }
        else if (fieldType.equals(new JavaType(Date.class.getName()))
                || fieldType.equals(new JavaType(Calendar.class.getName()))) {
            final Calendar cal = Calendar.getInstance();
            AnnotationMetadata dateTimeFormat = null;
            String style = null;
            if ((dateTimeFormat = MemberFindingUtils.getAnnotationOfType(
                    field.getAnnotations(), DATE_TIME_FORMAT)) != null) {
                final AnnotationAttributeValue<?> value = dateTimeFormat
                        .getAttribute(new JavaSymbolName("style"));
                if (value != null) {
                    style = value.getValue().toString();
                }
            }
            if (MemberFindingUtils.getAnnotationOfType(field.getAnnotations(),
                    PAST) != null) {
                cal.add(Calendar.YEAR, -1);
                cal.add(Calendar.MONTH, -1);
                cal.add(Calendar.DAY_OF_MONTH, -1);
            }
            else if (MemberFindingUtils.getAnnotationOfType(
                    field.getAnnotations(), FUTURE) != null) {
                cal.add(Calendar.YEAR, 1);
                cal.add(Calendar.MONTH, 1);
                cal.add(Calendar.DAY_OF_MONTH, 1);
            }
            if (style != null) {
                if (style.startsWith("-")) {
                    initializer = ((SimpleDateFormat) DateFormat
                            .getTimeInstance(
                                    DateTime.parseDateFormat(style.charAt(1)),
                                    Locale.getDefault())).format(cal.getTime());
                }
                else if (style.endsWith("-")) {
                    initializer = ((SimpleDateFormat) DateFormat
                            .getDateInstance(
                                    DateTime.parseDateFormat(style.charAt(0)),
                                    Locale.getDefault())).format(cal.getTime());
                }
                else {
                    initializer = ((SimpleDateFormat) DateFormat
                            .getDateTimeInstance(
                                    DateTime.parseDateFormat(style.charAt(0)),
                                    DateTime.parseDateFormat(style.charAt(1)),
                                    Locale.getDefault())).format(cal.getTime());
                }
            }
            else {
                initializer = ((SimpleDateFormat) DateFormat.getDateInstance(
                        DateFormat.SHORT, Locale.getDefault())).format(cal
                        .getTime());
            }

        }
        else if (fieldType.equals(JavaType.BOOLEAN_OBJECT)
                || fieldType.equals(JavaType.BOOLEAN_PRIMITIVE)) {
            initializer = Boolean.valueOf(false).toString();
        }
        else if (fieldType.equals(JavaType.INT_OBJECT)
                || fieldType.equals(JavaType.INT_PRIMITIVE)) {
            initializer = Integer.valueOf(index).toString();
        }
        else if (fieldType.equals(JavaType.DOUBLE_OBJECT)
                || fieldType.equals(JavaType.DOUBLE_PRIMITIVE)) {
            initializer = Double.toString(index);
        }
        else if (fieldType.equals(JavaType.FLOAT_OBJECT)
                || fieldType.equals(JavaType.FLOAT_PRIMITIVE)) {
            initializer = Float.toString(index);
        }
        else if (fieldType.equals(LONG_OBJECT)
                || fieldType.equals(JavaType.LONG_PRIMITIVE)) {
            initializer = Long.valueOf(index).toString();
        }
        else if (fieldType.equals(JavaType.SHORT_OBJECT)
                || fieldType.equals(JavaType.SHORT_PRIMITIVE)) {
            initializer = Short.valueOf(index).toString();
        }
        else if (fieldType.equals(BIG_DECIMAL)) {
            initializer = new BigDecimal(index).toString();
        }
        return initializer;
    }
View Full Code Here

        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);
        final MemberDetails memberDetails = memberDetailsScanner
                .getMemberDetails(getClass().getName(), formBackingTypeDetails);

        // Add composite PK identifier fields if needed
        for (final FieldMetadata field : persistenceMemberLocator
                .getEmbeddedIdentifierFields(formBackingType)) {
            final JavaType fieldType = field.getFieldType();
            if (!fieldType.isCommonCollectionType()
                    && !isSpecialType(fieldType)) {
                final FieldMetadataBuilder fieldBuilder = new FieldMetadataBuilder(
                        field);
                final String fieldName = field.getFieldName().getSymbolName();
                fieldBuilder.setFieldName(new JavaSymbolName(fieldName + "."
                        + fieldName));
                tbody.appendChild(typeCommand(document, fieldBuilder.build()));
            }
        }

        // Add all other fields
        final List<FieldMetadata> fields = webMetadataService
                .getScaffoldEligibleFieldMetadata(formBackingType,
                        memberDetails, null);
        for (final FieldMetadata field : fields) {
            final JavaType fieldType = field.getFieldType();
            if (!fieldType.isCommonCollectionType()
                    && !isSpecialType(fieldType)) {
                tbody.appendChild(typeCommand(document, field));
            }
        }

        tbody.appendChild(clickAndWaitCommand(document,
                "//input[@id = 'proceed']"));

        // Add verifications for all other fields
        for (final FieldMetadata field : fields) {
            final JavaType fieldType = field.getFieldType();
            if (!fieldType.isCommonCollectionType()
                    && !isSpecialType(fieldType)) {
                tbody.appendChild(verifyTextCommand(document, formBackingType,
                        field));
            }
        }
View Full Code Here

                // This qualified name expression is simply an inner type
                // reference
                final String name = compilationUnitServices
                        .getEnclosingTypeName().getFullyQualifiedTypeName()
                        + "." + nameToFind.getName();
                return new JavaType(name,
                        compilationUnitServices.getEnclosingTypeName());
            }

            // Refers to a different enclosing type, so calculate the package
            // name based on convention of an uppercase letter denotes same
            // package (ROO-1210)
            if (qne.toString().length() > 1
                    && Character.isUpperCase(qne.toString().charAt(0))) {
                // First letter is uppercase, so this likely requires prepending
                // of some package name
                final ImportDeclaration importDeclaration = getImportDeclarationFor(
                        compilationUnitServices, qne.getQualifier());
                if (importDeclaration == null) {
                    if (!compilationUnitPackage.getFullyQualifiedPackageName()
                            .equals("")) {
                        // It was not imported, so let's assume it's in the same
                        // package
                        return new JavaType(compilationUnitServices
                                .getCompilationUnitPackage()
                                .getFullyQualifiedPackageName()
                                + "." + qne.toString());
                    }
                }
                else {
                    return new JavaType(importDeclaration.getName() + "."
                            + qne.getName());
                }

                // This name expression (which contains a dot) had its qualifier
                // imported, so let's use the import
            }
            else {
                // First letter is lowercase, so the reference already includes
                // a package
                return new JavaType(qne.toString());
            }
        }

        if ("?".equals(nameToFind.getName())) {
            return new JavaType(OBJECT.getFullyQualifiedTypeName(), 0,
                    DataType.TYPE, JavaType.WILDCARD_NEITHER, null);
        }

        // Unqualified name detected, so check if it's in the type parameter
        // list
        if (typeParameters != null
                && typeParameters.contains(new JavaSymbolName(nameToFind
                        .getName()))) {
            return new JavaType(nameToFind.getName(), 0, DataType.VARIABLE,
                    null, null);
        }

        // Check if we are looking for the enclosingType itself
        final NameExpr enclosingTypeName = getNameExpr(compilationUnitServices
                .getEnclosingTypeName().getSimpleTypeName());
        if (isEqual(enclosingTypeName, nameToFind)) {
            return compilationUnitServices.getEnclosingTypeName();
        }

        // We are searching for a non-qualified name expression (nameToFind), so
        // check if the compilation unit itself declares that type
        for (final TypeDeclaration internalType : compilationUnitServices
                .getInnerTypes()) {
            final NameExpr nameExpr = getNameExpr(internalType.getName());
            if (isEqual(nameExpr, nameToFind)) {
                // Found, so now we need to convert the internalType to a proper
                // JavaType
                final String name = compilationUnitServices
                        .getEnclosingTypeName().getFullyQualifiedTypeName()
                        + "." + nameToFind.getName();
                return new JavaType(name);
            }
        }

        final ImportDeclaration importDeclaration = getImportDeclarationFor(
                compilationUnitServices, nameToFind);
        if (importDeclaration == null) {
            if (JdkJavaType.isPartOfJavaLang(nameToFind.getName())) {
                return new JavaType("java.lang." + nameToFind.getName());
            }
            final String name = compilationUnitPackage
                    .getFullyQualifiedPackageName().equals("") ? nameToFind
                    .getName() : compilationUnitPackage
                    .getFullyQualifiedPackageName()
                    + "."
                    + nameToFind.getName();
            return new JavaType(name);
        }

        return new JavaType(importDeclaration.getName().toString());
    }
View Full Code Here

        }

        if (internalType instanceof PrimitiveType) {
            final PrimitiveType pt = (PrimitiveType) internalType;
            if (pt.getType().equals(Primitive.Boolean)) {
                return new JavaType(Boolean.class.getName(), array,
                        DataType.PRIMITIVE, null, null);
            }
            if (pt.getType().equals(Primitive.Char)) {
                return new JavaType(Character.class.getName(), array,
                        DataType.PRIMITIVE, null, null);
            }
            if (pt.getType().equals(Primitive.Byte)) {
                return new JavaType(Byte.class.getName(), array,
                        DataType.PRIMITIVE, null, null);
            }
            if (pt.getType().equals(Primitive.Short)) {
                return new JavaType(Short.class.getName(), array,
                        DataType.PRIMITIVE, null, null);
            }
            if (pt.getType().equals(Primitive.Int)) {
                return new JavaType(Integer.class.getName(), array,
                        DataType.PRIMITIVE, null, null);
            }
            if (pt.getType().equals(Primitive.Long)) {
                return new JavaType(Long.class.getName(), array,
                        DataType.PRIMITIVE, null, null);
            }
            if (pt.getType().equals(Primitive.Float)) {
                return new JavaType(Float.class.getName(), array,
                        DataType.PRIMITIVE, null, null);
            }
            if (pt.getType().equals(Primitive.Double)) {
                return new JavaType(Double.class.getName(), array,
                        DataType.PRIMITIVE, null, null);
            }
            throw new IllegalStateException("Unsupported primitive '"
                    + pt.getType() + "'");
        }

        if (internalType instanceof WildcardType) {
            // We only provide very primitive support for wildcard types; Roo
            // only needs metadata at the end of the day,
            // not complete binding support from an AST
            final WildcardType wt = (WildcardType) internalType;
            if (wt.getSuper() != null) {
                final ReferenceType rt = wt.getSuper();
                final ClassOrInterfaceType cit = (ClassOrInterfaceType) rt
                        .getType();
                final JavaType effectiveType = getJavaTypeNow(
                        compilationUnitServices, cit, typeParameters);
                return new JavaType(effectiveType.getFullyQualifiedTypeName(),
                        rt.getArrayCount(), effectiveType.getDataType(),
                        JavaType.WILDCARD_SUPER, effectiveType.getParameters());
            }
            else if (wt.getExtends() != null) {
                final ReferenceType rt = wt.getExtends();
                final ClassOrInterfaceType cit = (ClassOrInterfaceType) rt
                        .getType();
                final JavaType effectiveType = getJavaTypeNow(
                        compilationUnitServices, cit, typeParameters);
                return new JavaType(effectiveType.getFullyQualifiedTypeName(),
                        rt.getArrayCount(), effectiveType.getDataType(),
                        JavaType.WILDCARD_EXTENDS,
                        effectiveType.getParameters());
            }
            else {
                return new JavaType(OBJECT.getFullyQualifiedTypeName(), 0,
                        DataType.TYPE, JavaType.WILDCARD_NEITHER, null);
            }
        }

        ClassOrInterfaceType cit;
        if (internalType instanceof ClassOrInterfaceType) {
            cit = (ClassOrInterfaceType) internalType;
        }
        else if (internalType instanceof ReferenceType) {
            cit = (ClassOrInterfaceType) ((ReferenceType) type).getType();
        }
        else {
            throw new IllegalStateException("The presented type '"
                    + internalType.getClass() + "' with value '" + internalType
                    + "' is unsupported by JavaParserUtils");
        }

        final JavaType effectiveType = getJavaTypeNow(compilationUnitServices,
                cit, typeParameters);
        if (array > 0) {
            return new JavaType(effectiveType.getFullyQualifiedTypeName(),
                    array, effectiveType.getDataType(),
                    effectiveType.getArgName(), effectiveType.getParameters());
        }

        return effectiveType;
    }
View Full Code Here

     * Constructor
     *
     * @param type the fully-qualified type name (required)
     */
    public MongoIdType(final String type) {
        javaType = new JavaType(type);
    }
View Full Code Here

TOP

Related Classes of org.springframework.roo.model.JavaType

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.