Example usage for javax.xml.bind JAXBException getLinkedException

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

Introduction

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

Prototype

public Throwable getLinkedException() 

Source Link

Document

Get the linked exception

Usage

From source file:org.voltdb.compiler.VoltCompiler.java

/**
 * Read the project file and get the database object.
 * @param projectFileURL  project file URL/path
 * @return  database for project or null
 *//* ww w.ja  v  a  2 s . c  o m*/
private DatabaseType getProjectDatabase(final VoltCompilerReader projectReader) {
    DatabaseType database = null;
    if (projectReader != null) {
        m_currentFilename = projectReader.getName();
        try {
            JAXBContext jc = JAXBContext.newInstance("org.voltdb.compiler.projectfile");
            // This schema shot the sheriff.
            SchemaFactory sf = SchemaFactory.newInstance(javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI);
            Schema schema = sf.newSchema(this.getClass().getResource("ProjectFileSchema.xsd"));
            Unmarshaller unmarshaller = jc.createUnmarshaller();
            // But did not shoot unmarshaller!
            unmarshaller.setSchema(schema);
            @SuppressWarnings("unchecked")
            JAXBElement<ProjectType> result = (JAXBElement<ProjectType>) unmarshaller.unmarshal(projectReader);
            ProjectType project = result.getValue();
            database = project.getDatabase();
        } catch (JAXBException e) {
            // Convert some linked exceptions to more friendly errors.
            if (e.getLinkedException() instanceof java.io.FileNotFoundException) {
                addErr(e.getLinkedException().getMessage());
                compilerLog.error(e.getLinkedException().getMessage());
            } else {
                DeprecatedProjectElement deprecated = DeprecatedProjectElement.valueOf(e);
                if (deprecated != null) {
                    addErr("Found deprecated XML element \"" + deprecated.name() + "\" in project.xml file, "
                            + deprecated.getSuggestion());
                    addErr("Error schema validating project.xml file. " + e.getLinkedException().getMessage());
                    compilerLog.error(
                            "Found deprecated XML element \"" + deprecated.name() + "\" in project.xml file");
                    compilerLog.error(e.getMessage());
                    compilerLog.error(projectReader.getPath());
                } else if (e.getLinkedException() instanceof org.xml.sax.SAXParseException) {
                    addErr("Error schema validating project.xml file. " + e.getLinkedException().getMessage());
                    compilerLog.error(
                            "Error schema validating project.xml file: " + e.getLinkedException().getMessage());
                    compilerLog.error(e.getMessage());
                    compilerLog.error(projectReader.getPath());
                } else {
                    throw new RuntimeException(e);
                }
            }
        } catch (SAXException e) {
            addErr("Error schema validating project.xml file. " + e.getMessage());
            compilerLog.error("Error schema validating project.xml file. " + e.getMessage());
        }
    } else {
        // No project.xml - create a stub object.
        database = new DatabaseType();
    }

    return database;
}

From source file:org.voltdb.utils.CatalogUtil.java

/**
 * Get a reference to the root <deployment> element from the deployment.xml file.
 * @param deployIS/*from w  ww  .j a  v  a2  s  . c o m*/
 * @return Returns a reference to the root <deployment> element.
 */
@SuppressWarnings("unchecked")
public static DeploymentType getDeployment(InputStream deployIS) {
    try {
        if (m_jc == null || m_schema == null) {
            throw new RuntimeException("Error schema validation.");
        }
        Unmarshaller unmarshaller = m_jc.createUnmarshaller();
        unmarshaller.setSchema(m_schema);
        JAXBElement<DeploymentType> result = (JAXBElement<DeploymentType>) unmarshaller.unmarshal(deployIS);
        DeploymentType deployment = result.getValue();
        // move any deprecated standalone export elements to the default target
        ExportType export = deployment.getExport();
        if (export != null && export.getTarget() != null) {
            if (export.getConfiguration().size() > 1) {
                hostLog.error(
                        "Invalid schema, cannot use deprecated export syntax with multiple configuration tags.");
                return null;
            }
            //OLD syntax use target as type.
            if (export.getConfiguration().isEmpty()) {
                // this code is for RestRoundtripTest
                export.getConfiguration().add(new ExportConfigurationType());
            }
            ExportConfigurationType exportConfig = export.getConfiguration().get(0);
            if (export.isEnabled() != null) {
                exportConfig.setEnabled(export.isEnabled());
            }
            if (export.getTarget() != null) {
                exportConfig.setType(export.getTarget());
            }
            if (export.getExportconnectorclass() != null) {
                exportConfig.setExportconnectorclass(export.getExportconnectorclass());
            }
            //Set target to default name.
            exportConfig.setStream(Constants.DEFAULT_EXPORT_CONNECTOR_NAME);
        }

        populateDefaultDeployment(deployment);
        return deployment;
    } catch (JAXBException e) {
        // Convert some linked exceptions to more friendly errors.
        if (e.getLinkedException() instanceof java.io.FileNotFoundException) {
            hostLog.error(e.getLinkedException().getMessage());
            return null;
        } else if (e.getLinkedException() instanceof org.xml.sax.SAXParseException) {
            hostLog.error(
                    "Error schema validating deployment.xml file. " + e.getLinkedException().getMessage());
            return null;
        } else {
            throw new RuntimeException(e);
        }
    }
}

From source file:org.voltdb.utils.CatalogUtil.java

/**
 * Given the deployment object generate the XML
 * @param deployment/* www . j av a2 s  . c  o m*/
 * @return XML of deployment object.
 * @throws IOException
 */
