/** * See {@link #addCacheableFile(java.io.File)} for description * * @param path The path to a file. Expected to be resolvable by {@link java.io.File#File(String)} * * @return this (for method chaining purposes) * * @see #addCacheableFile(java.io.File) */ public MetadataSources addCacheableFile(String path) { final Origin origin = new Origin( SourceType.FILE, path ); addCacheableFile( origin, new File( path ) ); return this; }
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() ); }
@Override public String getMessage() { String message = super.getMessage(); if (origin != null) { message += " : origin(" + origin.getName() + ")"; } return message; }
@Override protected Binding doBind( XMLEventReader staxEventReader, StartElement rootElementStartEvent, Origin origin) { final String rootElementLocalName = rootElementStartEvent.getName().getLocalPart(); if ( "hibernate-mapping".equals( rootElementLocalName ) ) { log.debugf( "Performing JAXB binding of hbm.xml document : %s", origin.toString() ); XMLEventReader hbmReader = new HbmEventReader( staxEventReader, xmlEventFactory ); JaxbHbmHibernateMapping hbmBindings = jaxb( hbmReader, MappingXsdSupport.INSTANCE.hbmXsd().getSchema(), hbmJaxbContext(), origin ); return new Binding<>( hbmBindings, origin ); } else { // final XMLEventReader reader = new JpaOrmXmlEventReader( staxEventReader ); // return jaxb( reader, LocalSchema.MAPPING.getSchema(), JaxbEntityMappings.class, origin ); try { final XMLEventReader reader = new JpaOrmXmlEventReader( staxEventReader, xmlEventFactory ); return new Binding<>( toDom4jDocument( reader, origin ), origin ); } catch (JpaOrmXmlEventReader.BadVersionException e) { throw new UnsupportedOrmXsdVersionException( e.getRequestedVersion(), origin ); } } }
public CacheableFileXmlSource(Origin origin, File xmlFile, boolean strict) { super( origin ); this.xmlFile = xmlFile; this.strict = strict; this.serFile = determineCachedFile( xmlFile ); if ( strict ) { if ( !serFile.exists() ) { throw new MappingException( String.format( "Cached file [%s] could not be found", origin.getName() ), origin ); } if ( isSerfileObsolete() ) { throw new MappingException( String.format( "Cached file [%s] could not be used as the mapping file is newer", origin.getName() ), origin ); } } }
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() ); }
"filter-def [name=%s, origin=%s] defined multiple conditions, accepting arbitrary one", jaxbFilterDefinitionMapping.getName(), context.getOrigin().toString() );
/** * Add a cached mapping file. A cached file is a serialized representation of the DOM structure of a * particular mapping. It is saved from a previous call as a file with the name {@code {xmlFile}.bin} * where {@code {xmlFile}} is the name of the original mapping file. * </p> * If a cached {@code {xmlFile}.bin} exists and is newer than {@code {xmlFile}}, the {@code {xmlFile}.bin} * file will be read directly. Otherwise {@code {xmlFile}} is read and then serialized to {@code {xmlFile}.bin} for * use the next time. * * @param file The cacheable mapping file to be added, {@code {xmlFile}} in above discussion. * * @return this (for method chaining purposes) */ public MetadataSources addCacheableFile(File file) { final Origin origin = new Origin( SourceType.FILE, file.getName() ); addCacheableFile( origin, file ); return this; }
@Override protected Binding doBind( XMLEventReader staxEventReader, StartElement rootElementStartEvent, Origin origin) { final String rootElementLocalName = rootElementStartEvent.getName().getLocalPart(); if ( "hibernate-mapping".equals( rootElementLocalName ) ) { log.debugf( "Performing JAXB binding of hbm.xml document : %s", origin.toString() ); XMLEventReader hbmReader = new HbmEventReader( staxEventReader, xmlEventFactory ); JaxbHbmHibernateMapping hbmBindings = jaxb( hbmReader, MappingXsdSupport.INSTANCE.hbmXsd().getSchema(), hbmJaxbContext(), origin ); return new Binding<>( hbmBindings, origin ); } else { // final XMLEventReader reader = new JpaOrmXmlEventReader( staxEventReader ); // return jaxb( reader, LocalSchema.MAPPING.getSchema(), JaxbEntityMappings.class, origin ); try { final XMLEventReader reader = new JpaOrmXmlEventReader( staxEventReader, xmlEventFactory ); return new Binding<>( toDom4jDocument( reader, origin ), origin ); } catch (JpaOrmXmlEventReader.BadVersionException e) { throw new UnsupportedOrmXsdVersionException( e.getRequestedVersion(), origin ); } } }
/** * Read mappings from a DOM {@link org.w3c.dom.Document} * * @param document The DOM document * * @return this (for method chaining purposes) * * @deprecated since 5.0. Use one of the other methods for passing mapping source(s). */ @Deprecated public MetadataSources addDocument(Document document) { final Origin origin = new Origin( SourceType.DOM, Origin.UNKNOWN_FILE_PATH ); xmlBindings.add( new JaxpSourceXmlSource( origin, new DOMSource( document ) ).doBind( getXmlMappingBinderAccess().getMappingBinder() ) ); return this; }
@Override public String getMessage() { String message = super.getMessage(); if (origin != null) { message += " : origin(" + origin.getName() + ")"; } return message; }
"filter-def [name=%s, origin=%s] defined multiple conditions, accepting arbitrary one", jaxbFilterDefinitionMapping.getName(), context.getOrigin().toString() );
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 ) ); }
public CacheableFileXmlSource(Origin origin, File xmlFile, boolean strict) { super( origin ); this.xmlFile = xmlFile; this.strict = strict; this.serFile = determineCachedFile( xmlFile ); if ( strict ) { if ( !serFile.exists() ) { throw new MappingException( String.format( "Cached file [%s] could not be found", origin.getName() ), origin ); } if ( isSerfileObsolete() ) { throw new MappingException( String.format( "Cached file [%s] could not be used as the mapping file is newer", origin.getName() ), origin ); } } }
/** * Constructs an InvalidMappingException using the given information. * * @param customMessage The custom message explaining the exception condition * @param origin The origin of the invalid mapping document */ public InvalidMappingException(String customMessage, Origin origin) { this( customMessage, origin.getType().getLegacyTypeText(), origin.getName() ); }