Package org.springframework.roo.model

Examples of org.springframework.roo.model.JavaPackage


        final StringBuilder sb = new StringBuilder(compilationUnit.getPackage()
                .getName().toString());
        if (name.getEnclosingType() != null) {
            sb.append(".").append(name.getEnclosingType().getSimpleTypeName());
        }
        compilationUnitPackage = new JavaPackage(sb.toString());

        // Determine the type name, adding type parameters if possible
        final JavaType newName = JavaParserUtils.getJavaType(
                compilationUnitServices, typeDeclaration);

        // Revert back to the original type name (thus avoiding unnecessary
        // inferences about java.lang types; see ROO-244)
        name = new JavaType(newName.getFullyQualifiedTypeName(),
                newName.getEnclosingType(), newName.getArray(),
                newName.getDataType(), newName.getArgName(),
                newName.getParameters());

        final ClassOrInterfaceTypeDetailsBuilder cidBuilder = new ClassOrInterfaceTypeDetailsBuilder(
                declaredByMetadataId);

        physicalTypeCategory = PhysicalTypeCategory.CLASS;
        if (typeDeclaration instanceof ClassOrInterfaceDeclaration) {
            clazz = (ClassOrInterfaceDeclaration) typeDeclaration;
            if (clazz.isInterface()) {
                physicalTypeCategory = PhysicalTypeCategory.INTERFACE;
            }

        }
        else if (typeDeclaration instanceof EnumDeclaration) {
            enumClazz = (EnumDeclaration) typeDeclaration;
            physicalTypeCategory = PhysicalTypeCategory.ENUMERATION;
        }

        Validate.notNull(physicalTypeCategory, UNSUPPORTED_MESSAGE_PREFIX
                + " (" + typeDeclaration.getClass().getSimpleName() + " for "
                + name + ")");

        cidBuilder.setName(name);
        cidBuilder.setPhysicalTypeCategory(physicalTypeCategory);

        imports = compilationUnit.getImports();
        if (imports == null) {
            imports = new ArrayList<ImportDeclaration>();
            compilationUnit.setImports(imports);
        }

        // Verify the package declaration appears to be correct
        Validate.isTrue(compilationUnitPackage.equals(name.getPackage()),
                "Compilation unit package '" + compilationUnitPackage
                        + "' unexpected for type '" + name.getPackage() + "'");

        for (final ImportDeclaration importDeclaration : imports) {
            if (importDeclaration.getName() instanceof QualifiedNameExpr) {
                final String qualifier = ((QualifiedNameExpr) importDeclaration
                        .getName()).getQualifier().toString();
                final String simpleName = importDeclaration.getName().getName();
                final String fullName = qualifier + "." + simpleName;
                // We want to calculate these...

                final JavaType type = new JavaType(fullName);
                final JavaPackage typePackage = importDeclaration.isAsterisk()
                    ? new JavaPackage(fullName) : type.getPackage();
                final ImportMetadataBuilder newImport = new ImportMetadataBuilder(
                        declaredByMetadataId, 0, typePackage, type,
                        importDeclaration.isStatic(),
                        importDeclaration.isAsterisk());
                cidBuilder.add(newImport.build());
View Full Code Here


        shell.flash(Level.FINE, "", JsfOperationsImpl.class.getName());
    }

    public void createManagedBean(final JavaType managedBean,
            final JavaType entity, String beanName, final boolean includeOnMenu) {
        final JavaPackage managedBeanPackage = managedBean.getPackage();
        installFacesConfig(managedBeanPackage);
        installI18n(managedBeanPackage);
        installBean("ApplicationBean-template.java", managedBeanPackage);

        final String managedBeanTypeName = managedBeanPackage
                .getFullyQualifiedPackageName();
        final JavaPackage utilPackage = new JavaPackage(managedBeanTypeName
                + ".util");
        installBean("LocaleBean-template.java", utilPackage);
        installBean(
                "ViewExpiredExceptionExceptionHandlerFactory-template.java",
                utilPackage);
        installBean("ViewExpiredExceptionExceptionHandler-template.java",
                utilPackage);
        installBean("MessageFactory-template.java", utilPackage);

        if (fileManager.exists(typeLocationService
                .getPhysicalTypeCanonicalPath(managedBean,
                        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
        final AnnotationMetadataBuilder annotationBuilder = new AnnotationMetadataBuilder(
                ROO_JSF_MANAGED_BEAN);
        annotationBuilder.addClassAttribute("entity", entity);

        if (StringUtils.isBlank(beanName)) {
            beanName = StringUtils
                    .uncapitalize(managedBean.getSimpleTypeName());
        }
        annotationBuilder.addStringAttribute("beanName", beanName);

        if (!includeOnMenu) {
            annotationBuilder.addBooleanAttribute("includeOnMenu",
                    includeOnMenu);
        }

        final LogicalPath managedBeanPath = pathResolver
                .getFocusedPath(Path.SRC_MAIN_JAVA);
        final String resourceIdentifier = typeLocationService
                .getPhysicalTypeCanonicalPath(managedBean, managedBeanPath);
        final String declaredByMetadataId = PhysicalTypeIdentifier
                .createIdentifier(managedBean,
                        pathResolver.getPath(resourceIdentifier));

        final ClassOrInterfaceTypeDetailsBuilder cidBuilder = new ClassOrInterfaceTypeDetailsBuilder(
                declaredByMetadataId, Modifier.PUBLIC, managedBean,
                PhysicalTypeCategory.CLASS);
        cidBuilder
                .addAnnotation(new AnnotationMetadataBuilder(ROO_SERIALIZABLE));
        cidBuilder.addAnnotation(annotationBuilder);

        typeManagementService.createOrUpdateTypeOnDisk(cidBuilder.build());

        shell.flash(Level.FINE,
                "Created " + managedBean.getFullyQualifiedTypeName(),
                JsfOperationsImpl.class.getName());
        shell.flash(Level.FINE, "", JsfOperationsImpl.class.getName());

        copyEntityTypePage(entity, beanName, pluralMetadata.getPlural());

        // Create a javax.faces.convert.Converter class for the entity
        createConverter(new JavaPackage(managedBeanTypeName + ".converter"),
                entity);
    }
View Full Code Here

            final NameExpr nameToFind, final Set<JavaSymbolName> typeParameters) {
        Validate.notNull(compilationUnitServices,
                "Compilation unit services required");
        Validate.notNull(nameToFind, "Name to find is required");

        final JavaPackage compilationUnitPackage = compilationUnitServices
                .getCompilationUnitPackage();

        if (nameToFind instanceof QualifiedNameExpr) {
            final QualifiedNameExpr qne = (QualifiedNameExpr) nameToFind;

            // Handle qualified name expressions that are related to inner types
            // (eg Foo.Bar)
            final NameExpr qneQualifier = qne.getQualifier();
            final NameExpr enclosedBy = getNameExpr(compilationUnitServices
                    .getEnclosingTypeName().getSimpleTypeName());
            if (isEqual(qneQualifier, enclosedBy)) {
                // 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);
        }
View Full Code Here

            final Set<JavaSymbolName> typeParameters) {
        Validate.notNull(compilationUnitServices,
                "Compilation unit services required");
        Validate.notNull(cit, "ClassOrInterfaceType required");

        final JavaPackage compilationUnitPackage = compilationUnitServices
                .getCompilationUnitPackage();
        Validate.notNull(compilationUnitPackage,
                "Compilation unit package required");

        String typeName = cit.getName();
View Full Code Here

     *         null)
     */
    public static NameExpr importTypeIfRequired(final JavaType targetType,
            final List<ImportDeclaration> imports, final JavaType typeToImport) {
        Validate.notNull(targetType, "Target type is required");
        final JavaPackage compilationUnitPackage = targetType.getPackage();
        Validate.notNull(imports, "Compilation unit imports required");
        Validate.notNull(typeToImport, "Java type to import is required");

        // If it's a primitive, it's really easy
        if (typeToImport.isPrimitive()) {
            return new NameExpr(typeToImport.getNameIncludingTypeParameters());
        }

        // Handle if the type doesn't have a package at all
        if (typeToImport.isDefaultPackage()) {
            return new NameExpr(typeToImport.getSimpleTypeName());
        }

        final JavaPackage typeToImportPackage = typeToImport.getPackage();
        if (typeToImportPackage.equals(compilationUnitPackage)) {
            return new NameExpr(typeToImport.getSimpleTypeName());
        }

        NameExpr typeToImportExpr;
        if (typeToImport.getEnclosingType() == null) {
View Full Code Here

        final HashSet<String> imported = new HashSet<String>();
        final ArrayList<ImportDeclaration> imports = new ArrayList<ImportDeclaration>();
        for (final ImportDeclaration importDeclaration : compilationUnit
                .getImports()) {
            JavaPackage importPackage = null;
            JavaType importType = null;
            if (importDeclaration.isAsterisk()) {
                importPackage = new JavaPackage(importDeclaration.getName()
                        .toString());
            }
            else {
                importType = new JavaType(importDeclaration.getName()
                        .toString());
                importPackage = importType.getPackage();
            }

            if (importPackage.equals(cid.getName().getPackage())
                    && importDeclaration.isAsterisk()) {
                continue;
            }

            if (importPackage.equals(cid.getName().getPackage())
                    && importType != null
                    && importType.getEnclosingType() == null) {
                continue;
            }
View Full Code Here

            final CompilationUnit compilationUnit = JavaParser
                    .parse(new ByteArrayInputStream(typeContents.getBytes()));
            if (compilationUnit == null || compilationUnit.getPackage() == null) {
                return null;
            }
            return new JavaPackage(compilationUnit.getPackage().getName()
                    .toString());
        }
        catch (final IOException e) {
            throw new IllegalStateException(e);
        }
View Full Code Here

    }

    public JavaPackage getTopLevelPackage(final String moduleName) {
        final Pom pom = getPomFromModuleName(moduleName);
        if (pom != null) {
            return new JavaPackage(pom.getGroupId());
        }
        return null;
    }
View Full Code Here

            addIndices(table, tableElement, IndexType.UNIQUE);

            tables.add(table);
        }

        JavaPackage destinationPackage = null;
        if (StringUtils.isNotBlank(databaseElement.getAttribute("package"))) {
            destinationPackage = new JavaPackage(
                    databaseElement.getAttribute("package"));
        }

        final Database database = new Database(tables);
        database.setDestinationPackage(destinationPackage);
View Full Code Here

    }

    private void setBasePackageForComponentScan(final Document document) {
        final Element componentScanElement = DomUtils.findFirstElementByName(
                "context:component-scan", (Element) document.getFirstChild());
        final JavaPackage topLevelPackage = projectOperations
                .getTopLevelPackage(projectOperations.getFocusedModuleName());
        componentScanElement.setAttribute("base-package",
                topLevelPackage.getFullyQualifiedPackageName());
    }
View Full Code Here

TOP

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

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.