Example usage for javax.xml.bind JAXBException printStackTrace

List of usage examples for javax.xml.bind JAXBException printStackTrace

Introduction

In this page you can find the example usage for javax.xml.bind JAXBException printStackTrace.

Prototype

public void printStackTrace() 

Source Link

Document

Prints this JAXBException and its stack trace (including the stack trace of the linkedException if it is non-null) to System.err .

Usage

From source file:visualoozie.api.UploadXmlAction.java

private UploadXmlResult generateResult(String rawXml) {
    UploadXmlResult result = new UploadXmlResult();

    Scanner scanner = new Scanner(rawXml);
    List<String> lines = new ArrayList<>();
    while (scanner.hasNextLine()) {
        String line = scanner.nextLine();
        lines.add(line);// w  w  w .  jav  a 2  s . co  m
    }
    result.xml = lines.toArray(new String[0]);

    // find xmlns to identify a version for the oozie xsd
    Pattern xmlnsPattern = Pattern.compile("workflow-app *xmlns *= *['|\"](.*?)['|\"]"); // TODO this is not good enough. e.g. when xmlns is on a line after.
    Matcher m = xmlnsPattern.matcher(rawXml);
    String xmlns = null;
    while (m.find()) {
        xmlns = m.group(1);
    }

    result.setIdentifiedNamespace(xmlns);
    List<WorkflowNode> nodes;
    try {
        if ("uri:oozie:workflow:0.1".equals(xmlns)) {
            nodes = new Workflow01Parser().parse(rawXml);
        } else if ("uri:oozie:workflow:0.2".equals(xmlns)) {
            nodes = new Workflow02Parser().parse(rawXml);
        } else if ("uri:oozie:workflow:0.2.5".equals(xmlns)) {
            nodes = new Workflow025Parser().parse(rawXml);
        } else if ("uri:oozie:workflow:0.3".equals(xmlns)) {
            nodes = new Workflow03Parser().parse(rawXml);
        } else if ("uri:oozie:workflow:0.4".equals(xmlns)) {
            nodes = new Workflow04Parser().parse(rawXml);
        } else {
            nodes = new Workflow04Parser().parse(rawXml);
        }
    } catch (JAXBException e) {
        // TODO Auto-generated catch block
        result.succeeded = false;
        if (e.getLinkedException() instanceof SAXParseException) {
            SAXParseException e2 = (SAXParseException) e.getLinkedException();
            result.lineNumber = e2.getLineNumber();
            result.columnNumber = e2.getColumnNumber();
            result.errorMessage = e2.getMessage();

        } else {
            e.printStackTrace();
            result.errorMessage = e.getMessage();
        }
        return result;
    } catch (Exception e) {
        e.printStackTrace();
        result.succeeded = false;
        result.errorMessage = e.getMessage();
        return result;
    }

    result.setNodes(nodes);
    result.succeeded = true;
    return result;
}