Package org.mybatis.generator.exception

Examples of org.mybatis.generator.exception.ShellException


            // calculated by the eclipse callback
            StringBuilder sb = new StringBuilder();
            sb.append("The file ");
            sb.append(existingFilePath);
            sb.append(" does not exist");
            throw new ShellException(sb.toString());
        }

        try {
            StringBuilder sb = new StringBuilder();
            BufferedReader br = new BufferedReader(new FileReader(file));
            char[] buffer = new char[1024];
            int returnedBytes = br.read(buffer);
            while (returnedBytes != -1) {
                sb.append(buffer, 0, returnedBytes);
                returnedBytes = br.read(buffer);
            }
       
            br.close();
            return sb.toString();
        } catch (IOException e) {
            StringBuilder sb = new StringBuilder();
            sb.append("IOException reading the file ");
            sb.append(existingFilePath);
            throw new ShellException(sb.toString(), e);
        }
    }
View Full Code Here


            StringBuffer sb = new StringBuffer();
            sb.append("targetProject ");
            sb.append(targetProject);
            sb.append(" is invalid - it cannot start with / or \\");

            throw new ShellException(sb.toString());
        }
       
        IFolder folder = getFolder(targetProject, targetPackage);

        return folder.getRawLocation().toFile();
View Full Code Here

            if (project.exists()) {
                boolean isJavaProject;
                try {
                    isJavaProject = project.hasNature(JavaCore.NATURE_ID);
                } catch (CoreException e) {
                    throw new ShellException(e.getStatus().getMessage(), e);
                }
                if (isJavaProject) {
                    javaProject = JavaCore.create(project);
                } else {
                    StringBuffer sb = new StringBuffer();
                    sb.append("Project ");
                    sb.append(javaProjectName);
                    sb.append(" is not a Java project");

                    throw new ShellException(sb.toString());
                }
            } else {
                StringBuffer sb = new StringBuffer();
                sb.append("Project ");
                sb.append(javaProjectName);
                sb.append(" does not exist");

                throw new ShellException(sb.toString());
            }

            projects.put(javaProjectName, javaProject);
        }
View Full Code Here

            try {
                folder = (IFolder) packageFragment.getCorrespondingResource();

                folders.put(key, folder);
            } catch (CoreException e) {
                throw new ShellException(e.getStatus().getMessage(), e);
            }
        }

        return folder;
    }
View Full Code Here

        // find the first non-JAR package fragment root
        IPackageFragmentRoot[] roots;
        try {
            roots = javaProject.getPackageFragmentRoots();
        } catch (CoreException e) {
            throw new ShellException(e.getStatus().getMessage(), e);
        }

        IPackageFragmentRoot srcFolder = null;
        for (int i = 0; i < roots.length; i++) {
            if (roots[i].isArchive() || roots[i].isReadOnly()
                    || roots[i].isExternal()) {
                continue;
            } else {
                srcFolder = roots[i];
                break;
            }
        }

        if (srcFolder == null) {
            StringBuffer sb = new StringBuffer();
            sb.append("Cannot find source folder for project ");
            sb.append(javaProject.getElementName());

            throw new ShellException(sb.toString());
        }

        return srcFolder;
    }
View Full Code Here

            if (pfr == null) {
                StringBuffer sb = new StringBuffer();
                sb.append("Cannot find source folder ");
                sb.append(targetProject);

                throw new ShellException(sb.toString());
            }

            return pfr;
        } catch (CoreException e) {
            throw new ShellException(e.getStatus().getMessage(), e);
        }
    }
View Full Code Here

            }

            fragment.getCorrespondingResource().refreshLocal(
                    IResource.DEPTH_ONE, null);
        } catch (CoreException e) {
            throw new ShellException(e.getStatus().getMessage(), e);
        }

        return fragment;
    }
View Full Code Here

            DocumentType newDocType = newDocument.getDoctype();
            DocumentType existingDocType = existingDocument.getDoctype();

            if (!newDocType.getName().equals(existingDocType.getName())) {
                throw new ShellException(getString("Warning.12", //$NON-NLS-1$
                        existingFile.getName()));
            }

            Element existingRootElement = existingDocument.getDocumentElement();
            Element newRootElement = newDocument.getDocumentElement();

            // reconcile the root element attributes -
            // take all attributes from the new element and add to the existing
            // element

            // remove all attributes from the existing root element
            NamedNodeMap attributes = existingRootElement.getAttributes();
            int attributeCount = attributes.getLength();
            for (int i = attributeCount - 1; i >= 0; i--) {
                Node node = attributes.item(i);
                existingRootElement.removeAttribute(node.getNodeName());
            }

            // add attributes from the new root node to the old root node
            attributes = newRootElement.getAttributes();
            attributeCount = attributes.getLength();
            for (int i = 0; i < attributeCount; i++) {
                Node node = attributes.item(i);
                existingRootElement.setAttribute(node.getNodeName(), node
                        .getNodeValue());
            }

            // remove the old generated elements and any
            // white space before the old nodes
            List<Node> nodesToDelete = new ArrayList<Node>();
            NodeList children = existingRootElement.getChildNodes();
            int length = children.getLength();
            for (int i = 0; i < length; i++) {
                Node node = children.item(i);
                if (isGeneratedNode(node)) {
                    nodesToDelete.add(node);
                } else if (isWhiteSpace(node)
                        && isGeneratedNode(children.item(i + 1))) {
                    nodesToDelete.add(node);
                }
            }

            for (Node node : nodesToDelete) {
                existingRootElement.removeChild(node);
            }

            // add the new generated elements
            children = newRootElement.getChildNodes();
            length = children.getLength();
            Node firstChild = existingRootElement.getFirstChild();
            for (int i = 0; i < length; i++) {
                Node node = children.item(i);
                // don't add the last node if it is only white space
                if (i == length - 1) {
                    if (isWhiteSpace(node)) {
                        break;
                    }
                }

                Node newNode = existingDocument.importNode(node, true);
                if (firstChild == null) {
                    existingRootElement.appendChild(newNode);
                } else {
                    existingRootElement.insertBefore(newNode, firstChild);
                }
            }

            // pretty print the result
            return prettyPrint(existingDocument);
        } catch (Exception e) {
            throw new ShellException(getString("Warning.13", //$NON-NLS-1$
                    existingFile.getName()), e);
        }
    }
