Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] Complex Mapping rules in MOXy?

Hello Bill,

One way to handle this would be to use an XML Transformation Mapping.  I have attached some sample code based on your use case below, (just rename the extension to .zip).

-Blaise

Knotts, Bill wrote:
Hello all,
 
Now that I have some basic XML-JAVA mappings working with MOXy, I have a more challenging question. 
 
What options are available for solving the following mapping requirement?: "If a given element is empty or null, populate domain model attribute with a concatenation of other element values if these values are not null or empty."
 
The example below is somewhat simplified but give the idea of what is required:
 
//XSD snippet
 <xs:complexType name="Address">
  <xs:sequence>
   <xs:element name="AddressLine01" type="xs:string" minOccurs="0"/>
   <xs:element name="AddressLine02" type="xs:string" minOccurs="0"/>
   <xs:element name="HouseNbr" type="xs:string" minOccurs="0"/>
   <xs:element name="StreetDir" type="xs:string" minOccurs="0"/>
   <xs:element name="StreetName" type="xs:string" minOccurs="0"/>
   <xs:element name="StreetSuffix" type="xs:string" minOccurs="0"/>
   <xs:element name="RRNbr" type="xs:string" minOccurs="0"/>
   <xs:element name="POBox" type="xs:string" minOccurs="0"/>
  </xs:sequence>
 </xs:complexType>
 
// Java Domain Model Attribute
 setAddress01(String addr01)
 
//Pseudo-coded Mapping Rules
if xml.AddressLine01 IS NOT null AND xmlAddressLine01 IS NOT empty
  java.Address01 should be set to value of xml.AddressLine01
else
  if (xml.RRNbr IS null OR empty) AND (xml.POBox IS null OR empty)
    java.Address01 = (xml.HouseNbr + " ") +
      if (xml.StreetDir IS NOT null) AND (xml.StreetDir IS NOT empty)
        (xml.StreetDir + " ")
      if (xml.StreetName IS NOT null) AND (xml.StreetName IS NOT empty)
        xml.StreetName
      if (xml.StreetSuffix IS NOT null) AND (xml.StreetSuffix IS NOT empty)
        (" " + xml.StreetSuffix)
 
 
I've been very pleased with what I could accomplish in a short amount of time working with MOXy but the solution to the above has me stumped.
 
Any suggestions would be greatly appreciated.
 
Regards,
Bill

_______________________________________________ eclipselink-users mailing list eclipselink-users@xxxxxxxxxxx https://dev.eclipse.org/mailman/listinfo/eclipselink-users

Attachment: knotts.zip_REMOVE
Description: Binary data


Back to the top