@Override public Binding bind(Source source, Origin origin) { final XMLEventReader eventReader = createReader( source, origin ); return doBind( eventReader, origin ); }
private XMLInputFactory staxFactory() { if ( staxFactory == null ) { staxFactory = buildStaxFactory(); } return staxFactory; }
@SuppressWarnings("unchecked") protected <T> T jaxb(XMLEventReader reader, Schema xsd, JAXBContext jaxbContext, Origin origin) { final ContextProvidingValidationEventHandler handler = new ContextProvidingValidationEventHandler(); try { final Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); if ( isValidationEnabled() ) { unmarshaller.setSchema( xsd ); } else { unmarshaller.setSchema( null ); } unmarshaller.setEventHandler( handler ); return (T) unmarshaller.unmarshal( reader ); } catch ( JAXBException e ) { throw new MappingException( "Unable to perform unmarshalling at line number " + handler.getLineNumber() + " and column " + handler.getColumnNumber() + ". Message: " + handler.getMessage(), e, origin ); } }
public static void createSerFile(File xmlFile, Binder binder) { final Origin origin = new Origin( SourceType.FILE, xmlFile.getAbsolutePath() ); writeSerFile( FileXmlSource.doBind( binder, xmlFile, origin ), xmlFile, determineCachedFile( xmlFile ) ); }
protected XMLEventReader createReader(InputStream stream, Origin origin) { try { // create a standard StAX reader final XMLEventReader staxReader = staxFactory().createXMLEventReader( stream ); // and wrap it in a buffered reader (keeping 100 element sized buffer) return new BufferedXMLEventReader( staxReader, 100 ); } catch ( XMLStreamException e ) { throw new MappingException( "Unable to create stax reader", e, origin ); } }
@Override public Binding doBind(Binder binder) { try { InputStream stream = url.openStream(); return InputStreamXmlSource.doBind( binder, stream, getOrigin(), true ); } catch (UnknownHostException e) { throw new MappingNotFoundException( "Invalid URL", e, getOrigin() ); } catch (IOException e) { throw new MappingException( "Unable to open URL InputStream", e, getOrigin() ); } } }
private Binding doBind(XMLEventReader eventReader, Origin origin) { try { final StartElement rootElementStartEvent = seekRootElementStartEvent( eventReader, origin ); return doBind( eventReader, rootElementStartEvent, origin ); } finally { try { eventReader.close(); } catch ( Exception e ) { log.debug( "Unable to close StAX reader", e ); } } }
@Override public Binding doBind(Binder binder) { final InputStream stream; try { stream = jarFile.getInputStream( jarFileEntry ); } catch (IOException e) { throw new MappingException( String.format( "Unable to open InputStream for jar file entry [%s : %s]", jarFile.getName(), jarFileEntry.getName() ), e, getOrigin() ); } return InputStreamXmlSource.doBind( binder, stream, getOrigin(), true ); } }
private void addCacheableFile(Origin origin, File file) { xmlBindings.add( new CacheableFileXmlSource( origin, file, false ).doBind( getXmlMappingBinderAccess().getMappingBinder() ) ); }
public Binding bind(InputStream xmlInputStream) { LOG.tracef( "reading mappings from InputStream" ); final Origin origin = new Origin( SourceType.INPUT_STREAM, null ); return new InputStreamXmlSource( origin, xmlInputStream, false ).doBind( getMappingBinder() ); }
public Binding bind(URL url) { final String urlExternalForm = url.toExternalForm(); LOG.debugf( "Reading mapping document from URL : %s", urlExternalForm ); final Origin origin = new Origin( SourceType.URL, urlExternalForm ); return new UrlXmlSource( origin, url ).doBind( getMappingBinder() ); } }
public Binding bind(File file) { final Origin origin = new Origin( SourceType.FILE, file.getPath() ); LOG.tracef( "reading mappings from file : %s", origin.getName() ); if ( !file.exists() ) { throw new MappingNotFoundException( origin ); } return new FileXmlSource( origin, file ).doBind( getMappingBinder() ); }
private void writeSerFile(Object binding) { writeSerFile( (Serializable) binding, xmlFile, serFile ); }
@Override public Binding doBind(Binder binder) { return binder.bind( jaxpSource, getOrigin() ); } }
public static Binding doBind(Binder binder, File file, Origin origin) { final FileInputStream fis; try { fis = new FileInputStream( file ); } catch ( FileNotFoundException e ) { throw new MappingNotFoundException( e, origin ); } return InputStreamXmlSource.doBind( binder, fis, origin, true ); } }
public XmlMappingBinderAccess(ServiceRegistry serviceRegistry) { this.classLoaderService = serviceRegistry.getService( ClassLoaderService.class ); // NOTE : The boolean here indicates whether or not to perform validation as we load XML documents. // Should we expose this setting? Disabling would speed up JAXP and JAXB at runtime, but potentially // at the cost of less obvious errors when a document is not valid. this.mappingBinder = new MappingBinder( serviceRegistry.getService( ClassLoaderService.class ), true ); }
@Override public Binding bind(InputStream stream, Origin origin) { final XMLEventReader eventReader = createReader( stream, origin ); try { return doBind( eventReader, origin ); } finally { try { eventReader.close(); } catch (XMLStreamException e) { log.debug( "Unable to close StAX reader", e ); } } }
protected XMLEventReader createReader(Source source, Origin origin) { try { // create a standard StAX reader final XMLEventReader staxReader = staxFactory().createXMLEventReader( source ); // and wrap it in a buffered reader (keeping 100 element sized buffer) return new BufferedXMLEventReader( staxReader, 100 ); } catch ( XMLStreamException e ) { throw new MappingException( "Unable to create stax reader", e, origin ); } }