cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject [2/4] cxf git commit: [CXF-7165] Fix mapping of XML names containing _ to class names
Date Wed, 02 Aug 2017 16:45:26 GMT
[CXF-7165] Fix mapping of XML names containing _ to class names


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/e899c32e
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/e899c32e
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/e899c32e

Branch: refs/heads/3.1.x-fixes
Commit: e899c32e0cd342b7b6f2a965d5c5f3dc8dfd6b9c
Parents: a907531
Author: Daniel Kulp <dkulp@apache.org>
Authored: Tue Aug 1 16:30:45 2017 -0400
Committer: Daniel Kulp <dkulp@apache.org>
Committed: Wed Aug 2 12:44:52 2017 -0400

----------------------------------------------------------------------
 core/src/main/java/org/apache/cxf/common/jaxb/JAXBUtils.java | 8 ++++++--
 .../src/test/java/org/apache/cxf/jaxb/JAXBUtilsTest.java     | 6 +++++-
 2 files changed, 11 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/e899c32e/core/src/main/java/org/apache/cxf/common/jaxb/JAXBUtils.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/cxf/common/jaxb/JAXBUtils.java b/core/src/main/java/org/apache/cxf/common/jaxb/JAXBUtils.java
index 46d0db0..0ffcac6 100644
--- a/core/src/main/java/org/apache/cxf/common/jaxb/JAXBUtils.java
+++ b/core/src/main/java/org/apache/cxf/common/jaxb/JAXBUtils.java
@@ -403,10 +403,12 @@ public final class JAXBUtils {
 
         boolean legalIdentifier = false;
         StringBuilder buf = new StringBuilder(name);
+        boolean hasUnderscore = false;
         legalIdentifier = Character.isJavaIdentifierStart(buf.charAt(0));
 
         for (int i = 1; i < name.length() && legalIdentifier; i++) {
-            legalIdentifier = legalIdentifier && Character.isJavaIdentifierPart(buf.charAt(i));
+            legalIdentifier &= Character.isJavaIdentifierPart(buf.charAt(i));
+            hasUnderscore |= '_' == buf.charAt(i);
         }
         
         boolean conventionalIdentifier = isConventionalIdentifier(buf, type); 
@@ -414,7 +416,9 @@ public final class JAXBUtils {
             if (JAXBUtils.isJavaKeyword(name) && type == IdentifierType.VARIABLE)
{
                 name = normalizePackageNamePart(name);
             }
-            return name;
+            if (!hasUnderscore || IdentifierType.CLASS != type) {
+                return name;
+            }
         }
         
         // split into words 

http://git-wip-us.apache.org/repos/asf/cxf/blob/e899c32e/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/JAXBUtilsTest.java
----------------------------------------------------------------------
diff --git a/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/JAXBUtilsTest.java b/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/JAXBUtilsTest.java
index 62f9070..e4c3254 100644
--- a/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/JAXBUtilsTest.java
+++ b/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/JAXBUtilsTest.java
@@ -89,7 +89,7 @@ public class JAXBUtilsTest extends Assert {
     
     @Test
     public void testNameToIdentifier() {
-        assertEquals("_return", 
+        assertEquals("_return",
                      JAXBUtils.nameToIdentifier("return", JAXBUtils.IdentifierType.VARIABLE));
         assertEquals("getReturn", 
                      JAXBUtils.nameToIdentifier("return", JAXBUtils.IdentifierType.GETTER));
@@ -146,6 +146,10 @@ public class JAXBUtilsTest extends Assert {
                      JAXBUtils.nameToIdentifier("other_punct-chars", JAXBUtils.IdentifierType.GETTER));
         assertEquals("OTHER_PUNCT_CHARS", 
                      JAXBUtils.nameToIdentifier("other_punct-chars", JAXBUtils.IdentifierType.CONSTANT));
+        
+        assertEquals("XMLTransfer",
+                     JAXBUtils.nameToIdentifier("XMLTransfer", JAXBUtils.IdentifierType.CLASS));
+
     }
     
     @Test


Mime
View raw message