}
return mapping;
}
public ChoiceCollectionMapping generateChoiceCollectionMapping(Property property, Descriptor descriptor, NamespaceInfo namespace) {
ChoiceCollectionMapping mapping = new XMLChoiceCollectionMapping();
initializeXMLContainerMapping(mapping, property.getType().isArray());
mapping.setAttributeName(property.getPropertyName());
// handle read-only set via metadata
if (property.isSetReadOnly()) {
mapping.setIsReadOnly(property.isReadOnly());
}
// handle write-only set via metadata
if (property.isSetWriteOnly()) {
mapping.setIsWriteOnly(property.isWriteOnly());
}
if (property.isMethodProperty()) {
if (property.getGetMethodName() == null) {
// handle case of set with no get method
String paramTypeAsString = property.getType().getName();
mapping.setAttributeAccessor(new JAXBSetMethodAttributeAccessor(paramTypeAsString, helper.getClassLoader()));
mapping.setIsReadOnly(true);
mapping.setSetMethodName(property.getSetMethodName());
} else if (property.getSetMethodName() == null) {
mapping.setGetMethodName(property.getGetMethodName());
mapping.setIsWriteOnly(true);
} else {
mapping.setSetMethodName(property.getSetMethodName());
mapping.setGetMethodName(property.getGetMethodName());
}
}
JavaClass collectionType = property.getType();
collectionType = containerClassImpl(collectionType);
mapping.useCollectionClassName(collectionType.getRawName());
if (property.isSetXmlElementWrapper()) {
mapping.setWrapperNullPolicy(getWrapperNullPolicyFromProperty(property));
}
boolean isIdRef = property.isXmlIdRef();
Iterator<Property> choiceProperties = property.getChoiceProperties().iterator();
while (choiceProperties.hasNext()) {
Property next = choiceProperties.next();
JavaClass type = next.getType();
JavaClass originalType = next.getType();
Converter converter = null;
Field xmlField = null;
TypeInfo info = typeInfo.get(type.getName());
if(info != null){
XmlJavaTypeAdapter adapter = info.getXmlJavaTypeAdapter();
if(adapter != null){
String adapterValue = adapter.getValue();
JavaClass adapterClass = helper.getJavaClass(adapterValue);
JavaClass theClass = CompilerHelper.getTypeFromAdapterClass(adapterClass, helper);
type = theClass;
converter = new XMLJavaTypeConverter(adapterClass.getQualifiedName());
}
}
if (next.getXmlJoinNodes() != null) {
// handle XmlJoinNodes
List<Field> srcFlds = new ArrayList<Field>();
List<Field> tgtFlds = new ArrayList<Field>();
for (XmlJoinNode xmlJoinNode: next.getXmlJoinNodes().getXmlJoinNode()) {
srcFlds.add(new XMLField(xmlJoinNode.getXmlPath()));
tgtFlds.add(new XMLField(xmlJoinNode.getReferencedXmlPath()));
}
mapping.addChoiceElement(srcFlds, type.getQualifiedName(), tgtFlds);
} else if (isIdRef) {
// handle IDREF
String tgtXPath = null;
TypeInfo referenceType = typeInfo.get(type.getQualifiedName());
if (null != referenceType && referenceType.isIDSet()) {
Property prop = referenceType.getIDProperty();
tgtXPath = getXPathForField(prop, namespace, !prop.isAttribute(), false).getXPath();
}
// if the XPath is set (via xml-path) use it, otherwise figure it out
Field srcXPath;
if (next.getXmlPath() != null) {
srcXPath = new XMLField(next.getXmlPath());
} else {
srcXPath = getXPathForField(next, namespace, true, false);
}
mapping.addChoiceElement(srcXPath.getXPath(), type.getQualifiedName(), tgtXPath);
} else {
Field xpath;
if (next.getXmlPath() != null) {
xpath = new XMLField(next.getXmlPath());
} else {
xpath = getXPathForField(next, namespace, (!(this.typeInfo.containsKey(type.getQualifiedName()))) || type.isEnum(), false);
}
xmlField = xpath;
mapping.addChoiceElement(xpath.getName(), type.getQualifiedName());
if(!originalType.getQualifiedName().equals(type.getQualifiedName())) {
if(mapping.getClassNameToFieldMappings().get(originalType.getQualifiedName()) == null) {
mapping.getClassNameToFieldMappings().put(originalType.getQualifiedName(), xpath);
}
mapping.addConverter(xpath, converter);
}
}
if(xmlField !=null){
Mapping nestedMapping = (Mapping) mapping.getChoiceElementMappings().get(xmlField);
if(nestedMapping.isAbstractCompositeCollectionMapping()){
// handle null policy set via xml metadata
if (property.isSetNullPolicy()) {
((CompositeCollectionMapping)nestedMapping).setNullPolicy(getNullPolicyFromProperty(property, namespace.getNamespaceResolverForDescriptor()));
} else if (next.isNillable() && property.isNillable()){