Skip to content

Commit

Permalink
Fixed misunderstanding with respect to excludeUnlistedClasses default…
Browse files Browse the repository at this point in the history
… in JPA 2.0

Issue: SPR-10767
(cherry picked from commit d0948f1)
  • Loading branch information
jhoeller committed Jul 31, 2013
1 parent 5b4dcbf commit 85c9ed0
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 39 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -39,18 +39,17 @@
* @author Costin Leau
* @author Arjen Poutsma
* @author Luke Taylor
* @since 1.2
* @see org.w3c.dom.Node
* @see org.w3c.dom.Element
* @since 1.2
*/
public abstract class DomUtils {

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

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

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

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

/**
* Retrieve all child elements of the given DOM element
* @param ele the DOM element to analyze
* Retrieves all child elements of the given DOM element
* @param ele the DOM element to analyze
* @return a List of child {@code org.w3c.dom.Element} instances
*/
public static List<Element> getChildElements(Element ele) {
Expand All @@ -138,9 +133,10 @@ public static List<Element> getChildElements(Element ele) {
}

/**
* Extract the text value from the given DOM element, ignoring XML comments. <p>Appends all CharacterData nodes and
* EntityReference nodes into a single String value, excluding Comment nodes.
*
* Extracts the text value from the given DOM element, ignoring XML comments.
* <p>Appends all CharacterData nodes and EntityReference nodes into a single
* String value, excluding Comment nodes. Only exposes actual user-specified
* text, no default values of any kind.
* @see CharacterData
* @see EntityReference
* @see Comment
Expand All @@ -159,8 +155,9 @@ public static String getTextValue(Element valueEle) {
}

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

/**
* Returns a SAX {@code ContentHandler} that transforms callback calls to DOM {@code Node}s.
*
* @param node the node to publish events to
* @return the content handler
*/
public static ContentHandler createContentHandler(Node node) {
return new DomContentHandler(node);
}

/** Matches the given node's name and local name against the given desired name. */
/**
* Matches the given node's name and local name against the given desired name.
*/
private static boolean nodeNameMatch(Node node, String desiredName) {
return (desiredName.equals(node.getNodeName()) || desiredName.equals(node.getLocalName()));
}

/** Matches the given node's name and local name against the given desired names. */
/**
* Matches the given node's name and local name against the given desired names.
*/
private static boolean nodeNameMatch(Node node, Collection desiredNames) {
return (desiredNames.contains(node.getNodeName()) || desiredNames.contains(node.getLocalName()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import java.net.URL;
import java.util.LinkedList;
import java.util.List;

import javax.persistence.SharedCacheMode;
import javax.persistence.ValidationMode;
import javax.persistence.spi.PersistenceUnitTransactionType;
Expand All @@ -35,6 +34,7 @@
import org.w3c.dom.Element;
import org.xml.sax.ErrorHandler;
import org.xml.sax.SAXException;

import org.springframework.core.io.Resource;
import org.springframework.core.io.support.ResourcePatternResolver;
import org.springframework.jdbc.datasource.lookup.DataSourceLookup;
Expand Down Expand Up @@ -83,8 +83,6 @@ class PersistenceUnitReader {

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

private static final String VERSION_1 = "1.0";


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

Expand Down Expand Up @@ -251,7 +249,7 @@ protected SpringPersistenceUnitInfo parsePersistenceUnitInfo(Element persistence
unitInfo.setTransactionType(PersistenceUnitTransactionType.valueOf(txType));
}

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

// exclude unlisted classes
Element excludeUnlistedClasses = DomUtils.getChildElementByTagName(persistenceUnit, EXCLUDE_UNLISTED_CLASSES);
if (excludeUnlistedClasses == null) {
// element is not defined, use default appropriate for version
unitInfo.setExcludeUnlistedClasses(!VERSION_1.equals(version));
}
else {
if (excludeUnlistedClasses != null) {
String excludeText = DomUtils.getTextValue(excludeUnlistedClasses);
unitInfo.setExcludeUnlistedClasses(StringUtils.isEmpty(excludeText) ||
Boolean.valueOf(excludeText));
unitInfo.setExcludeUnlistedClasses(!StringUtils.hasText(excludeText) || Boolean.valueOf(excludeText));
}

// set JPA 2.0 shared cache mode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ public void testJpa2ExcludeUnlisted() throws Exception {
PersistenceUnitInfo noExclude = info[0];
assertNotNull("noExclude should not be null.", noExclude);
assertEquals("noExclude name is not correct.", "NoExcludeElement", noExclude.getPersistenceUnitName());
assertTrue("Exclude unlisted should default true in 2.0.", noExclude.excludeUnlistedClasses());
assertFalse("Exclude unlisted still defaults to false in 2.0.", noExclude.excludeUnlistedClasses());

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

0 comments on commit 85c9ed0

Please sign in to comment.