Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 325897 - JAXB: Issues with schema gen dealing with anonymous complex types and namespaces
Summary: JAXB: Issues with schema gen dealing with anonymous complex types and namespaces
Status: RESOLVED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Nobody - feel free to take it CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-09-21 15:34 EDT by David McCann CLA
Modified: 2022-06-09 10:26 EDT (History)
0 users

See Also:


Attachments
Proposed fix (4.85 KB, patch)
2010-09-21 15:36 EDT, David McCann CLA
no flags Details | Diff
Supporting test cases (14.67 KB, patch)
2010-09-21 15:37 EDT, David McCann CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description David McCann CLA 2010-09-21 15:34:20 EDT
Given the following:

  TypeMappingInfo t1 = new TypeMappingInfo();
  t1.setAnnotations(new Annotation[0]);
  t1.setType(Process.class);
  t1.setElementScope(TypeMappingInfo.ElementScope.Global);
  t1.setXmlTagName(new QName("http://xmlns.oracle.com/Test", "process"));
    
  TypeMappingInfo[] types = { t1 };
  Map<String, Object> properties = new HashMap<String, Object>();
  properties.put(JAXBContextFactory.DEFAULT_TARGET_NAMESPACE_KEY,
     "http://xmlns.oracle.com/Test/types");
  JAXBContext cxt = JAXBContextFactory.createContext(types, properties, 
     Thread.currentThread().getContextClassLoader());

  MySchemaOutputResolver mysr = new MySchemaOutputResolver();
  cxt.generateSchema(mysr);

Where Process is:

  @XmlType(name = "")
  @XmlRootElement(name = "process")
  public class Process {
      @XmlElement(required = true)
      protected String input;
  }

We get two schemas generated as expected, but the schema generated for the default target namespace is incorrect:

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:ns1="http://xmlns.oracle.com/Test/types" 
      xmlns:ns0="http://xmlns.oracle.com/Test" 
      xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
      targetNamespace="http://xmlns.oracle.com/Test">
  <xsd:import schemaLocation="schema0.xsd" 
      namespace="http://xmlns.oracle.com/Test/types"/>
  <xsd:element name="process" type="ns1:null"/>
</xsd:schema>

We shouldn't be trying to do an import and reference global types in the imported schema, because there aren't any.  We should detect that there is no type, and generate an anonymous complex type, i.e.

<xsd:schema xmlns:ns0="http://xmlns.oracle.com/Test/types" 
      xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
      targetNamespace="http://xmlns.oracle.com/Test/types">
   <xsd:element name="process">
      <xsd:complexType>
         <xsd:sequence>
            <xsd:element name="input" type="xsd:string"/>
         </xsd:sequence>
      </xsd:complexType>
   </xsd:element>
</xsd:schema>
Comment 1 David McCann CLA 2010-09-21 15:36:49 EDT
Created attachment 179337 [details]
Proposed fix
Comment 2 David McCann CLA 2010-09-21 15:37:07 EDT
Created attachment 179338 [details]
Supporting test cases
Comment 3 David McCann CLA 2010-09-22 10:27:41 EDT
reviewed by: matt.macivor@oracle.com
tests: jaxb/schemagen/anonymoustype/AnonymousTypeTestCases; all unit tests pass as expected
Comment 4 Eclipse Webmaster CLA 2022-06-09 10:26:07 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink