Skip to content

Commit 85c9ed0

Browse files
committed
Fixed misunderstanding with respect to excludeUnlistedClasses default in JPA 2.0
Issue: SPR-10767 (cherry picked from commit d0948f1)
1 parent 5b4dcbf commit 85c9ed0

File tree

3 files changed

+32
-39
lines changed

3 files changed

+32
-39
lines changed

spring-core/src/main/java/org/springframework/util/xml/DomUtils.java

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2013 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -39,18 +39,17 @@
3939
* @author Costin Leau
4040
* @author Arjen Poutsma
4141
* @author Luke Taylor
42+
* @since 1.2
4243
* @see org.w3c.dom.Node
4344
* @see org.w3c.dom.Element
44-
* @since 1.2
4545
*/
4646
public abstract class DomUtils {
4747

4848
/**
49-
* Retrieve all child elements of the given DOM element that match any of the given element names. Only look at the
50-
* direct child level of the given element; do not go into further depth (in contrast to the DOM API's
51-
* {@code getElementsByTagName} method).
52-
*
53-
* @param ele the DOM element to analyze
49+
* Retrieves all child elements of the given DOM element that match any of the given element names.
50+
* Only looks at the direct child level of the given element; do not go into further depth
51+
* (in contrast to the DOM API's {@code getElementsByTagName} method).
52+
* @param ele the DOM element to analyze
5453
* @param childEleNames the child element names to look for
5554
* @return a List of child {@code org.w3c.dom.Element} instances
5655
* @see org.w3c.dom.Element
@@ -72,11 +71,10 @@ public static List<Element> getChildElementsByTagName(Element ele, String[] chil
7271
}
7372

7473
/**
75-
* Retrieve all child elements of the given DOM element that match the given element name. Only look at the direct
76-
* child level of the given element; do not go into further depth (in contrast to the DOM API's
77-
* {@code getElementsByTagName} method).
78-
*
79-
* @param ele the DOM element to analyze
74+
* Retrieves all child elements of the given DOM element that match the given element name.
75+
* Only look at the direct child level of the given element; do not go into further depth
76+
* (in contrast to the DOM API's {@code getElementsByTagName} method).
77+
* @param ele the DOM element to analyze
8078
* @param childEleName the child element name to look for
8179
* @return a List of child {@code org.w3c.dom.Element} instances
8280
* @see org.w3c.dom.Element
@@ -88,8 +86,7 @@ public static List<Element> getChildElementsByTagName(Element ele, String childE
8886

8987
/**
9088
* Utility method that returns the first child element identified by its name.
91-
*
92-
* @param ele the DOM element to analyze
89+
* @param ele the DOM element to analyze
9390
* @param childEleName the child element name to look for
9491
* @return the {@code org.w3c.dom.Element} instance, or {@code null} if none found
9592
*/
@@ -108,8 +105,7 @@ public static Element getChildElementByTagName(Element ele, String childEleName)
108105

109106
/**
110107
* Utility method that returns the first child element value identified by its name.
111-
*
112-
* @param ele the DOM element to analyze
108+
* @param ele the DOM element to analyze
113109
* @param childEleName the child element name to look for
114110
* @return the extracted text value, or {@code null} if no child element found
115111
*/
@@ -119,9 +115,8 @@ public static String getChildElementValueByTagName(Element ele, String childEleN
119115
}
120116

121117
/**
122-
* Retrieve all child elements of the given DOM element
123-
124-
* @param ele the DOM element to analyze
118+
* Retrieves all child elements of the given DOM element
119+
* @param ele the DOM element to analyze
125120
* @return a List of child {@code org.w3c.dom.Element} instances
126121
*/
127122
public static List<Element> getChildElements(Element ele) {
@@ -138,9 +133,10 @@ public static List<Element> getChildElements(Element ele) {
138133
}
139134

140135
/**
141-
* Extract the text value from the given DOM element, ignoring XML comments. <p>Appends all CharacterData nodes and
142-
* EntityReference nodes into a single String value, excluding Comment nodes.
143-
*
136+
* Extracts the text value from the given DOM element, ignoring XML comments.
137+
* <p>Appends all CharacterData nodes and EntityReference nodes into a single
138+
* String value, excluding Comment nodes. Only exposes actual user-specified
139+
* text, no default values of any kind.
144140
* @see CharacterData
145141
* @see EntityReference
146142
* @see Comment
@@ -159,8 +155,9 @@ public static String getTextValue(Element valueEle) {
159155
}
160156

161157
/**
162-
* Namespace-aware equals comparison. Returns {@code true} if either {@link Node#getLocalName} or {@link
163-
* Node#getNodeName} equals {@code desiredName}, otherwise returns {@code false}.
158+
* Namespace-aware equals comparison. Returns {@code true} if either
159+
* {@link Node#getLocalName} or {@link Node#getNodeName} equals
160+
* {@code desiredName}, otherwise returns {@code false}.
164161
*/
165162
public static boolean nodeNameEquals(Node node, String desiredName) {
166163
Assert.notNull(node, "Node must not be null");
@@ -170,20 +167,23 @@ public static boolean nodeNameEquals(Node node, String desiredName) {
170167

171168
/**
172169
* Returns a SAX {@code ContentHandler} that transforms callback calls to DOM {@code Node}s.
173-
*
174170
* @param node the node to publish events to
175171
* @return the content handler
176172
*/
177173
public static ContentHandler createContentHandler(Node node) {
178174
return new DomContentHandler(node);
179175
}
180176

181-
/** Matches the given node's name and local name against the given desired name. */
177+
/**
178+
* Matches the given node's name and local name against the given desired name.
179+
*/
182180
private static boolean nodeNameMatch(Node node, String desiredName) {
183181
return (desiredName.equals(node.getNodeName()) || desiredName.equals(node.getLocalName()));
184182
}
185183

186-
/** Matches the given node's name and local name against the given desired names. */
184+
/**
185+
* Matches the given node's name and local name against the given desired names.
186+
*/
187187
private static boolean nodeNameMatch(Node node, Collection desiredNames) {
188188
return (desiredNames.contains(node.getNodeName()) || desiredNames.contains(node.getLocalName()));
189189
}

spring-orm/src/main/java/org/springframework/orm/jpa/persistenceunit/PersistenceUnitReader.java

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import java.net.URL;
2222
import java.util.LinkedList;
2323
import java.util.List;
24-
2524
import javax.persistence.SharedCacheMode;
2625
import javax.persistence.ValidationMode;
2726
import javax.persistence.spi.PersistenceUnitTransactionType;
@@ -35,6 +34,7 @@
3534
import org.w3c.dom.Element;
3635
import org.xml.sax.ErrorHandler;
3736
import org.xml.sax.SAXException;
37+
3838
import org.springframework.core.io.Resource;
3939
import org.springframework.core.io.support.ResourcePatternResolver;
4040
import org.springframework.jdbc.datasource.lookup.DataSourceLookup;
@@ -83,8 +83,6 @@ class PersistenceUnitReader {
8383

8484
private static final String META_INF = "META-INF";
8585

86-
private static final String VERSION_1 = "1.0";
87-
8886

8987
private final Log logger = LogFactory.getLog(getClass());
9088

@@ -251,7 +249,7 @@ protected SpringPersistenceUnitInfo parsePersistenceUnitInfo(Element persistence
251249
unitInfo.setTransactionType(PersistenceUnitTransactionType.valueOf(txType));
252250
}
253251

254-
// data-source
252+
// evaluate data sources
255253
String jtaDataSource = DomUtils.getChildElementValueByTagName(persistenceUnit, JTA_DATA_SOURCE);
256254
if (StringUtils.hasText(jtaDataSource)) {
257255
unitInfo.setJtaDataSource(this.dataSourceLookup.getDataSource(jtaDataSource.trim()));
@@ -270,14 +268,9 @@ protected SpringPersistenceUnitInfo parsePersistenceUnitInfo(Element persistence
270268

271269
// exclude unlisted classes
272270
Element excludeUnlistedClasses = DomUtils.getChildElementByTagName(persistenceUnit, EXCLUDE_UNLISTED_CLASSES);
273-
if (excludeUnlistedClasses == null) {
274-
// element is not defined, use default appropriate for version
275-
unitInfo.setExcludeUnlistedClasses(!VERSION_1.equals(version));
276-
}
277-
else {
271+
if (excludeUnlistedClasses != null) {
278272
String excludeText = DomUtils.getTextValue(excludeUnlistedClasses);
279-
unitInfo.setExcludeUnlistedClasses(StringUtils.isEmpty(excludeText) ||
280-
Boolean.valueOf(excludeText));
273+
unitInfo.setExcludeUnlistedClasses(!StringUtils.hasText(excludeText) || Boolean.valueOf(excludeText));
281274
}
282275

283276
// set JPA 2.0 shared cache mode

spring-orm/src/test/java/org/springframework/orm/jpa/persistenceunit/PersistenceXmlParsingTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ public void testJpa2ExcludeUnlisted() throws Exception {
351351
PersistenceUnitInfo noExclude = info[0];
352352
assertNotNull("noExclude should not be null.", noExclude);
353353
assertEquals("noExclude name is not correct.", "NoExcludeElement", noExclude.getPersistenceUnitName());
354-
assertTrue("Exclude unlisted should default true in 2.0.", noExclude.excludeUnlistedClasses());
354+
assertFalse("Exclude unlisted still defaults to false in 2.0.", noExclude.excludeUnlistedClasses());
355355

356356
PersistenceUnitInfo emptyExclude = info[1];
357357
assertNotNull("emptyExclude should not be null.", emptyExclude);

0 commit comments

Comments
 (0)