Author: dkulp
Date: Thu Jul 29 21:13:03 2010
New Revision: 980578
URL: http://svn.apache.org/viewvc?rev=980578&view=rev
Log:
Merged revisions 980121 via svnmerge from
https://svn.apache.org/repos/asf/cxf/trunk
........
r980121 | gmazza | 2010-07-28 12:45:27 -0400 (Wed, 28 Jul 2010) | 3 lines
Fix for CXF-2917 (JAXB package naming rules)
........
Modified:
cxf/branches/2.2.x-fixes/ (props changed)
cxf/branches/2.2.x-fixes/common/common/src/main/java/org/apache/cxf/helpers/JavaUtils.java
cxf/branches/2.2.x-fixes/common/common/src/main/java/org/apache/cxf/jaxb/JAXBUtils.java
cxf/branches/2.2.x-fixes/common/common/src/test/java/org/apache/cxf/jaxb/JAXBUtilsTest.java
Propchange: cxf/branches/2.2.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.
Modified:
cxf/branches/2.2.x-fixes/common/common/src/main/java/org/apache/cxf/helpers/JavaUtils.java
URL:
http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/common/common/src/main/java/org/apache/cxf/helpers/JavaUtils.java?rev=980578&r1=980577&r2=980578&view=diff
==============================================================================
---
cxf/branches/2.2.x-fixes/common/common/src/main/java/org/apache/cxf/helpers/JavaUtils.java
(original)
+++
cxf/branches/2.2.x-fixes/common/common/src/main/java/org/apache/cxf/helpers/JavaUtils.java
Thu Jul 29 21:13:03 2010
@@ -30,7 +30,7 @@ public final class JavaUtils {
/**
* These are java keywords as specified at the following URL.
- *
http://java.sun.com/docs/books/jls/second_edition/html/lexical.doc.html#229308
+ * http://java.sun.com/docs/books/jls/third_edition/html/lexical.html#3.9
* Note that false, true, and null are not strictly keywords; they are
* literal values, but for the purposes of this array, they can be treated
* as literals.
Modified:
cxf/branches/2.2.x-fixes/common/common/src/main/java/org/apache/cxf/jaxb/JAXBUtils.java
URL:
http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/common/common/src/main/java/org/apache/cxf/jaxb/JAXBUtils.java?rev=980578&r1=980577&r2=980578&view=diff
==============================================================================
---
cxf/branches/2.2.x-fixes/common/common/src/main/java/org/apache/cxf/jaxb/JAXBUtils.java
(original)
+++
cxf/branches/2.2.x-fixes/common/common/src/main/java/org/apache/cxf/jaxb/JAXBUtils.java
Thu Jul 29 21:13:03 2010
@@ -168,12 +168,13 @@ public final class JAXBUtils {
}
/**
- * Checks if the specified word is a Java keyword (as of 1.5).
+ * Checks if the specified word is a Java keyword (as defined in
JavaUtils).
*
* @param word the word to check.
* @return true if the word is a keyword.
+ * @see org.apache.cxf.helpers.JavaUtils
*/
- public static boolean isJavaKeyword(String word) {
+ protected static boolean isJavaKeyword(String word) {
return JavaUtils.isJavaKeyword(word);
}
@@ -194,7 +195,7 @@ public final class JAXBUtils {
/**
* Generates a Java package name from a URI according to the
- * algorithm outlined in JAXB 2.0.
+ * algorithm outlined in Appendix D of JAXB (2.0+).
*
* @param namespaceURI the namespace URI.
* @return the package name.
@@ -203,13 +204,15 @@ public final class JAXBUtils {
StringBuilder packageName = new StringBuilder();
String authority = uri.getAuthority();
- if (authority == null && "urn".equals(uri.getScheme())) {
+ String scheme = uri.getScheme();
+ if (authority == null && "urn".equals(scheme)) {
authority = uri.getSchemeSpecificPart();
}
if (null != authority && !"".equals(authority)) {
- if ("urn".equals(uri.getScheme())) {
+ if ("urn".equals(scheme)) {
packageName.append(authority);
+ /* JAXB 2.2 D.5.1, Rule #5 */
for (int i = 0; i < packageName.length(); i++) {
if (packageName.charAt(i) == '-') {
packageName.setCharAt(i, '.');
@@ -247,17 +250,29 @@ public final class JAXBUtils {
}
packageName.insert(0, normalizePackageNamePart(token));
}
-
}
+
+ if (!("http".equalsIgnoreCase(scheme) ||
"urn".equalsIgnoreCase(scheme))) {
+ packageName.insert(0, ".");
+ packageName.insert(0, normalizePackageNamePart(scheme));
+ }
+
}
String path = uri.getPath();
if (path == null) {
path = "";
}
+ /* JAXB 2.2 D.5.1 Rule 2 - remove trailing .??, .???, or .html only. */
int index = path.lastIndexOf('.');
if (index < 0) {
index = path.length();
+ } else {
+ String ending = path.substring(index + 1);
+ if (ending.length() < 2 || (ending.length() > 3
+ && !"html".equalsIgnoreCase(ending))) {
+ index = path.length();
+ }
}
StringTokenizer st = new StringTokenizer(path.substring(0, index),
"/");
while (st.hasMoreTokens()) {
@@ -297,7 +312,7 @@ public final class JAXBUtils {
/**
* Converts an XML name to a Java identifier according to the mapping
- * algorithm outlines in the JAXB specification
+ * algorithm outlined in the JAXB specification
*
* @param name the XML name
* @return the Java identifier
Modified:
cxf/branches/2.2.x-fixes/common/common/src/test/java/org/apache/cxf/jaxb/JAXBUtilsTest.java
URL:
http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/common/common/src/test/java/org/apache/cxf/jaxb/JAXBUtilsTest.java?rev=980578&r1=980577&r2=980578&view=diff
==============================================================================
---
cxf/branches/2.2.x-fixes/common/common/src/test/java/org/apache/cxf/jaxb/JAXBUtilsTest.java
(original)
+++
cxf/branches/2.2.x-fixes/common/common/src/test/java/org/apache/cxf/jaxb/JAXBUtilsTest.java
Thu Jul 29 21:13:03 2010
@@ -37,18 +37,42 @@ public class JAXBUtilsTest extends Asser
public void testPackageNames() {
assertEquals("org.apache.cxf.configuration.types",
JAXBUtils.namespaceURIToPackage("http://cxf.apache.org/configuration/types"));
+
+ // tests of JAXB 2.2 Appendix D.5.1, Rule #1: schemes to be removed
are just http and urn
+ assertEquals("auto.org.apache.cxf.configuration.types",
+
JAXBUtils.namespaceURIToPackage("auto://cxf.apache.org/configuration/types"));
+ assertEquals("mouse.org.apache.cxf.configuration.types",
+
JAXBUtils.namespaceURIToPackage("mouse://cxf.apache.org/configuration/types"));
+ assertEquals("h.org.apache.cxf.configuration.types",
+
JAXBUtils.namespaceURIToPackage("h://cxf.apache.org/configuration/types"));
+
+ // tests of JAXB 2.2 Appendix D.5.1, Rule #2: file type is one of .??
or .??? or .html
+ assertEquals("org.apache.cxf.configuration.types_h",
+
JAXBUtils.namespaceURIToPackage("http://cxf.apache.org/configuration/types.h"));
+ assertEquals("org.apache.cxf.configuration.types",
+
JAXBUtils.namespaceURIToPackage("http://cxf.apache.org/configuration/types.hi"));
+ assertEquals("org.apache.cxf.configuration.types",
+
JAXBUtils.namespaceURIToPackage("http://cxf.apache.org/configuration/types.xsd"));
assertEquals("org.apache.cxf.configuration.types",
-
JAXBUtils.namespaceURIToPackage("http://cxf.apache.org/configuration/types.xsd"));
+
JAXBUtils.namespaceURIToPackage("http://cxf.apache.org/configuration/types.html"));
+ assertEquals("org.apache.cxf.configuration.types_auto",
+
JAXBUtils.namespaceURIToPackage("http://cxf.apache.org/configuration/types.auto"));
+ assertEquals("org.apache.cxf.configuration.types_mouse",
+
JAXBUtils.namespaceURIToPackage("http://cxf.apache.org/configuration/types.mouse"));
+
+ // other tests
+ assertEquals("https.com.mytech.rosette_analysis",
+
JAXBUtils.namespaceURIToPackage("https://mytech.com/rosette.analysis"));
+ assertEquals("org.apache.cxf.config._4types_",
+
JAXBUtils.namespaceURIToPackage("http://cxf.apache.org/config/4types."));
assertEquals("org.apache.cxf.config_types",
JAXBUtils.namespaceURIToPackage("http://cxf.apache.org/config-types"));
assertEquals("org.apache.cxf._default.types",
JAXBUtils.namespaceURIToPackage("http://cxf.apache.org/default/types"));
- assertEquals("org.apache.cxf.config._4types",
-
JAXBUtils.namespaceURIToPackage("http://cxf.apache.org/config/4types."));
- assertEquals("com.iona.configuration.types",
-
JAXBUtils.namespaceURIToPackage("http://www.iona.com/configuration/types"));
+ assertEquals("com.progress.configuration.types",
+
JAXBUtils.namespaceURIToPackage("http://www.progress.com/configuration/types"));
assertEquals("org.apache.cxf.config.types",
-
JAXBUtils.namespaceURIToPackage("urn://cxf-apache-org/config/types"));
+
JAXBUtils.namespaceURIToPackage("urn:cxf-apache-org:config:types"));
assertEquals("types", JAXBUtils.namespaceURIToPackage("types"));
}