Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 366255

Summary: Schema Gen: Wrong schema generated for two predicate mappings that share an element/attribute combination
Product: z_Archived Reporter: Blaise Doughan <blaise.doughan>
Component: EclipselinkAssignee: Nobody - feel free to take it <nobody>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P2 CC: david.mccann, david.twelves
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
Proposed fix.
none
Supporting test cases.
none
Supporting test cases. none

Description Blaise Doughan CLA 2011-12-09 16:11:39 EST
Given the following class:

  @XmlRootElement
  @XmlType(propOrder = {"id", "name", "address", "phoneNumbers"})
  @XmlAccessorType(XmlAccessType.FIELD)
  public class Customer {

    private String id;
    private String name;

    @XmlJavaTypeAdapter(LinkAdapter.class)
    @XmlPath("atom:link[@rel='address']/@href")
    private Address address;

    @XmlJavaTypeAdapter(LinkAdapter.class)
    @XmlPath("atom:link[@rel='phone']/@href")
    private PhoneNumber phoneNumbers;

  }

Currently the following XML schemas are incorrectly generated:

 <?xml version="1.0" encoding="UTF-8"?>
 <xsd:schema xmlns:atom="http://www.w3.org/2005/Atom" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
   <xsd:import schemaLocation="schema2.xsd" namespace="http://www.w3.org/2005/Atom"/>
   <xsd:complexType name="customer">
      <xsd:sequence>
         <xsd:element name="id" type="xsd:string" minOccurs="0"/>
         <xsd:element name="name" type="xsd:string" minOccurs="0"/>
         <xsd:element ref="atom:link" minOccurs="0"/>
      </xsd:sequence>
   </xsd:complexType>
   <xsd:element name="customer" type="customer"/>
 </xsd:schema>
 <?xml version="1.0" encoding="UTF-8"?>
 <xsd:schema xmlns:ns0="http://www.w3.org/2005/Atom" xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.w3.org/2005/Atom">
   <xsd:element name="link">
      <xsd:complexType>
         <xsd:sequence/>
         <xsd:attribute name="href" type="xsd:string"/>
         <xsd:attribute name="href" type="xsd:string"/>
         <xsd:attribute name="rel" type="xsd:string"/>
      </xsd:complexType>
   </xsd:element>
 </xsd:schema>

The schemas should look as follows:

 <?xml version="1.0" encoding="UTF-8"?>
 <xsd:schema xmlns:atom="http://www.w3.org/2005/Atom" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
   <xsd:import schemaLocation="schema2.xsd" namespace="http://www.w3.org/2005/Atom"/>
   <xsd:complexType name="customer">
      <xsd:sequence>
         <xsd:element name="id" type="xsd:string" minOccurs="0"/>
         <xsd:element name="name" type="xsd:string" minOccurs="0"/>
         <xsd:element ref="atom:link" minOccurs="0" maxOccurs="unbounded"/>
      </xsd:sequence>
   </xsd:complexType>
   <xsd:element name="customer" type="customer"/>
 </xsd:schema>
 <?xml version="1.0" encoding="UTF-8"?>
 <xsd:schema xmlns:ns0="http://www.w3.org/2005/Atom" xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.w3.org/2005/Atom">
   <xsd:element name="link">
      <xsd:complexType>
         <xsd:sequence/>
         <xsd:attribute name="href" type="xsd:string"/>
         <xsd:attribute name="rel" type="xsd:string"/>
      </xsd:complexType>
   </xsd:element>
 </xsd:schema>
Comment 1 Blaise Doughan CLA 2011-12-09 16:13:26 EST
Additional Info

public class LinkAdapter extends XmlAdapter<String, Object> {
   ...
}
Comment 2 David McCann CLA 2012-05-30 15:55:32 EDT
Created attachment 216528 [details]
Proposed fix.
Comment 3 David McCann CLA 2012-05-30 15:55:44 EDT
Created attachment 216529 [details]
Supporting test cases.
Comment 4 David McCann CLA 2012-05-30 15:58:44 EDT
Created attachment 216531 [details]
Supporting test cases.
Comment 5 David McCann CLA 2012-05-31 10:28:15 EDT
Fix checked into 2.4, Revision:  11568
Reviewed by:  blaise.doughan@oracle.com 
Tests: all unit tests pass as expected;  jaxb.annotations.xmlpath.predicate.adapter.CustomerTestCases
Comment 6 David McCann CLA 2012-05-31 13:54:22 EDT
Fix checked into 2.5, revision: 11579
Comment 7 Eclipse Webmaster CLA 2022-06-09 10:16:14 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink
Comment 8 Eclipse Webmaster CLA 2022-06-09 10:22:32 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink