Example usage for javax.xml.bind ValidationException ValidationException

List of usage examples for javax.xml.bind ValidationException ValidationException

Introduction

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

Prototype

public ValidationException(String message, Throwable exception) 

Source Link

Document

Construct an ValidationException with the specified detail message and linkedException.

Usage

From source file:csiro.pidsvc.mappingstore.Manager.java

/**************************************************************************
 *  Generic processing methods./*from   w ww .j ava2  s. c  om*/
 */

protected void validateRequest(String inputData, String xmlSchemaResourcePath)
        throws IOException, ValidationException {
    try {
        SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
        schemaFactory.setResourceResolver(new LSResourceResolver() {
            @Override
            public LSInput resolveResource(String type, String namespaceURI, String publicId, String systemId,
                    String baseURI) {
                return new XsdSchemaResolver(type, namespaceURI, publicId, systemId, baseURI);
            }
        });

        Schema schema = schemaFactory
                .newSchema(new StreamSource(getClass().getResourceAsStream(xmlSchemaResourcePath)));
        Validator validator = schema.newValidator();
        _logger.trace("Validating XML Schema.");
        validator.validate(new StreamSource(new StringReader(inputData)));
    } catch (SAXException ex) {
        _logger.debug("Unknown format.", ex);
        throw new ValidationException("Unknown format.", ex);
    }
}

From source file:org.pepstock.jem.ant.validator.transformer.TransformerValidator.java

/**
 * Create the file listner. if already exists, recreate a new one
 * /* ww w .  j  a  va 2s. c o  m*/
 * @param xsltvalidatorFile the xsltvalidator file
 * @throws ValidationException the validation exception
 */
private void createFileListner(String xsltvalidatorFile) throws ValidationException {

    try {
        if (monitor == null) {
            // create a new monitor
            // interval default: 10 sec
            monitor = new FileAlterationMonitor();
        } else {
            // stop monitor
            monitor.stop();
        }

        // remove old observer
        if (observer != null) {
            monitor.removeObserver(observer);
            observer.removeListener(this);
            observer.destroy();
            observer = null;
        }

        // create new observer, the file is already validated
        File f = new File(xsltvalidatorFile);
        String fDir = f.getParent();
        String fName = f.getName();

        // Create a FileFilter
        IOFileFilter filter = FileFilterUtils.nameFileFilter(fName);

        observer = new FileAlterationObserver(fDir, filter);
        observer.addListener(this);
        monitor.addObserver(observer);

        // start monitor
        monitor.start();

    } catch (Exception e) {
        throw new ValidationException(e.getMessage(), e);
    }
}