dev@jaxb.java.net

Namespace with # not getting replaced to _ in 2.2 as it was in 2.1

From: jayashree viswanathan <jviswana_at_linux.vnet.ibm.com>
Date: Wed, 07 Mar 2012 15:28:19 +0530

Hi,

If the namespace has '#' in it, JAXB RI 2,1 used to convert it to "",
but in 2,2 it is just removing and replace to "" is not happening.

Testcase:

You can reproduce by compiling the following schema with XJC:

<?xml version='1.0' encoding='UTF-8'?>
<xs:schema targetNamespace='http://example.com/abc#'
xmlns:xs='http://www.w3.org/2001/XMLSchema'>
<xs:complexType name='exampleType'>
<xs:sequence>
<xs:element name='aString' type='xs:string'/>
</xs:sequence>
</xs:complexType>
</xs:schema>

Output from JAXB 2.1 tools:
D:\schemas\example>xjc example.xsd
parsing a schema...
compiling a schema...
com\example\abc_\ExampleType.java
com\example\abc_\ObjectFactory.java
com\example\abc_\package-info.java

Output from JAXB 2.2 tools:
D:\schemas\example>xjc example.xsd
parsing a schema...
compiling a schema...
com\example\abc\ExampleType.java
com\example\abc\ObjectFactory.java
com\example\abc\package-info.java

Notice that the underscore '_' was removed from the package name.

SPEC
----
Here is what SPEC talks about handling namespaces in such a scenario.
  From Section D.5.1 Mapping from a Namespace URI
"
a. If the sting component contains a hyphen, or any other special
character not allowed in an identifier, convert it into an underscore.
b. If any of the resulting package name components are keywords then
append underscore to them.
c. If any of the resulting package name components start with a digit, or
any other character that is not allowed as an initial character of an
identifier, have an underscore prefixed to the component.
"
Problem Analysis:
Upon analysis, Identified that the problem is because of Issue 709. 
http://java.net/jira/browse/JAXB-709 , Core problem as described in the link
"com.sun.istack.SAXParseException2: The package name 
'org.etsi.uri.trstsvc.svcinfoext.esigdir_1999_93_ec_trustedlist.__#' 
used for this schema is not a valid package name. where the namespace on 
the schema is: 
targetNamespace="http://uri.etsi.org/TrstSvc/SvcInfoExt/eSigDir-1999-93-EC-TrustedList/#""
Here for addressing this, according to SPEC above I think namespace 
needs to convert the package name in 
targetNamespace="http://uri.etsi.org/TrstSvc/SvcInfoExt/eSigDir-1999-93-EC-TrustedList/#" 
from "#" to 
"http://uri.etsi.org/TrstSvc/SvcInfoExt/eSigDir-1999-93-EC-TrustedList/__", 
according to SPEC definition. But instead, the fix for Issue - 709
addresses this by removing of special character "#", which is not 
correct as per SPEC.
Fix :
---
Fix available with the attached patch .
Regards,
Jayashree Viswanathan