public static String getDeployment(DeploymentType deployment) throws IOException {
    try {
        if (m_jc == null || m_schema == null) {
            throw new RuntimeException("Error schema validation.");
        }
        Marshaller marshaller = m_jc.createMarshaller();
        marshaller.setSchema(m_schema);
        StringWriter sw = new StringWriter();
        marshaller.marshal(new JAXBElement(new QName("", "deployment"), DeploymentType.class, deployment), sw);
        return sw.toString();
    } catch (JAXBException e) {
        // Convert some linked exceptions to more friendly errors.
        if (e.getLinkedException() instanceof java.io.FileNotFoundException) {
            hostLog.error(e.getLinkedException().getMessage());
            return null;
        } else if (e.getLinkedException() instanceof org.xml.sax.SAXParseException) {
            hostLog.error(
                    "Error schema validating deployment.xml file. " + e.getLinkedException().getMessage());
            return null;
        } else {
            throw new RuntimeException(e);
        }
    }
}

From source file:org.wso2.carbon.device.mgt.core.app.mgt.AppManagementConfigurationManagerTest.java

private void validateMalformedConfig(File malformedConfig) {
    try {//from   w ww . j  a  v a2s.  c  o m
        JAXBContext ctx = JAXBContext.newInstance(AppManagementConfig.class);
        Unmarshaller um = ctx.createUnmarshaller();
        um.setSchema(this.getSchema());
        um.unmarshal(malformedConfig);
        Assert.assertTrue(false);
    } catch (JAXBException e) {
        Throwable linkedException = e.getLinkedException();
        if (!(linkedException instanceof SAXParseException)) {
            log.error("Unexpected error occurred while unmarshalling app management config", e);
            Assert.assertTrue(false);
        }
        log.error("JAXB parser occurred while unmarsharlling app management config", e);
        Assert.assertTrue(true);
    }
}

From source file:org.wso2.carbon.device.mgt.core.DeviceManagementConfigTests.java

private void validateMalformedConfig(File malformedConfig) {
    try {/*from  w  w  w  .  j  av  a  2s. co  m*/
        JAXBContext ctx = JAXBContext.newInstance(DeviceManagementConfig.class);
        Unmarshaller um = ctx.createUnmarshaller();
        um.setSchema(this.getSchema());
        um.unmarshal(malformedConfig);
        Assert.assertTrue(false);
    } catch (JAXBException e) {
        Throwable linkedException = e.getLinkedException();
        if (!(linkedException instanceof SAXParseException)) {
            log.error("Unexpected error occurred while unmarshalling device management config", e);
            Assert.assertTrue(false);
        }
        log.error("JAXB parser occurred while unmarsharlling device management config", e);
        Assert.assertTrue(true);
    }
}

From source file:org.wso2.carbon.device.mgt.mobile.impl.MobileDeviceManagementConfigTests.java

/**
 * Validates a given malformed-configuration file.
 *///from  www. j av  a2s . c  o  m
private void validateMalformedConfig(File malformedConfig) {
    try {
        JAXBContext ctx = JAXBContext.newInstance(MobileDeviceManagementConfig.class);
        Unmarshaller um = ctx.createUnmarshaller();
        um.setSchema(this.getSchema());
        um.unmarshal(malformedConfig);
        Assert.assertTrue(false);
    } catch (JAXBException e) {
        Throwable linkedException = e.getLinkedException();
        if (!(linkedException instanceof SAXParseException)) {
            log.error("Unexpected error occurred while unmarshalling mobile device management config", e);
            Assert.assertTrue(false);
        }
        Assert.assertTrue(true);
    }
}

From source file:ox.softeng.gel.filereceive.FileReceive.java

public static void main(String[] args) {

    if (hasSimpleOptions(args))
        System.exit(0);/*from w  w w .  java2  s  . c o  m*/

    try {
        // parse the command line arguments
        CommandLine line = parser.parse(defineMainOptions(), args);

        long start = System.currentTimeMillis();

        try {
            FileReceive fr = new FileReceive(line.getOptionValue('c'), line.getOptionValue('r'),
                    (Integer) line.getParsedOptionValue("p"),
                    line.getOptionValue('u', ConnectionFactory.DEFAULT_USER),
                    line.getOptionValue('w', ConnectionFactory.DEFAULT_PASS), line.getOptionValue('e'),
                    line.getOptionValue('b'), (Long) line.getParsedOptionValue("t"));
            fr.startMonitors();

            logger.info("File receiver started in {}ms", System.currentTimeMillis() - start);
        } catch (JAXBException ex) {
            logger.error("Could not create file receiver because of JAXBException: {}",
                    ex.getLinkedException().getMessage());
        } catch (IOException | TimeoutException ex) {
            logger.error("Could not create file receiver because: {}", ex.getMessage());
            ex.printStackTrace();
        }
    } catch (ParseException exp) {
        logger.error("Could not start file-receiver because of ParseException: " + exp.getMessage());
        help();
    }
}

From source file:pl.nask.hsn2.workflow.parser.HWLParser.java

private WorkflowSyntaxException makeWorkflowSyntaxException(JAXBException e) {
    int lineNo = -1;
    int colNo = -1;
    String msg = e.getMessage();/*  ww  w . j av a2  s  . c  o  m*/
    if (e.getLinkedException() instanceof SAXParseException) {
        SAXParseException linked = (SAXParseException) e.getLinkedException();
        lineNo = linked.getLineNumber();
        colNo = linked.getColumnNumber();
        msg = linked.getMessage();
    }

    return new WorkflowSyntaxException(e, lineNo, colNo, msg);
}

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);//from www .  ja va2s  .  c om
    }
    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;
}