use of org.glassfish.jaxb.runtime.api.JAXBRIContext in project metro-jax-ws by eclipse-ee4j.
the class JAXBTest method testJAXBElementMarshalling.
public void testJAXBElementMarshalling() throws Exception {
JAXBRIContext jc = (JAXBRIContext) JAXBContext.newInstance(whitebox.jaxb.client.DetailType.class);
DetailType dt = new DetailType();
SOAPFault sf = createFault();
dt.getDetails().add(sf.getDetail());
Marshaller m = jc.createMarshaller();
m.marshal(dt, System.out);
XMLStreamBufferResult sbr = new XMLStreamBufferResult();
m.setProperty(Marshaller.JAXB_FRAGMENT, true);
m.marshal(dt, sbr);
XMLStreamBuffer infoset = sbr.getXMLStreamBuffer();
XMLStreamReader reader = infoset.readAsXMLStreamReader();
if (reader.getEventType() == START_DOCUMENT)
XMLStreamReaderUtil.nextElementContent(reader);
verifyDetail(reader);
}
use of org.glassfish.jaxb.runtime.api.JAXBRIContext in project jaxb-ri by eclipse-ee4j.
the class CompositeStructureTest method test1.
// this annotation is just so that we can pass it to tr4.
@XmlJavaTypeAdapter(HexBinaryAdapter.class)
public void test1() throws Exception {
TypeReference tr1 = new TypeReference(new QName("", "foo"), String.class);
TypeReference tr2 = new TypeReference(new QName("", "bar"), int.class);
TypeReference tr3 = new TypeReference(new QName("", "zot"), byte[].class);
TypeReference tr4 = new TypeReference(new QName("", "zoo"), byte[].class, this.getClass().getMethod("test1").getAnnotation(XmlJavaTypeAdapter.class));
JAXBRIContext c = JAXBRIContext.newInstance(new Class[0], Arrays.asList(tr1, tr2, tr3, tr4), "", false);
CompositeStructure cs = new CompositeStructure();
cs.bridges = new Bridge[] { c.createBridge(tr1), c.createBridge(tr2), c.createBridge(tr3), c.createBridge(tr4) };
cs.values = new Object[] { "foo", 5, new byte[4], new byte[4] };
JAXBElement<CompositeStructure> root = new JAXBElement<>(new QName("", "root"), CompositeStructure.class, cs);
StringWriter sw = new StringWriter();
c.createMarshaller().marshal(root, System.out);
c.createMarshaller().marshal(root, sw);
assertTrue(sw.toString().contains("<root><foo>foo</foo><bar>5</bar><zot>AAAAAA==</zot><zoo>00000000</zoo></root>"));
}
use of org.glassfish.jaxb.runtime.api.JAXBRIContext in project metro-jax-ws by eclipse-ee4j.
the class JAXBRIContextFactory method newContext.
@Override
public BindingContext newContext(BindingInfo bi) {
Class[] classes = bi.contentClasses().toArray(new Class[0]);
for (int i = 0; i < classes.length; i++) {
if (WrapperComposite.class.equals(classes[i])) {
classes[i] = CompositeStructure.class;
}
}
Map<TypeInfo, TypeReference> typeInfoMappings = typeInfoMappings(bi.typeInfos());
Map<Class, Class> subclassReplacements = bi.subclassReplacements();
String defaultNamespaceRemap = bi.getDefaultNamespace();
Boolean c14nSupport = (Boolean) bi.properties().get("c14nSupport");
RuntimeAnnotationReader ar = (RuntimeAnnotationReader) bi.properties().get("org.glassfish.jaxb.runtime.v2.model.annotation.RuntimeAnnotationReader");
JAXBContextFactory jaxbContextFactory = (JAXBContextFactory) bi.properties().get(JAXBContextFactory.class.getName());
try {
JAXBRIContext context = (jaxbContextFactory != null) ? jaxbContextFactory.createJAXBContext(bi.getSEIModel(), toList(classes), toList(typeInfoMappings.values())) : ContextFactory.createContext(classes, typeInfoMappings.values(), subclassReplacements, defaultNamespaceRemap, (c14nSupport != null) ? c14nSupport : false, ar, false, false, false);
return new JAXBRIContextWrapper(context, typeInfoMappings);
} catch (Exception e) {
throw new DatabindingException(e);
}
}
Aggregations