@Test public void readFromXMLTest() { try { PersistenceDescriptorModel descriptor = PersistenceDescriptorXMLMarshaller.fromXML( getInputStream( "persistence.xml" ), false ); assertEqualsDescriptor( expectedDescriptor(), descriptor ); } catch ( Exception e ) { fail( e.getMessage() ); } }
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 { logger.warn( "PersistenceDescriptorModel parsing error: ", e ); } @Override public void error( SAXParseException e ) throws SAXException { logger.error( "PersistenceDescriptorModel parsing error: ", e ); throw e; } @Override public void fatalError( SAXParseException e ) throws SAXException { logger.error( "PersistenceDescriptorModel parsing error: ", e ); throw e; } } ); validator.validate( new DOMSource( document ) ); } DOM2PersistenceDescriptorVisitor visitor = new DOM2PersistenceDescriptorVisitor( document ); return visitor.visit(); }
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 { logger.warn( "PersistenceDescriptorModel parsing error: ", e ); } @Override public void error( SAXParseException e ) throws SAXException { logger.error( "PersistenceDescriptorModel parsing error: ", e ); throw e; } @Override public void fatalError( SAXParseException e ) throws SAXException { logger.error( "PersistenceDescriptorModel parsing error: ", e ); throw e; } } ); validator.validate( new DOMSource( document ) ); } DOM2PersistenceDescriptorVisitor visitor = new DOM2PersistenceDescriptorVisitor( document ); return visitor.visit(); } }
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 { logger.warn( "PersistenceDescriptorModel parsing error: ", e ); } @Override public void error( SAXParseException e ) throws SAXException { logger.error( "PersistenceDescriptorModel parsing error: ", e ); throw e; } @Override public void fatalError( SAXParseException e ) throws SAXException { logger.error( "PersistenceDescriptorModel parsing error: ", e ); throw e; } } ); validator.validate( new DOMSource( document ) ); } DOM2PersistenceDescriptorVisitor visitor = new DOM2PersistenceDescriptorVisitor( document ); return visitor.visit(); }  }
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 { logger.warn( "PersistenceDescriptorModel parsing error: ", e ); } @Override public void error( SAXParseException e ) throws SAXException { logger.error( "PersistenceDescriptorModel parsing error: ", e ); throw e; } @Override public void fatalError( SAXParseException e ) throws SAXException { logger.error( "PersistenceDescriptorModel parsing error: ", e ); throw e; } } ); validator.validate( new DOMSource( document ) ); } DOM2PersistenceDescriptorVisitor visitor = new DOM2PersistenceDescriptorVisitor( document ); return visitor.visit(); }  static PersistenceDescriptorModel fromXML( InputStream xmlStream, boolean validate ); static String toXML( PersistenceDescriptorModel persistenceDescriptor ); static void toXML( PersistenceDescriptorModel persistenceDescriptor, OutputStream outputStream ); }
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 { logger.warn( "PersistenceDescriptorModel parsing error: ", e ); } @Override public void error( SAXParseException e ) throws SAXException { logger.error( "PersistenceDescriptorModel parsing error: ", e ); throw e; } @Override public void fatalError( SAXParseException e ) throws SAXException { logger.error( "PersistenceDescriptorModel parsing error: ", e ); throw e; } } ); validator.validate( new DOMSource( document ) ); } DOM2PersistenceDescriptorVisitor visitor = new DOM2PersistenceDescriptorVisitor( document ); return visitor.visit(); }  static PersistenceDescriptorModel fromXML( InputStream xmlStream, boolean validate ); static String toXML( PersistenceDescriptorModel persistenceDescriptor ); static void toXML( PersistenceDescriptorModel persistenceDescriptor, OutputStream outputStream ); static final String PERSISTENCE; static final String VERSION; static final String PERSISTENCE_UNIT; static final String NAME; static final String VALUE; static final String TRANSACTION_TYPE; static final String DESCRIPTION; static final String PROVIDER; static final String JTA_DATA_SOURCE; static final String NON_JTA_DATA_SOURCE; static final String MAPPING_FILE; static final String JAR_FILE; static final String CLASS; static final String EXCLUDE_UNLISTED_CLASSES; static final String SHARED_CACHE_MODE; static final String VALIDATION_MODE; static final String PROPERTIES; static final String PROPERTY; }