[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Newsgroup Home]
|
[news.eclipse.rt.eclipselink] Re: MOXy mapping question
|
Hello Matti,
You could map this as follows. I believe you were just missing the
"/text()" at the end of your XPath statements on your choice mappings.
import org.eclipse.persistence.oxm.NamespaceResolver;
import org.eclipse.persistence.oxm.XMLDescriptor;
import org.eclipse.persistence.oxm.mappings.XMLChoiceObjectMapping;
import org.eclipse.persistence.sessions.Project;
public class DesignationRequestProject extends Project {
public DesignationRequestProject() {
this.addDescriptor(getDesignationRequestDescriptor());
}
private XMLDescriptor getDesignationRequestDescriptor() {
XMLDescriptor xmlDescriptor = new XMLDescriptor();
xmlDescriptor.setJavaClass(DesignationRequest.class);
xmlDescriptor.setDefaultRootElement("app:DesignationRequest");
NamespaceResolver namespaceResolver = new NamespaceResolver();
namespaceResolver.put("app", "urn:your-namespace");
xmlDescriptor.setNamespaceResolver(namespaceResolver);
XMLChoiceObjectMapping numericIdMapping = new
XMLChoiceObjectMapping();
numericIdMapping.setAttributeName("numericId");
numericIdMapping.addChoiceElement("app:numericId/value/text()",
String.class);
numericIdMapping.addChoiceElement("app:numericIdTypeB/value/text()",
String.class);
xmlDescriptor.addMapping(numericIdMapping);
XMLChoiceObjectMapping alphanumericIdMapping = new
XMLChoiceObjectMapping();
alphanumericIdMapping.setAttributeName("alphanumericId");
alphanumericIdMapping.addChoiceElement("app:alphanumericId/value/text()",
String.class);
alphanumericIdMapping.addChoiceElement("app:alphanumericIdTypeB/value/text()",
String.class);
xmlDescriptor.addMapping(alphanumericIdMapping);
return xmlDescriptor;
}
}
For your XML schema to get the namespace qualification from your examples
you could use something like the one below. Note you will need to use
elementFormDefault="unqualified" and make all elements that will be
namespace qualified global elements.
<xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="unqualified"
attributeFormDefault="unqualified"
targetNamespace="urn:your-namespace" xmlns="urn:your-namespace">
<xs:element name="DesignationRequest">
<xs:complexType>
<xs:choice>
<xs:element ref="numericId"/>
<xs:element ref="numericIdTypeB"/>
<xs:element ref="alphanumericId"/>
<xs:element ref="alphanumericIdTypeB"/>
</xs:choice>
</xs:complexType>
</xs:element>
<xs:element name="numericId" type="value"/>
<xs:element name="numericIdTypeB" type="value"/>
<xs:element name="alphanumericId" type="value"/>
<xs:element name="alphanumericIdTypeB" type="value"/>
<xs:complexType name="value">
<xs:sequence>
<xs:element name="value" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
-Blaise
Blaise Doughan
Team Lead, EclipseLink OXM/JAXB/SDO