class PersistenceDescriptorXMLMarshaller {

    public static PersistenceDescriptorModel fromXML( InputStream xmlStream, boolean validate ) throws Exception {

        DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
        builderFactory.setNamespaceAware( true );
        DocumentBuilder documentBuilder = builderFactory.newDocumentBuilder();
        Document document = documentBuilder.parse( xmlStream );
        if ( validate ) {
            Validator validator = getPersistenceSchema().newValidator();
            validator.setErrorHandler( new ErrorHandler() {
                @Override
                public void warning( SAXParseException e ) throws SAXException {
                    //TODO add fine grained error processing if needed
                    logger.warn( "PersistenceDescriptorModel parsing error: ", e );
                }

                @Override
                public void error( SAXParseException e ) throws SAXException {
                    //TODO add fine grained error processing if needed
                    logger.error( "PersistenceDescriptorModel parsing error: ", e );
                    throw e;
                }

                @Override
                public void fatalError( SAXParseException e ) throws SAXException {
                    //TODO add fine grained error processing if needed
                    logger.error( "PersistenceDescriptorModel parsing error: ", e );
                    throw e;
                }
            } );
            validator.validate( new DOMSource( document ) );
        }

        DOM2PersistenceDescriptorVisitor visitor = new DOM2PersistenceDescriptorVisitor( document );
        return visitor.visit();
    }

}