61
61
import org .hibernate .metamodel .source .internal .jaxb .JaxbMappedSuperclass ;
62
62
import org .hibernate .metamodel .source .internal .jaxb .JaxbPersistenceUnitDefaults ;
63
63
import org .hibernate .metamodel .source .internal .jaxb .JaxbPersistenceUnitMetadata ;
64
- import org .hibernate .metamodel .source .spi .InvalidMappingException ;
65
64
import org .hibernate .metamodel .source .spi .MappingException ;
66
65
import org .hibernate .metamodel .source .spi .MappingNotFoundException ;
66
+ import org .hibernate .metamodel .spi .ClassLoaderAccess ;
67
67
import org .hibernate .service .ServiceRegistry ;
68
68
import org .hibernate .type .SerializationException ;
69
69
import org .hibernate .xml .internal .jaxb .UnifiedMappingBinder ;
@@ -86,16 +86,13 @@ public class MetadataSources {
86
86
private static final CoreMessageLogger LOG = CoreLogging .messageLogger ( MetadataSources .class );
87
87
88
88
private final ServiceRegistry serviceRegistry ;
89
- private final UnifiedMappingBinder jaxbProcessor ;
90
89
private List <BindResult > bindResultList = new ArrayList <BindResult >();
91
90
private LinkedHashSet <Class <?>> annotatedClasses = new LinkedHashSet <Class <?>>();
92
91
private LinkedHashSet <String > annotatedClassNames = new LinkedHashSet <String >();
93
92
private LinkedHashSet <String > annotatedPackages = new LinkedHashSet <String >();
94
93
95
94
private List <Class <? extends AttributeConverter >> converterClasses ;
96
95
97
- private boolean hasOrmXmlJaxbRoots ;
98
-
99
96
public MetadataSources () {
100
97
this ( new BootstrapServiceRegistryBuilder ().build () );
101
98
}
@@ -115,13 +112,19 @@ public MetadataSources(ServiceRegistry serviceRegistry) {
115
112
);
116
113
}
117
114
this .serviceRegistry = serviceRegistry ;
118
- this .jaxbProcessor = new UnifiedMappingBinder ();
119
115
}
120
116
121
117
protected static boolean isExpectedServiceRegistryType (ServiceRegistry serviceRegistry ) {
122
118
return BootstrapServiceRegistry .class .isInstance ( serviceRegistry )
123
119
|| StandardServiceRegistry .class .isInstance ( serviceRegistry );
124
120
}
121
+
122
+ public void buildBindResults (ClassLoaderAccess classLoaderAccess ) {
123
+ final UnifiedMappingBinder jaxbProcessor = new UnifiedMappingBinder ( classLoaderAccess );
124
+ for ( BindResult bindResult : bindResultList ) {
125
+ bindResult .bind ( jaxbProcessor );
126
+ }
127
+ }
125
128
126
129
public List <BindResult > getBindResultList () {
127
130
return bindResultList ;
@@ -243,24 +246,9 @@ private ClassLoaderService classLoaderService() {
243
246
}
244
247
245
248
private BindResult add (InputStream inputStream , Origin origin , boolean close ) {
246
- try {
247
- BindResult bindResult = new BindResult ( jaxbProcessor .bind ( inputStream , origin ), origin );
248
- addJaxbRoot ( bindResult );
249
- return bindResult ;
250
- }
251
- catch ( Exception e ) {
252
- throw new InvalidMappingException ( origin , e );
253
- }
254
- finally {
255
- if ( close ) {
256
- try {
257
- inputStream .close ();
258
- }
259
- catch ( IOException ignore ) {
260
- LOG .trace ( "Was unable to close input stream" );
261
- }
262
- }
263
- }
249
+ BindResult bindResult = new BindResult ( inputStream , origin , close );
250
+ bindResultList .add ( bindResult );
251
+ return bindResult ;
264
252
}
265
253
266
254
/**
@@ -419,7 +407,7 @@ public MetadataSources addCacheableFileStrictly(File file) throws SerializationE
419
407
}
420
408
421
409
LOG .readingCachedMappings ( cachedFile );
422
- addJaxbRoot ( (BindResult ) SerializationHelper .deserialize ( new FileInputStream ( cachedFile ) ) );
410
+ bindResultList . add ( (BindResult ) SerializationHelper .deserialize ( new FileInputStream ( cachedFile ) ) );
423
411
return this ;
424
412
}
425
413
@@ -470,16 +458,10 @@ public MetadataSources addURL(URL url) {
470
458
@ Deprecated
471
459
public MetadataSources addDocument (Document document ) {
472
460
final Origin origin = new Origin ( SourceType .DOM , Origin .UNKNOWN_FILE_PATH );
473
- BindResult bindResult = new BindResult ( jaxbProcessor .bind ( new DOMSource ( document ), origin ), origin );
474
- addJaxbRoot ( bindResult );
461
+ bindResultList .add ( new BindResult ( new DOMSource ( document ), origin ) );
475
462
return this ;
476
463
}
477
464
478
- private void addJaxbRoot (BindResult bindResult ) {
479
- hasOrmXmlJaxbRoots = hasOrmXmlJaxbRoots || JaxbEntityMappings .class .isInstance ( bindResult .getRoot () );
480
- bindResultList .add ( bindResult );
481
- }
482
-
483
465
/**
484
466
* Read all mappings from a jar file.
485
467
* <p/>
0 commit comments