Example usage for javax.xml.bind Validator validate

List of usage examples for javax.xml.bind Validator validate

Introduction

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

Prototype

public boolean validate(Object subrootObj) throws JAXBException;

Source Link

Document

Validate the Java content tree starting at subrootObj .

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  www .  ja v a 2  s.c  o m
        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);
    }

}