use of javax.xml.bind.Marshaller in project jersey by jersey.
the class AbstractJaxbProvider method getMarshaller.
/**
* Get the JAXB marshaller for the given class and media type.
* <p>
* In case this provider instance has been {@link #AbstractJaxbProvider(Providers, MediaType)
* created with a fixed resolver media type}, the supplied media type argument will be ignored.
* </p>
*
* @param type Java type to be marshalled.
* @param mediaType entity media type.
* @return JAXB marshaller for the requested Java type, media type combination.
* @throws JAXBException in case retrieving the marshaller fails with a JAXB exception.
*/
protected final Marshaller getMarshaller(Class type, MediaType mediaType) throws JAXBException {
if (fixedResolverMediaType) {
return getMarshaller(type);
}
final ContextResolver<Marshaller> mcr = jaxrsProviders.getContextResolver(Marshaller.class, mediaType);
if (mcr != null) {
Marshaller m = mcr.getContext(type);
if (m != null) {
return m;
}
}
final JAXBContext ctx = getJAXBContext(type, mediaType);
if (ctx == null) {
return null;
}
Marshaller m = ctx.createMarshaller();
if (formattedOutput.get()) {
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, formattedOutput.get());
}
return m;
}
use of javax.xml.bind.Marshaller in project jersey by jersey.
the class AbstractJaxbProvider method getMarshaller.
private Marshaller getMarshaller(Class type) throws JAXBException {
final ContextResolver<Marshaller> resolver = mtMarshaller.get();
if (resolver != null) {
Marshaller u = resolver.getContext(type);
if (u != null) {
return u;
}
}
final JAXBContext ctx = getJAXBContext(type);
if (ctx == null) {
return null;
}
Marshaller m = ctx.createMarshaller();
if (formattedOutput.get()) {
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, formattedOutput.get());
}
return m;
}
use of javax.xml.bind.Marshaller in project quickstarts by jboss-switchyard.
the class Library method toString.
public String toString(boolean detailed) {
StringWriter sw = new StringWriter();
synchronized (librarian) {
try {
if (detailed) {
JAXBContext ctx = JAXBContext.newInstance("org.switchyard.quickstarts.demos.library.types");
Marshaller m = ctx.createMarshaller();
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
m.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
ObjectFactory of = new ObjectFactory();
for (Book book : isbns_to_books.values()) {
int quantity = isbns_to_quantities.get(book.getIsbn());
sw.write("\nBook (quantity=" + quantity + ")\n");
m.marshal(of.createBook(book), sw);
sw.write('\n');
}
} else {
for (Book book : isbns_to_books.values()) {
int quantity = isbns_to_quantities.get(book.getIsbn());
sw.write(book.getTitle() + " (" + quantity + ")\n");
}
}
} catch (Throwable t) {
t.printStackTrace();
}
}
return sw.toString().trim();
}
use of javax.xml.bind.Marshaller in project quickstarts by jboss-switchyard.
the class LibraryClient method wrapRequest.
private <T> String wrapRequest(QName name, Class<T> declaredType, T value, String pid) throws Exception {
JAXBElement<T> e = new JAXBElement<T>(name, declaredType, null, value);
JAXBContext ctx = JAXBContext.newInstance("org.switchyard.quickstarts.demos.library.types");
Marshaller m = ctx.createMarshaller();
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
m.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
StringWriter sw = new StringWriter();
String processInstanceId = pid != null ? "<bpm:processInstanceId xmlns:bpm='urn:switchyard-component-bpm:bpm:1.0'>" + pid + "</bpm:processInstanceId>" : "";
sw.write(SOAP_REQUEST_PREFIX.replaceFirst("PID", processInstanceId));
m.marshal(e, sw);
sw.write(SOAP_REQUEST_SUFFIX);
return sw.toString();
}
use of javax.xml.bind.Marshaller in project jersey by jersey.
the class WadlGeneratorResourceDocSupportTest method wadlIsGeneratedWithUnknownCustomParameterAnnotation.
@Test
public void wadlIsGeneratedWithUnknownCustomParameterAnnotation() throws JAXBException {
/* Set up a ClassDocType that has something for a custom-annotated parameter */
ClassDocType cdt = new ClassDocType();
cdt.setClassName(TestResource.class.getName());
MethodDocType mdt = new MethodDocType();
mdt.setMethodName("method");
cdt.getMethodDocs().add(mdt);
ParamDocType pdt = new ParamDocType("x", "comment about x");
mdt.getParamDocs().add(pdt);
AnnotationDocType adt = new AnnotationDocType();
adt.setAnnotationTypeName(CustomParam.class.getName());
adt.getAttributeDocs().add(new NamedValueType("value", "x"));
pdt.getAnnotationDocs().add(adt);
ResourceDocType rdt = new ResourceDocType();
rdt.getDocs().add(cdt);
/* Generate WADL for that class */
WadlGenerator wg = new WadlGeneratorResourceDocSupport(new WadlGeneratorImpl(), rdt);
WadlBuilder wb = new WadlBuilder(wg, false, null);
Resource resource = Resource.from(TestResource.class);
ApplicationDescription app = wb.generate(Collections.singletonList(resource));
/* Confirm that it can be marshalled without error */
StringWriter sw = new StringWriter();
JAXBContext context = JAXBContext.newInstance(Application.class);
Marshaller m = context.createMarshaller();
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
m.marshal(app.getApplication(), sw);
}
Aggregations