* @param elt
* @return
*/
private Root createXMLRootFromJAXBElement(JAXBElement elt) {
// create an XMLRoot to hand into the marshaller
Root xmlroot = new Root();
Object objectValue = elt.getValue();
xmlroot.setObject(objectValue);
QName qname = elt.getName();
xmlroot.setLocalName(qname.getLocalPart());
xmlroot.setNamespaceURI(qname.getNamespaceURI());
xmlroot.setDeclaredType(elt.getDeclaredType());
xmlroot.setNil(elt.isNil());
if (elt.getDeclaredType() == CoreClassConstants.ABYTE || elt.getDeclaredType() == CoreClassConstants.APBYTE ||
elt.getDeclaredType().getCanonicalName().equals("javax.activation.DataHandler") ||
elt.getDeclaredType().isEnum()) {
// need a binary data mapping so need to wrap
Class generatedClass = getClassToGeneratedClasses().get(elt.getDeclaredType().getCanonicalName());
if(!elt.getDeclaredType().isEnum()) {
xmlroot.setSchemaType(Constants.BASE_64_BINARY_QNAME);
}
if (generatedClass != null && WrappedValue.class.isAssignableFrom(generatedClass)) {
ClassDescriptor desc = xmlMarshaller.getXMLContext().getSession(generatedClass).getDescriptor(generatedClass);
Object newObject = desc.getInstantiationPolicy().buildNewInstance();
((WrappedValue) newObject).setValue(objectValue);
xmlroot.setObject(newObject);
return xmlroot;
}
} else {
xmlroot.setSchemaType((QName) org.eclipse.persistence.internal.oxm.XMLConversionManager.getDefaultJavaTypes().get(elt.getDeclaredType()));
}
if (elt instanceof WrappedValue) {
xmlroot.setObject(elt);
return xmlroot;
}
Map<QName, Class> qNameToGeneratedClasses = jaxbContext.getQNameToGeneratedClasses();
if (qNameToGeneratedClasses != null) {
Class theClass = qNameToGeneratedClasses.get(qname);
if (theClass != null && WrappedValue.class.isAssignableFrom(theClass)) {
ClassDescriptor desc = xmlMarshaller.getXMLContext().getSession(theClass).getDescriptor(theClass);
Object newObject = desc.getInstantiationPolicy().buildNewInstance();
((WrappedValue) newObject).setValue(objectValue);
xmlroot.setObject(newObject);
return xmlroot;
}
}
Class generatedClass = null;
if (jaxbContext.getTypeMappingInfoToGeneratedType() != null) {
if (jaxbContext.getTypeToTypeMappingInfo() != null) {
if (elt.getDeclaredType() != null && elt.getDeclaredType().isArray()) {
TypeMappingInfo tmi = jaxbContext.getTypeToTypeMappingInfo().get(elt.getDeclaredType());
generatedClass = jaxbContext.getTypeMappingInfoToGeneratedType().get(tmi);
} else if (elt instanceof JAXBTypeElement) {
Type objectType = ((JAXBTypeElement) elt).getType();
TypeMappingInfo tmi = jaxbContext.getTypeToTypeMappingInfo().get(objectType);
generatedClass = jaxbContext.getTypeMappingInfoToGeneratedType().get(tmi);
}
}
} else {
if (elt.getDeclaredType() != null && elt.getDeclaredType().isArray()) {
if (jaxbContext.getArrayClassesToGeneratedClasses() != null) {
generatedClass = jaxbContext.getArrayClassesToGeneratedClasses().get(elt.getDeclaredType().getCanonicalName());
}
} else if (elt instanceof JAXBTypeElement) {
Type objectType = ((JAXBTypeElement) elt).getType();
generatedClass = jaxbContext.getCollectionClassesToGeneratedClasses().get(objectType);
}
}
if (generatedClass != null) {
ClassDescriptor desc = xmlMarshaller.getXMLContext().getSession(generatedClass).getDescriptor(generatedClass);
Object newObject = desc.getInstantiationPolicy().buildNewInstance();
((ManyValue) newObject).setItem(objectValue);
xmlroot.setObject(newObject);
}
return xmlroot;
}