| Summary: | JAXB: Issues with schema gen dealing with anonymous complex types and namespaces | ||||||||
|---|---|---|---|---|---|---|---|---|---|
| Product: | z_Archived | Reporter: | David McCann <david.mccann> | ||||||
| Component: | Eclipselink | Assignee: | Nobody - feel free to take it <nobody> | ||||||
| Status: | RESOLVED FIXED | QA Contact: | |||||||
| Severity: | normal | ||||||||
| Priority: | P3 | ||||||||
| Version: | unspecified | ||||||||
| Target Milestone: | --- | ||||||||
| Hardware: | PC | ||||||||
| OS: | Windows XP | ||||||||
| Whiteboard: | |||||||||
| Attachments: |
|
||||||||
Created attachment 179337 [details]
Proposed fix
Created attachment 179338 [details]
Supporting test cases
reviewed by: matt.macivor@oracle.com tests: jaxb/schemagen/anonymoustype/AnonymousTypeTestCases; all unit tests pass as expected The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink |
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>