Example usage for javax.xml.bind JAXBContext createValidator

List of usage examples for javax.xml.bind JAXBContext createValidator

Introduction

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

Prototype

@Deprecated
public abstract Validator createValidator() throws JAXBException;

Source Link

Document

Validator has been made optional and deprecated in JAXB 2.0.

Usage

From source file:de.thorstenberger.taskmodel.complex.complextaskdef.impl.ComplexTaskDefDAOImpl.java

public void save(ComplexTaskDefRoot ctdr, OutputStream os) throws TaskApiException {
    BufferedOutputStream bos = new BufferedOutputStream(os);

    Marshaller marshaller = null;
    try {//from   ww  w . j  a v a  2s.com
        JAXBContext jc = createJAXBContext();
        marshaller = JAXBUtils.getJAXBMarshaller(jc);
        Validator validator = jc.createValidator();
        ComplexTaskDef ctd = ((ComplexTaskDefRootImpl) ctdr).getJAXBContent();
        validator.validate(ctd);
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, new Boolean(true));
        marshaller.marshal(ctd, bos);

    } catch (JAXBException e) {
        throw new TaskModelPersistenceException(e);
    } finally {
        try {
            bos.close();
        } catch (IOException e) {
            throw new TaskModelPersistenceException(e);
        }
        if (marshaller != null)
            JAXBUtils.releaseJAXBMarshaller(jc, marshaller);
    }

}