use of org.eclipse.persistence.jaxb.TypeMappingInfo in project metro-jax-ws by eclipse-ee4j.
the class JAXBBond method marshal.
@Override
public void marshal(T object, Result result) throws JAXBException {
JAXBMarshaller marshaller = null;
try {
marshaller = parent.mpool.allocate();
marshaller.setAttachmentMarshaller(null);
marshaller.setProperty(jakarta.xml.bind.Marshaller.JAXB_FRAGMENT, true);
if (mappingInfo != null) {
if (isParameterizedType) {
JAXBTypeElement jte = new JAXBTypeElement(mappingInfo.getXmlTagName(), object, (ParameterizedType) mappingInfo.getType());
marshaller.marshal(jte, result, mappingInfo);
} else {
JAXBElement<T> elt = new JAXBElement<>(mappingInfo.getXmlTagName(), (Class<T>) mappingInfo.getType(), object);
// marshaller.marshal(elt, result);
marshaller.marshal(elt, result, mappingInfo);
}
} else {
TypeMappingInfo tmi = null;
if (object instanceof JAXBElement) {
QName q = ((JAXBElement) object).getName();
JAXBContext ctx = (JAXBContext) parent.getJAXBContext();
Map<TypeMappingInfo, QName> mtq = ctx.getTypeMappingInfoToSchemaType();
for (Map.Entry<TypeMappingInfo, QName> es : mtq.entrySet()) {
if (q.equals(es.getValue())) {
tmi = es.getKey();
break;
}
}
}
if (tmi != null) {
marshaller.marshal(object, result, tmi);
} else {
marshaller.marshal(object, result);
}
}
} finally {
if (marshaller != null) {
marshaller.setAttachmentMarshaller(null);
parent.mpool.replace(marshaller);
}
}
}
use of org.eclipse.persistence.jaxb.TypeMappingInfo in project metro-jax-ws by eclipse-ee4j.
the class JAXBContextFactory method newContext.
@Override
protected BindingContext newContext(BindingInfo bi) {
Map<String, Source> extMapping = (Map<String, Source>) bi.properties().get(OXM_XML_OVERRIDE);
Map<String, Object> properties = new HashMap<>();
Map<TypeInfo, TypeMappingInfo> map = createTypeMappings(bi.typeInfos());
// chen workaround for document-literal wrapper - new feature on eclipselink API requested
for (TypeInfo tinfo : map.keySet()) {
WrapperParameter wp = (WrapperParameter) tinfo.properties().get(WrapperParameter.class.getName());
if (wp != null) {
Class<?> wrpCls = (Class) tinfo.type;
Element javaAttributes = null;
for (ParameterImpl p : wp.getWrapperChildren()) {
Element xmlelem = findXmlElement(p.getTypeInfo().properties());
if (xmlelem != null) {
if (javaAttributes == null) {
javaAttributes = javaAttributes(wrpCls, extMapping);
}
xmlelem = (Element) javaAttributes.getOwnerDocument().importNode(xmlelem, true);
String fieldName = getFieldName(p, wrpCls);
xmlelem.setAttribute("java-attribute", fieldName);
javaAttributes.appendChild(xmlelem);
}
}
if (wrpCls.getPackage() != null)
wrpCls.getPackage().getName();
}
}
// Source src = extMapping.get("com.sun.xml.ws.test.toplink.jaxws");
// if (src != null){
// TransformerFactory tf = TransformerFactory.newInstance();
// try {
// Transformer t = tf.newTransformer();
// java.io.ByteArrayOutputStream bo = new java.io.ByteArrayOutputStream();
// StreamResult sax = new StreamResult(bo);
// t.transform(src, sax);
// System.out.println(new String(bo.toByteArray()));
// } catch (TransformerConfigurationException e) {
// e.printStackTrace();
// throw new WebServiceException(e.getMessage(), e);
// } catch (TransformerException e) {
// e.printStackTrace();
// throw new WebServiceException(e.getMessage(), e);
// }
// }
HashSet<Type> typeSet = new HashSet<>();
HashSet<TypeMappingInfo> typeList = new HashSet<>();
for (TypeMappingInfo tmi : map.values()) {
typeList.add(tmi);
typeSet.add(tmi.getType());
}
for (Class<?> clss : bi.contentClasses()) {
if (!typeSet.contains(clss) && !WrapperComposite.class.equals(clss)) {
typeSet.add(clss);
TypeMappingInfo tmi = new TypeMappingInfo();
tmi.setType(clss);
typeList.add(tmi);
}
}
TypeMappingInfo[] types = typeList.toArray(new TypeMappingInfo[0]);
if (extMapping != null) {
properties.put(OXM_XML_OVERRIDE, extMapping);
}
if (bi.getDefaultNamespace() != null) {
properties.put(OXM_XML_ELEMENT, bi.getDefaultNamespace());
}
try {
org.eclipse.persistence.jaxb.JAXBContext jaxbContext = (org.eclipse.persistence.jaxb.JAXBContext) org.eclipse.persistence.jaxb.JAXBContextFactory.createContext(types, properties, bi.getClassLoader());
return new JAXBContextWrapper(jaxbContext, map, bi.getSEIModel());
} catch (JAXBException e) {
throw new DatabindingException(e.getMessage(), e);
}
}
use of org.eclipse.persistence.jaxb.TypeMappingInfo in project eclipselink by eclipse-ee4j.
the class ConflictingListClassesTestCases method getTypeMappingInfos.
protected TypeMappingInfo[] getTypeMappingInfos() throws Exception {
if (typeMappingInfos == null) {
typeMappingInfos = new TypeMappingInfo[3];
TypeMappingInfo tmi = new TypeMappingInfo();
tmi.setXmlTagName(new QName("", "testTagName1"));
tmi.setElementScope(ElementScope.Global);
tmi.setType(List.class);
typeMappingInfos[0] = tmi;
TypeMappingInfo tmi2 = new TypeMappingInfo();
tmi2.setXmlTagName(new QName("", "testTagName2"));
tmi2.setElementScope(ElementScope.Global);
tmi2.setType(List.class);
typeMappingInfos[1] = tmi2;
TypeMappingInfo tmi3 = new TypeMappingInfo();
tmi3.setType(Employee.class);
typeMappingInfos[2] = tmi3;
}
return typeMappingInfos;
}
use of org.eclipse.persistence.jaxb.TypeMappingInfo in project eclipselink by eclipse-ee4j.
the class ConflictingListTypeTestCases method getTypeMappingInfos.
protected TypeMappingInfo[] getTypeMappingInfos() throws Exception {
if (typeMappingInfos == null) {
typeMappingInfos = new TypeMappingInfo[6];
TypeMappingInfo tmi = new TypeMappingInfo();
tmi.setXmlTagName(new QName("someUri", "testTagName1"));
tmi.setElementScope(ElementScope.Global);
tmi.setType(getClass().getField("testField").getGenericType());
typeMappingInfos[0] = tmi;
TypeMappingInfo tmi2 = new TypeMappingInfo();
tmi2.setXmlTagName(new QName("someUri", "testTagName2"));
tmi2.setElementScope(ElementScope.Global);
tmi2.setType(getClass().getField("testField").getGenericType());
typeMappingInfos[1] = tmi2;
TypeMappingInfo tmi3 = new TypeMappingInfo();
tmi3.setXmlTagName(new QName("someUri", "testTagName3"));
tmi3.setElementScope(ElementScope.Global);
tmi3.setType(List.class);
Element xmlElement = getXmlElement("<xml-element type='org.eclipse.persistence.testing.jaxb.typemappinginfo.Employee' />");
tmi3.setXmlElement(xmlElement);
typeMappingInfos[2] = tmi3;
TypeMappingInfo tmi4 = new TypeMappingInfo();
tmi4.setXmlTagName(new QName("someUri", "testTagName4"));
tmi4.setElementScope(ElementScope.Global);
tmi4.setType(getClass().getField("testSimpleField").getGenericType());
typeMappingInfos[3] = tmi4;
TypeMappingInfo tmi5 = new TypeMappingInfo();
tmi5.setXmlTagName(new QName("someUri", "testTagName5"));
tmi5.setElementScope(ElementScope.Global);
tmi5.setType(getClass().getField("testSimpleField").getGenericType());
Element xmlElement2 = getXmlElement("<xml-element xml-list='true'/>");
tmi5.setXmlElement(xmlElement2);
typeMappingInfos[4] = tmi5;
TypeMappingInfo tmi6 = new TypeMappingInfo();
tmi6.setXmlTagName(new QName("someUri", "testTagName6"));
tmi6.setElementScope(ElementScope.Global);
tmi6.setType(getClass().getField("testSimpleField").getGenericType());
Annotation[] annotations = getClass().getField("xmlListAnnotationField").getAnnotations();
tmi6.setAnnotations(annotations);
typeMappingInfos[5] = tmi6;
}
return typeMappingInfos;
}
use of org.eclipse.persistence.jaxb.TypeMappingInfo in project eclipselink by eclipse-ee4j.
the class ArrayWithAnnotationsTestCases method getTypeMappingInfos.
protected TypeMappingInfo[] getTypeMappingInfos() throws Exception {
if (typeMappingInfos == null) {
typeMappingInfos = new TypeMappingInfo[1];
TypeMappingInfo ti = new TypeMappingInfo();
ti.setXmlTagName(XML_TAG_NAME);
ti.setType(Float[].class);
ti.setElementScope(ElementScope.Global);
Field fld = getClass().getField("f");
ti.setAnnotations(fld.getAnnotations());
typeMappingInfos[0] = ti;
}
return typeMappingInfos;
}
Aggregations