Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] [MOXy] Mapping composite object into parent record

Hi Polly,

Nothing is jumping out at me, and yes, the self (".") mapping should work.  Can you please forward me your schema file?

--Dave

amphoras wrote:
Hi,

Argh!  I am trying to map a composite object into the parent record like
documented here:
http://wiki.eclipse.org/Introduction_to_XML_Mappings_(ELUG)#XML_Composite_Object_Mapping

I have an Address element, and I'm trying to map the "Line" elements inside
it to another object called "AddressLine".  This is not working.  The object
"addressLine" is always null.

My XML looks like:
<Address ...>
  <AttentionOfName>Jane Doe</AttentionOfName>
  <CareOfName></CareOfName>
  <LineOne>101 Main Street</LineOne>
  <LineTwo>Apt 514</LineTwo>
  <LineThree>P.O. Box 123123</LineThree>
  <LineFour>Suite 1234</LineFour>
  <CityName>Malibu</CityName>
  <StateCode>CA</StateCode>
  <CountryCode>USA</CountryCode>
  <PostalCode>90914-2938</PostalCode>
</Address>

My project.xml file looks like:
		<class-mapping-descriptor xsi:type="xml-class-mapping-descriptor">
			<class>com.infor.common.model.fields.AddressLines</class>
			<alias>AddressLines</alias>
			<events xsi:type="event-policy"/>
			<querying xsi:type="query-policy"/>
			<attribute-mappings>
				<attribute-mapping xsi:type="xml-direct-mapping">
					<attribute-name>addressLine1</attribute-name>
					<field name="LineOne/text()" xsi:type="node"/>
				</attribute-mapping>
				<attribute-mapping xsi:type="xml-direct-mapping">
					<attribute-name>addressLine2</attribute-name>
					<field name="LineTwo/text()" xsi:type="node"/>
				</attribute-mapping>
				<attribute-mapping xsi:type="xml-direct-mapping">
					<attribute-name>addressLine3</attribute-name>
					<field name="LineThree/text()" xsi:type="node"/>
				</attribute-mapping>
				<attribute-mapping xsi:type="xml-direct-mapping">
					<attribute-name>addressLine4</attribute-name>
					<field name="LineFour/text()" xsi:type="node"/>
				</attribute-mapping>
			</attribute-mappings>
			<descriptor-type>aggregate</descriptor-type>
			<instantiation/>
			<copying xsi:type="instantiation-copy-policy"/>
			<namespace-resolver>
				<namespaces/>
			
<default-namespace-uri>http://www.foo.com/bar/baz</default-namespace-uri>
			</namespace-resolver>
			<schema xsi:type="schema-file-reference">
				<schema-context>/Address</schema-context>
				<node-type>complex-type</node-type>
			</schema>
		</class-mapping-descriptor>
		<class-mapping-descriptor xsi:type="xml-class-mapping-descriptor">
			<class>com.infor.common.model.fields.Address</class>
			<alias>Address</alias>
			<events xsi:type="event-policy"/>
			<querying xsi:type="query-policy"/>
			<attribute-mappings>
				<attribute-mapping xsi:type="xml-direct-mapping">
					<attribute-name>attentionOfName</attribute-name>
					<field name="AttentionOfName/text()" xsi:type="node"/>
				</attribute-mapping>
				<attribute-mapping xsi:type="xml-direct-mapping">
					<attribute-name>careOfName</attribute-name>
					<field name="CareOfName/text()" xsi:type="node"/>
				</attribute-mapping>
				<attribute-mapping xsi:type="xml-composite-object-mapping">
					<attribute-name>addressLines</attribute-name>
				
<reference-class>com.infor.common.model.fields.AddressLines</reference-class>
					<field name="." xsi:type="node"/>
				</attribute-mapping>
				<attribute-mapping xsi:type="xml-direct-mapping">
					<attribute-name>city</attribute-name>
					<field name="CityName/text()" xsi:type="node"/>
				</attribute-mapping>
				<attribute-mapping xsi:type="xml-direct-mapping">
					<attribute-name>state</attribute-name>
					<field name="StateCode/text()" xsi:type="node"/>
				</attribute-mapping>
				<attribute-mapping xsi:type="xml-direct-mapping">
					<attribute-name>postalCode</attribute-name>
					<field name="PostalCode/text()" xsi:type="node"/>
				</attribute-mapping>
				<attribute-mapping xsi:type="xml-direct-mapping">
					<attribute-name>countryCode</attribute-name>
					<field name="CountryCode/text()" xsi:type="node"/>
				</attribute-mapping>
			</attribute-mappings>
			<descriptor-type>aggregate</descriptor-type>
			<instantiation/>
			<copying xsi:type="instantiation-copy-policy"/>
			<default-root-element>Address</default-root-element>
			<default-root-element-field name="Address" xsi:type="node">
				<leaf-element-type>AddressType</leaf-element-type>
			</default-root-element-field>
			<namespace-resolver>
				<namespaces/>
			
<default-namespace-uri>http://www.foo.com/bar/baz</default-namespace-uri>
			</namespace-resolver>
			<schema xsi:type="schema-file-reference">
				<schema-context>/Address</schema-context>
				<node-type>complex-type</node-type>
			</schema>
		</class-mapping-descriptor>

This mapping looks to me to be the XML equivalent of the examples that I saw
in code.  So why doesn't this work?  I saw the one note in the documentation
that said "The nodes mapped to by the composite object must be sequential. " 
I am not 100% sure what this means, but I did make sure that all the nodes
in Address and AddressLine are in the right order.  In addition, I debugged
into this but can't figure out why the "." mapping to AddressLine is never
used.  The eclipselink.moxy.test project uses this, so it looks like this is
definitely supposed to be supported.  But I want to do this with XML, not
with code.  

Can someone tell me what is wrong with this mapping?

Thanks!
--Polly
  

--

Oracle
David McCann | Principal Software Engineer | TopLink Product
Oracle Corporation Canada
45 O'Connor Street, Suite 400
Ottawa, Ontario K1P 1A4
Canada
613.288.4636
613.238.2818 (fax)


Back to the top