You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@bval.apache.org by dw...@apache.org on 2010/05/20 17:55:44 UTC
svn commit: r946678 -
/incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/xml/ValidationParser.java
Author: dwoods
Date: Thu May 20 15:55:44 2010
New Revision: 946678
URL: http://svn.apache.org/viewvc?rev=946678&view=rev
Log:
BVAL-52 ValidationParser.getInputStream() should call getResourceAsStream() for TCK suite to work. Contributed by Carlos Vara.
Modified:
incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/xml/ValidationParser.java
Modified: incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/xml/ValidationParser.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/xml/ValidationParser.java?rev=946678&r1=946677&r2=946678&view=diff
==============================================================================
--- incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/xml/ValidationParser.java (original)
+++ incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/xml/ValidationParser.java Thu May 20 15:55:44 2010
@@ -102,19 +102,20 @@ public class ValidationParser {
private InputStream getInputStream(String path) throws IOException {
ClassLoader loader = PrivilegedActions.getClassLoader(getClass());
- Enumeration<URL> urls = loader.getResources(path);
- if (urls.hasMoreElements()) {
- URL url = urls.nextElement();
- if (urls.hasMoreElements()) {
- // spec says: If more than one META-INF/validation.xml file
- // is found in the classpath, a ValidationException is raised.
- throw new ValidationException(
- "More than one " + path + " is found in the classpath");
+ InputStream inputStream = loader.getResourceAsStream( path );
+
+ if ( inputStream != null ) {
+ // spec says: If more than one META-INF/validation.xml file
+ // is found in the classpath, a ValidationException is raised.
+ if ( path.equals("META-INF/validation.xml") ) {
+ Enumeration<URL> urls = loader.getResources(path);
+ if ( urls.hasMoreElements() && (urls.nextElement() != null) && urls.hasMoreElements() ) {
+ throw new ValidationException("More than one " + path + " is found in the classpath");
+ }
}
- return url.openStream();
- } else {
- return null;
}
+
+ return inputStream;
}
private Schema getSchema() {
@@ -204,22 +205,27 @@ public class ValidationParser {
private void applyMappingStreams(ValidationConfigType xmlConfig,
ConfigurationImpl target) {
- for (JAXBElement<String> mappingFileName : xmlConfig.getConstraintMapping()) {
+ for (JAXBElement<String> mappingFileNameElement : xmlConfig.getConstraintMapping()) {
+ String mappingFileName = mappingFileNameElement.getValue();
+ if ( mappingFileName.startsWith("/") ) {
+ // Classloader needs a path without a starting /
+ mappingFileName = mappingFileName.substring(1);
+ }
if (log.isDebugEnabled()) {
log.debug(
- "Trying to open input stream for " + mappingFileName.getValue());
+ "Trying to open input stream for " + mappingFileName);
}
InputStream in = null;
try {
- in = getInputStream(mappingFileName.getValue());
+ in = getInputStream(mappingFileName);
if (in == null) {
throw new ValidationException(
"Unable to open input stream for mapping file " +
- mappingFileName.getValue());
+ mappingFileName);
}
} catch (IOException e) {
throw new ValidationException("Unable to open input stream for mapping file " +
- mappingFileName.getValue(), e);
+ mappingFileName, e);
}
target.addMapping(in);
}