|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2013 the original author or authors. |
| 2 | + * Copyright 2002-2016 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
51 | 51 | * @author Juergen Hoeller
|
52 | 52 | * @since 2.0
|
53 | 53 | */
|
54 |
| -class PersistenceUnitReader { |
| 54 | +final class PersistenceUnitReader { |
55 | 55 |
|
56 | 56 | private static final String PERSISTENCE_VERSION = "version";
|
57 | 57 |
|
@@ -84,7 +84,7 @@ class PersistenceUnitReader {
|
84 | 84 | private static final String META_INF = "META-INF";
|
85 | 85 |
|
86 | 86 |
|
87 |
| - private final Log logger = LogFactory.getLog(getClass()); |
| 87 | + private static final Log logger = LogFactory.getLog(PersistenceUnitReader.class); |
88 | 88 |
|
89 | 89 | private final ResourcePatternResolver resourcePatternResolver;
|
90 | 90 |
|
@@ -185,47 +185,6 @@ protected List<SpringPersistenceUnitInfo> parseDocument(
|
185 | 185 | return infos;
|
186 | 186 | }
|
187 | 187 |
|
188 |
| - /** |
189 |
| - * Determine the persistence unit root URL based on the given resource |
190 |
| - * (which points to the {@code persistence.xml} file we're reading). |
191 |
| - * @param resource the resource to check |
192 |
| - * @return the corresponding persistence unit root URL |
193 |
| - * @throws IOException if the checking failed |
194 |
| - */ |
195 |
| - protected URL determinePersistenceUnitRootUrl(Resource resource) throws IOException { |
196 |
| - URL originalURL = resource.getURL(); |
197 |
| - |
198 |
| - // If we get an archive, simply return the jar URL (section 6.2 from the JPA spec) |
199 |
| - if (ResourceUtils.isJarURL(originalURL)) { |
200 |
| - return ResourceUtils.extractJarFileURL(originalURL); |
201 |
| - } |
202 |
| - |
203 |
| - // check META-INF folder |
204 |
| - String urlToString = originalURL.toExternalForm(); |
205 |
| - if (!urlToString.contains(META_INF)) { |
206 |
| - if (logger.isInfoEnabled()) { |
207 |
| - logger.info(resource.getFilename() + |
208 |
| - " should be located inside META-INF directory; cannot determine persistence unit root URL for " + |
209 |
| - resource); |
210 |
| - } |
211 |
| - return null; |
212 |
| - } |
213 |
| - if (urlToString.lastIndexOf(META_INF) == urlToString.lastIndexOf('/') - (1 + META_INF.length())) { |
214 |
| - if (logger.isInfoEnabled()) { |
215 |
| - logger.info(resource.getFilename() + |
216 |
| - " is not located in the root of META-INF directory; cannot determine persistence unit root URL for " + |
217 |
| - resource); |
218 |
| - } |
219 |
| - return null; |
220 |
| - } |
221 |
| - |
222 |
| - String persistenceUnitRoot = urlToString.substring(0, urlToString.lastIndexOf(META_INF)); |
223 |
| - if (persistenceUnitRoot.endsWith("/")) { |
224 |
| - persistenceUnitRoot = persistenceUnitRoot.substring(0, persistenceUnitRoot.length() - 1); |
225 |
| - } |
226 |
| - return new URL(persistenceUnitRoot); |
227 |
| - } |
228 |
| - |
229 | 188 | /**
|
230 | 189 | * Parse the unit info DOM element.
|
231 | 190 | */
|
@@ -365,4 +324,46 @@ protected void parseJarFiles(Element persistenceUnit, SpringPersistenceUnitInfo
|
365 | 324 | }
|
366 | 325 | }
|
367 | 326 |
|
| 327 | + |
| 328 | + /** |
| 329 | + * Determine the persistence unit root URL based on the given resource |
| 330 | + * (which points to the {@code persistence.xml} file we're reading). |
| 331 | + * @param resource the resource to check |
| 332 | + * @return the corresponding persistence unit root URL |
| 333 | + * @throws IOException if the checking failed |
| 334 | + */ |
| 335 | + static URL determinePersistenceUnitRootUrl(Resource resource) throws IOException { |
| 336 | + URL originalURL = resource.getURL(); |
| 337 | + |
| 338 | + // If we get an archive, simply return the jar URL (section 6.2 from the JPA spec) |
| 339 | + if (ResourceUtils.isJarURL(originalURL)) { |
| 340 | + return ResourceUtils.extractJarFileURL(originalURL); |
| 341 | + } |
| 342 | + |
| 343 | + // Check META-INF folder |
| 344 | + String urlToString = originalURL.toExternalForm(); |
| 345 | + if (!urlToString.contains(META_INF)) { |
| 346 | + if (logger.isInfoEnabled()) { |
| 347 | + logger.info(resource.getFilename() + |
| 348 | + " should be located inside META-INF directory; cannot determine persistence unit root URL for " + |
| 349 | + resource); |
| 350 | + } |
| 351 | + return null; |
| 352 | + } |
| 353 | + if (urlToString.lastIndexOf(META_INF) == urlToString.lastIndexOf('/') - (1 + META_INF.length())) { |
| 354 | + if (logger.isInfoEnabled()) { |
| 355 | + logger.info(resource.getFilename() + |
| 356 | + " is not located in the root of META-INF directory; cannot determine persistence unit root URL for " + |
| 357 | + resource); |
| 358 | + } |
| 359 | + return null; |
| 360 | + } |
| 361 | + |
| 362 | + String persistenceUnitRoot = urlToString.substring(0, urlToString.lastIndexOf(META_INF)); |
| 363 | + if (persistenceUnitRoot.endsWith("/")) { |
| 364 | + persistenceUnitRoot = persistenceUnitRoot.substring(0, persistenceUnitRoot.length() - 1); |
| 365 | + } |
| 366 | + return new URL(persistenceUnitRoot); |
| 367 | + } |
| 368 | + |
368 | 369 | }
|
0 commit comments