/** * 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() ); }
@Override public int hashCode() { int result = type != null ? type.hashCode() : 0; result = 31 * result + ( name != null ? name.hashCode() : 0 ); return result; }
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() ); }
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 ); } } }
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() ); } }
/** * <b>INTENDED FOR TESTSUITE USE ONLY!</b> * <p/> * Much like {@link #addCacheableFile(java.io.File)} except that here we will fail immediately if * the cache version cannot be found or used for whatever reason * * @param file The xml file, not the bin! * * @return The dom "deserialized" from the cached file. * * @throws org.hibernate.type.SerializationException Indicates a problem deserializing the cached dom tree * @throws java.io.FileNotFoundException Indicates that the cached file was not found or was not usable. */ public MetadataSources addCacheableFileStrictly(File file) throws SerializationException, FileNotFoundException { final Origin origin = new Origin( SourceType.FILE, file.getAbsolutePath() ); xmlBindings.add( new CacheableFileXmlSource( origin, file, true ).doBind( getXmlMappingBinderAccess().getMappingBinder() ) ); return this; }
/** * 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; }
/** * 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 InvalidMappingException(Origin origin, Throwable e) { super( String.format( "Could not parse mapping document: %s (%s)", origin.getName(), origin.getType() ), origin.getType().getLegacyTypeText(), origin.getName(), e ); this.origin = origin; }
public Binding bind(InputStreamAccess xmlInputStreamAccess) { LOG.tracef( "reading mappings from InputStreamAccess : %s", xmlInputStreamAccess.getStreamName() ); final Origin origin = new Origin( SourceType.INPUT_STREAM, xmlInputStreamAccess.getStreamName() ); InputStream xmlInputStream = xmlInputStreamAccess.accessInputStream(); try { return new InputStreamXmlSource( origin, xmlInputStream, false ).doBind( mappingBinder ); } finally { try { xmlInputStream.close(); } catch (IOException e) { LOG.debugf( "Unable to close InputStream obtained from InputStreamAccess : " + xmlInputStreamAccess.getStreamName() ); } } }
public Binding bind(String resource) { LOG.tracef( "reading mappings from resource : %s", resource ); final Origin origin = new Origin( SourceType.RESOURCE, resource ); final URL url = classLoaderService.locateResource( resource ); if ( url == null ) { throw new MappingNotFoundException( origin ); } return new UrlXmlSource( origin, url ).doBind( getMappingBinder() ); }
/** * 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; }
public LoadedConfig loadConfigXmlFile(File cfgXmlFile) { try { final JaxbCfgHibernateConfiguration jaxbCfg = jaxbProcessorHolder.getValue().unmarshal( new FileInputStream( cfgXmlFile ), new Origin( SourceType.FILE, cfgXmlFile.getAbsolutePath() ) ); return LoadedConfig.consume( jaxbCfg ); } catch (FileNotFoundException e) { throw new ConfigurationException( "Specified cfg.xml file [" + cfgXmlFile.getAbsolutePath() + "] does not exist" ); } }
public LoadedConfig loadConfigXmlResource(String cfgXmlResourceName) { final InputStream stream = bootstrapServiceRegistry.getService( ClassLoaderService.class ).locateResourceStream( cfgXmlResourceName ); if ( stream == null ) { throw new ConfigurationException( "Could not locate cfg.xml resource [" + cfgXmlResourceName + "]" ); } try { final JaxbCfgHibernateConfiguration jaxbCfg = jaxbProcessorHolder.getValue().unmarshal( stream, new Origin( SourceType.RESOURCE, cfgXmlResourceName ) ); return LoadedConfig.consume( jaxbCfg ); } finally { try { stream.close(); } catch (IOException e) { log.debug( "Unable to close cfg.xml resource stream", e ); } } }