use of org.eclipse.persistence.internal.jaxb.WrappedValue in project eclipselink by eclipse-ee4j.
the class JAXBContext method createJAXBElementFromXMLRoot.
protected JAXBElement createJAXBElementFromXMLRoot(Root xmlRoot, Class<?> declaredType) {
Object value = xmlRoot.getObject();
if (value instanceof List) {
List theList = (List) value;
for (int i = 0; i < theList.size(); i++) {
Object next = theList.get(i);
if (next instanceof Root) {
theList.set(i, createJAXBElementFromXMLRoot((Root) next, declaredType));
}
}
} else if (value instanceof WrappedValue) {
QName qname = new QName(xmlRoot.getNamespaceURI(), xmlRoot.getLocalName());
return new JAXBElement(qname, ((WrappedValue) value).getDeclaredType(), ((WrappedValue) value).getValue());
} else if (value instanceof JAXBElement) {
return (JAXBElement) value;
} else if (value instanceof ManyValue) {
value = ((ManyValue) value).getItem();
}
QName qname = new QName(xmlRoot.getNamespaceURI(), xmlRoot.getLocalName());
Map<QName, Class<?>> qNamesToDeclaredClasses = getQNamesToDeclaredClasses();
if (qNamesToDeclaredClasses != null && qNamesToDeclaredClasses.size() > 0) {
Class<?> declaredClass = qNamesToDeclaredClasses.get(qname);
if (declaredClass != null) {
return createJAXBElement(qname, declaredClass, value);
}
}
Class<?> xmlRootDeclaredType = xmlRoot.getDeclaredType();
if (xmlRootDeclaredType != null) {
return createJAXBElement(qname, xmlRootDeclaredType, value);
}
return createJAXBElement(qname, declaredType, value);
}
use of org.eclipse.persistence.internal.jaxb.WrappedValue in project eclipselink by eclipse-ee4j.
the class JAXBMarshaller method wrapObject.
private Object wrapObject(Object object, JAXBElement wrapperElement, TypeMappingInfo typeMappingInfo) {
if (jaxbContext.getTypeMappingInfoToGeneratedType().size() > 0) {
Class<?> generatedClass = jaxbContext.getTypeMappingInfoToGeneratedType().get(typeMappingInfo);
if (generatedClass != null && object == null && wrapperElement != null) {
return wrapObjectInXMLRoot(wrapperElement, null, typeMappingInfo);
}
if (generatedClass != null && WrappedValue.class.isAssignableFrom(generatedClass)) {
ClassDescriptor desc = xmlMarshaller.getXMLContext().getSession(generatedClass).getDescriptor(generatedClass);
Object newObject = desc.getInstantiationPolicy().buildNewInstance();
((WrappedValue) newObject).setValue(object);
object = newObject;
} else if (generatedClass != null) {
// should be a many value
ClassDescriptor desc = xmlMarshaller.getXMLContext().getSession(generatedClass).getDescriptor(generatedClass);
Object newObject = desc.getInstantiationPolicy().buildNewInstance();
((ManyValue) newObject).setItem(object);
object = newObject;
}
}
if (null == wrapperElement) {
Root xmlRoot = new Root();
QName xmlTagName = typeMappingInfo.getXmlTagName();
if (null == xmlTagName) {
return object;
}
xmlRoot.setNamespaceURI(typeMappingInfo.getXmlTagName().getNamespaceURI());
xmlRoot.setLocalName(typeMappingInfo.getXmlTagName().getLocalPart());
xmlRoot.setObject(object);
return xmlRoot;
}
return wrapObjectInXMLRoot(wrapperElement, object, typeMappingInfo);
}
Aggregations