View Full Code Here

        // created
        // if it does not already exist

        File project = new File(targetProject);
        if (!project.isDirectory()) {
            throw new ShellException(getString("Warning.9", //$NON-NLS-1$
                    targetProject));
        }

        StringBuilder sb = new StringBuilder();
        StringTokenizer st = new StringTokenizer(targetPackage, "."); //$NON-NLS-1$
        while (st.hasMoreTokens()) {
            sb.append(st.nextToken());
            sb.append(File.separatorChar);
        }

        File directory = new File(project, sb.toString());
        if (!directory.isDirectory()) {
            boolean rc = directory.mkdirs();
            if (!rc) {
                throw new ShellException(getString("Warning.10", //$NON-NLS-1$
                        directory.getAbsolutePath()));
            }
        }

        return directory;
View Full Code Here

        if (typeDeclaration == null) {
            StringBuffer sb = new StringBuffer();
            sb.append("No types defined in the file ");
            sb.append(existingFilePath);

            throw new ShellException(sb.toString());
        }

        // reconcile the superinterfaces
        List<Type> newSuperInterfaces = getNewSuperInterfaces(
                typeDeclaration.superInterfaceTypes(), newJavaFileVisitor);
        for (Type newSuperInterface : newSuperInterfaces) {
            typeDeclaration.superInterfaceTypes().add(
                    ASTNode.copySubtree(ast, newSuperInterface));
        }

        // set the superclass
        if (newJavaFileVisitor.getSuperclass() != null) {
            typeDeclaration.setSuperclassType((Type) ASTNode.copySubtree(ast,
                    newJavaFileVisitor.getSuperclass()));
        } else {
            typeDeclaration.setSuperclassType(null);
        }

        // interface or class?
        if (newJavaFileVisitor.isInterface()) {
            typeDeclaration.setInterface(true);
        } else {
            typeDeclaration.setInterface(false);
        }

        // reconcile the imports
        List<ImportDeclaration> newImports = getNewImports(cu.imports(),
                newJavaFileVisitor);
        for (ImportDeclaration newImport : newImports) {
            Name name = ast
                    .newName(newImport.getName().getFullyQualifiedName());
            ImportDeclaration newId = ast.newImportDeclaration();
            newId.setName(name);
            cu.imports().add(newId);
        }

        TextEdit textEdit = cu.rewrite(document, null);
        try {
            textEdit.apply(document);
        } catch (BadLocationException e) {
            throw new ShellException(
                    "BadLocationException removing prior fields and methods");
        }

        // regenerate the CompilationUnit to reflect all the deletes and changes
        astParser.setSource(document.get().toCharArray());
        CompilationUnit strippedCu = (CompilationUnit) astParser
                .createAST(null);

        // find the top level public type declaration
        TypeDeclaration topLevelType = null;
        Iterator iter = strippedCu.types().iterator();
        while (iter.hasNext()) {
            TypeDeclaration td = (TypeDeclaration) iter.next();
            if (td.getParent().equals(strippedCu)
                    && (td.getModifiers() & Modifier.PUBLIC) > 0) {
                topLevelType = td;
                break;
            }
        }

        // now add all the new methods and fields to the existing
        // CompilationUnit with a ListRewrite
        ASTRewrite rewrite = ASTRewrite.create(topLevelType.getRoot().getAST());
        ListRewrite listRewrite = rewrite.getListRewrite(topLevelType,
                TypeDeclaration.BODY_DECLARATIONS_PROPERTY);

        Iterator<ASTNode> astIter = newJavaFileVisitor.getNewNodes().iterator();
        int i = 0;
        while (astIter.hasNext()) {
            ASTNode node = astIter.next();

            if (node.getNodeType() == ASTNode.TYPE_DECLARATION) {
                String name = ((TypeDeclaration) node).getName()
                        .getFullyQualifiedName();
                if (visitor.containsInnerClass(name)) {
                    continue;
                }
            } else if (node instanceof FieldDeclaration) {
                addExistsAnnotations((BodyDeclaration) node,
                        visitor.getFieldAnnotations((FieldDeclaration) node));
            } else if (node instanceof MethodDeclaration) {
                addExistsAnnotations((BodyDeclaration) node,
                        visitor.getMethodAnnotations((MethodDeclaration) node));
            }

            listRewrite.insertAt(node, i++, null);
        }

        textEdit = rewrite.rewriteAST(document, JavaCore.getOptions());
        try {
            textEdit.apply(document);
        } catch (BadLocationException e) {
            throw new ShellException(
                    "BadLocationException adding new fields and methods");
        }

        String newSource = document.get();
        return newSource;
View Full Code Here

TOP

Related Classes of org.mybatis.generator.exception.ShellException

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.