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

Bug 339596

Summary: Extension: XPath Mapping with Predicates
Product: z_Archived Reporter: Blaise Doughan <blaise.doughan>
Component: EclipselinkAssignee: Nobody - feel free to take it <nobody>
Status: RESOLVED FIXED QA Contact:
Severity: enhancement    
Priority: P3 CC: eclipselink.oxm-inbox
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Bug Depends on:    
Bug Blocks: 332770, 340474, 348114    
Attachments:
Description Flags
Core - Fix
none
Core - Fix
none
Core - Fix
none
MOXy - Test Cases
none
Core - Fix
none
MOXy - Test Cases
none
Core - Fix
none
MOXy - Test Cases
none
Core - Fix
none
MOXy - Test Cases
none
Core - Fix
none
MOXy - Test Cases
none
Core - Fix
none
MOXy - Fix none

Description Blaise Doughan CLA 2011-03-10 16:01:11 EST
This extension will allow the following XML document:

<?xml version="1.0" encoding="UTF-8"?>
<customer>
   <name type="FIRST">Jane</name>
   <name type="LAST">Doe</name>
   <address type="BILLING"/>
   <address type="SHIPPING"/>
</customer>


To be mapped to the following class:

package conditional;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;

import org.eclipse.persistence.oxm.annotations.XmlPath;

@XmlRootElement
@XmlType(propOrder={"firstName", "lastName", "billingAddress", "shippingAddress"})
@XmlAccessorType(XmlAccessType.FIELD)
public class Customer {

    @XmlPath("name[@type=FIRST]/text()")
    private String firstName;

    @XmlPath("name[@type=LAST]/text()")
    private String lastName;

    @XmlPath("address[@type=BILLING]")
    private Address billingAddress;

    @XmlPath("address[@type=SHIPPING]")
    private Address shippingAddress;

}

This is through adding support for predicates (the part between the square brackets) to MOXy's XPath based mapping.
Comment 1 Blaise Doughan CLA 2011-03-10 16:09:39 EST
Created attachment 190928 [details]
Core - Fix
Comment 2 Blaise Doughan CLA 2011-03-10 16:42:59 EST
Created attachment 190934 [details]
Core - Fix
Comment 3 Blaise Doughan CLA 2011-03-11 11:41:17 EST
Created attachment 191001 [details]
Core - Fix

Updated to include support for namespaces.
Comment 4 Blaise Doughan CLA 2011-03-14 12:55:29 EDT
Created attachment 191149 [details]
MOXy - Test Cases
Comment 5 Blaise Doughan CLA 2011-03-14 12:55:46 EDT
Created attachment 191150 [details]
Core - Fix
Comment 6 Blaise Doughan CLA 2011-03-14 16:45:54 EDT
Created attachment 191167 [details]
MOXy - Test Cases
Comment 7 Blaise Doughan CLA 2011-03-14 16:46:11 EDT
Created attachment 191168 [details]
Core - Fix
Comment 8 Blaise Doughan CLA 2011-03-15 16:59:35 EDT
Created attachment 191249 [details]
MOXy - Test Cases
Comment 9 Blaise Doughan CLA 2011-03-15 16:59:53 EDT
Created attachment 191250 [details]
Core - Fix
Comment 10 Blaise Doughan CLA 2011-03-17 13:45:09 EDT
Created attachment 191449 [details]
MOXy - Test Cases
Comment 11 Blaise Doughan CLA 2011-03-17 13:45:26 EDT
Created attachment 191450 [details]
Core - Fix
Comment 12 Blaise Doughan CLA 2011-03-18 15:38:22 EDT
Created attachment 191545 [details]
MOXy - Test Cases
Comment 13 Blaise Doughan CLA 2011-03-18 15:38:45 EDT
Created attachment 191546 [details]
Core - Fix
Comment 14 Blaise Doughan CLA 2011-03-18 15:38:59 EDT
Created attachment 191547 [details]
MOXy - Fix
Comment 15 Blaise Doughan CLA 2011-03-18 15:58:48 EDT
CORE CHANGES

XPathPredicate
- New class.  This class represents the [@foo='bar] portion of the XPath.  It has two properties, one to store the XPath portion and the other to hold the value.

XPathFragment
- Now can hold onto an XPathPredicate.

XMLField
- Has code to cause the XPathPredicate to be initialized.

*NodeValue
- Causes the predicate to be written when appropriate.

MarshalRecord
- Added a new method predicateAttribute which is responsible for writing the predicate attribute if one was specified.

UnmarshalRecord
- Now leverages the predicate if one is available.  This is done the same way as for positional nodes.

---

MOXy CHANGES

AnnotationsProcessor
- Added JoinNode and JoinNodes to the list of annotations that should be looked for to determine if a property has been mapped.
- Fixed an "is attribute" check.

MappingsGenerator
- Fixed an issue where the schema type was not being set to QName if the mapping was configured with @XmlPath.
Comment 16 Blaise Doughan CLA 2011-03-21 10:09:10 EDT
Fix checked into trunk at rev:  9140

Code reviewed by:  Matt MacIvor
Comment 17 Eclipse Webmaster CLA 2022-06-09 10:32:37 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink