xs:import namespace="http://www.w3.org/2005/05/xmlmime" is not generated · Issue #856 · javaee/jaxb-v2 (original) (raw)

The following issues were found when using schemagen of JAXB RI 2.2.3
and 2.2.4u1.

If @XmlMimeType is used in java file(the attached test program ItemType.java of
TP_XmlMimeType), the problems below can be seen.

(a)The namespce http://www.w3.org/2005/05/xmlmime is not imported.

(b)The declaration xmlns:xmime="http://www.w3.org/2005/05/xmlmime" is
not printed out in the element xs:schema, so different prefix
namespace is declared at each xs:element as follows.

----->
<xs:element name="TextXml" ns1:expectedContentTypes="text/xml"
type="xs:base64Binary" xmlns:ns1="http://www.w3.org/2005/05/xmlmime"/>
<xs:element name="AppXml" ns2:expectedContentTypes="application/xml"
type="xs:base64Binary" xmlns:ns2="http://www.w3.org/2005/05/xmlmime"/>
<-----

To reproduce:
(1)Specified @XmlMimeType in Java source file.
(2)Use schemagen to generate XMLSchema against those Java files.

Investigation:

If @XmlAttachmentRef is used in Java file(ExXmlAttachRef.java of
TP_ExXmlAttachRef) to generate XMLSchema, the following xml with
xs:import element is created.

----->
<xs:schema version="1.0" xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:swaRef="http://ws-i.org/profiles/basic/1.1/xsd">
<xs:import namespace="http://ws-i.org/profiles/basic/1.1/xsd"
schemaLocation="http://ws-i.org/profiles/basic/1.1/swaref.xsd"/>
...
<-----

The element "import" is necessary to access a namespace different from
targetNamespace of the XMLSchema document, likewise the element
xs:import below is printed out from java source where @XmlMimeType is
used.

----->
<xs:import namespace="http://www.w3.org/2005/05/xmlmime"
schemaLocation="http://www.w3.org/2005/05/xmlmime"/>
<-----

I think this is in line with XMLSchema specification.

Fix plan:

We provided the following fix at com\sun\xml\bind\v2\schemagen\XmlSchemaGenerator.java based on jaxb 2.2.3. (XmlSchemaGenerator contains the fix).

Before:
----->
216:public void add( ClassInfo<T,C> clazz ) {
:
270: if(generateSwaRefAdapter(p))
271: n.useSwaRef = true;
<-----

After:
----->
216:public void add( ClassInfo<T,C> clazz ) {
:
270: if(generateSwaRefAdapter(p))
271: n.useSwaRef = true;
272: MimeType mimeType = p.getExpectedMimeType(); //added
273: if( mimeType != null ) //added
274: n.useMimeType = true; //added
<-----

Affected Versions

[2.2.3]