}
return mapping;
}
public XMLCompositeDirectCollectionMapping generateDirectCollectionMapping(Property property, XMLDescriptor descriptor, NamespaceInfo namespaceInfo) {
XMLCompositeDirectCollectionMapping mapping = new XMLCompositeDirectCollectionMapping();
mapping.setAttributeName(property.getPropertyName());
initializeXMLContainerMapping(mapping, property.getType().isArray());
// 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();
if (collectionType.isArray()){
JAXBArrayAttributeAccessor accessor = new JAXBArrayAttributeAccessor(mapping.getAttributeAccessor(), mapping.getContainerPolicy(), helper.getClassLoader());
String componentClassName = collectionType.getComponentType().getQualifiedName();
if (collectionType.getComponentType().isPrimitive()){
Class primitiveClass = XMLConversionManager.getDefaultManager().convertClassNameToClass(componentClassName);
accessor.setComponentClass(primitiveClass);
mapping.setAttributeAccessor(accessor);
Class declaredClass = XMLConversionManager.getDefaultManager().getObjectClass(primitiveClass);
mapping.setAttributeElementClass(declaredClass);
} else {
accessor.setComponentClassName(componentClassName);
mapping.setAttributeAccessor(accessor);
JavaClass componentType = collectionType.getComponentType();
try{
Class declaredClass = PrivilegedAccessHelper.getClassForName(componentType.getRawName(), false, helper.getClassLoader());
mapping.setAttributeElementClass(declaredClass);
}catch (Exception e) {}
}
} else if (helper.isCollectionType(collectionType)){
Collection args = collectionType.getActualTypeArguments();
if (args.size() >0){
JavaClass itemType = (JavaClass)args.iterator().next();
try {
Class declaredClass = PrivilegedAccessHelper.getClassForName(itemType.getRawName(), false, helper.getClassLoader());
if(declaredClass != String.class){
mapping.setAttributeElementClass(declaredClass);
}
} catch (Exception e) {}
}
}
collectionType = containerClassImpl(collectionType);
mapping.useCollectionClassName(collectionType.getRawName());
// if the XPath is set (via xml-path) use it; otherwise figure it out
XMLField xmlField = getXPathForField(property, namespaceInfo, true, false);
mapping.setField(xmlField);
if (helper.isAnnotationPresent(property.getElement(), XmlMixed.class)) {
xmlField.setXPath("text()");
}
if (XMLConstants.QNAME_QNAME.equals(property.getSchemaType())){
((XMLField) mapping.getField()).setSchemaType(XMLConstants.QNAME_QNAME);
}
// handle null policy set via xml metadata
if (property.isSetNullPolicy()) {
mapping.setNullPolicy(getNullPolicyFromProperty(property, namespaceInfo.getNamespaceResolverForDescriptor()));
} else if (property.isNillable()){
mapping.getNullPolicy().setNullRepresentedByXsiNil(true);
mapping.getNullPolicy().setMarshalNullRepresentation(XMLNullRepresentationType.XSI_NIL);
}
mapping.getNullPolicy().setNullRepresentedByEmptyNode(false);
if (property.isSetXmlElementWrapper()) {
mapping.setWrapperNullPolicy(getWrapperNullPolicyFromProperty(property));
}
if (property.isRequired()) {
((XMLField) mapping.getField()).setRequired(true);
}
if (property.isXmlElementType() && property.getGenericType()!=null ){
Class theClass = helper.getClassForJavaClass(property.getGenericType());
mapping.setAttributeElementClass(theClass);
}
if (xmlField.getXPathFragment().isAttribute() || property.isXmlList() || xmlField.getXPathFragment().nameIsText()){
mapping.setUsesSingleNode(true);
}
// handle cdata set via metadata
if (property.isSetCdata()) {
mapping.setIsCDATA(property.isCdata());
}
return mapping;
}