Package org.mybatis.generator.exception

Examples of org.mybatis.generator.exception.ShellException


    case Node.COMMENT_NODE:
      write((Comment) node);
      break;

    default:
      throw new ShellException(getString("RuntimeError.18", Short.toString(type))); //$NON-NLS-1$
    }
  }
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

    try {
      return getMergedSource(new InputSource(new StringReader(generatedXmlFile.getFormattedContent())),
          new InputSource(new FileReader(existingFile)), existingFile.getName());
    } catch (IOException e) {
      throw new ShellException(getString("Warning.13", //$NON-NLS-1$
          existingFile.getName()), e);
    } catch (SAXException e) {
      throw new ShellException(getString("Warning.13", //$NON-NLS-1$
          existingFile.getName()), e);
    } catch (ParserConfigurationException e) {
      throw new ShellException(getString("Warning.13", //$NON-NLS-1$
          existingFile.getName()), e);
    }
  }
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$
          existingFileName));
    }

    Element existingRootElement = existingDocument.getDocumentElement();
    Element newRootElement = newDocument.getDocumentElement();
View Full Code Here

        try {
            return getMergedSource(new InputSource(new StringReader(generatedXmlFile.getFormattedContent())),
                new InputSource(new InputStreamReader(new FileInputStream(existingFile), "UTF-8")), //$NON-NLS-1$
                existingFile.getName());
        } catch (IOException e) {
            throw new ShellException(getString("Warning.13", //$NON-NLS-1$
                    existingFile.getName()), e);
        } catch (SAXException e) {
            throw new ShellException(getString("Warning.13", //$NON-NLS-1$
                    existingFile.getName()), e);
        } catch (ParserConfigurationException e) {
            throw new ShellException(getString("Warning.13", //$NON-NLS-1$
                    existingFile.getName()), e);
        }
    }
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$
                    existingFileName));
        }

        Element existingRootElement = existingDocument.getDocumentElement();
        Element newRootElement = newDocument.getDocumentElement();
View Full Code Here

        case Node.COMMENT_NODE:
            write((Comment) node);
            break;

        default:
            throw new ShellException(getString(
                    "RuntimeError.18", Short.toString(type))); //$NON-NLS-1$
        }
    }
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 (!project.exists()) {
            project.mkdirs();
        }
       
        if (!project.isDirectory()) {
            throw new ShellException(Messages.getString("Warning.9", //$NON-NLS-1$
                    project.getAbsolutePath()));
        }
       
        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(Messages.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) {
            if (newSuperInterface.isSimpleType()) {
                SimpleType st = (SimpleType) newSuperInterface;
                Name name = ast.newName(st.getName().getFullyQualifiedName());
                SimpleType newSt = ast.newSimpleType(name);
                typeDeclaration.superInterfaceTypes().add(newSt);
            } else {
                // this shouldn't happen - MyBatis Generator only generates simple names
                throw new ShellException("The Java file merger only supports simple types as super interfaces");
            }
        }

        // set the superclass
        if (newJavaFileVisitor.getSuperclass() != null) {
            if (newJavaFileVisitor.getSuperclass().isSimpleType()) {
                SimpleType st = (SimpleType) newJavaFileVisitor.getSuperclass();
                Name name = ast.newName(st.getName().getFullyQualifiedName());
                SimpleType newSt = ast.newSimpleType(name);
                typeDeclaration.setSuperclassType(newSt);
            } else {
                // this shouldn't happen - MyBatis Generator only generates simple names
                throw new ShellException("The Java file merger only supports simple types as super classes");
            }
        } 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;
                }
            }
           
            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.