/** * Attempts to locate {@link XmlRegistry} for the XML type. Usually, a class named ObjectFactory is located * in the same package as the type we're trying to marshall. This method simply locates this class and * instantiates it if found. * * @param type type class * @return object factory instance */ public static Object findObjectFactory(Class<?> type) { try { Class<?> factoryClass = AbstractJAXBContextFinder.findDefaultObjectFactoryClass(type); if (factoryClass != null && factoryClass.isAnnotationPresent(XmlRegistry.class)) { return factoryClass.newInstance(); } else { throw new JAXBMarshalException(Messages.MESSAGES.validXmlRegistryCouldNotBeLocated()); } } catch (InstantiationException | IllegalAccessException e) { throw new JAXBMarshalException(e); } }
@Override public Response toResponse(JAXBMarshalException exception) { Status status = Response.Status.INTERNAL_SERVER_ERROR; if (exception.getResponse() != null) { status = Response.Status.fromStatusCode( exception.getResponse().getStatus()); } return getDefaultBuilder(exception, status, determineBestMediaType()).build(); }
throw new JAXBMarshalException(Messages.MESSAGES.createMethodNotFound(type)); throw new JAXBMarshalException(e); throw new JAXBMarshalException(e.getCause());
public void writeTo(T t, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream outputStream) throws IOException { try { LogMessages.LOGGER.debugf("Provider : %s, Method : writeTo", getClass().getName()); Marshaller marshaller = getMarshaller(type, annotations, mediaType); marshaller = decorateMarshaller(type, annotations, mediaType, marshaller); marshaller.marshal(t, outputStream); } catch (JAXBException e) { throw new JAXBMarshalException(e); } }
@SuppressWarnings("unchecked") protected static XmlAdapterWrapper getXmlAdapter(Class<?> baseType, Annotation[] annotations) { if (baseType.isAnnotationPresent(XmlJavaTypeAdapter.class)) { XmlJavaTypeAdapter xmlJavaTypeAdapter = FindAnnotation.findAnnotation(baseType, annotations, XmlJavaTypeAdapter.class); Class<? extends XmlAdapter> adapterClass = xmlJavaTypeAdapter.value(); ParameterizedType xmlAdapterType = ParameterizedType.class.cast(adapterClass.getGenericSuperclass()); Class<?> boundType = Types.getArgumentType(xmlAdapterType, 1); if (boundType.isAssignableFrom(baseType)) { try { Class<?> valueType = Types.getArgumentType(xmlAdapterType, 0); return new XmlAdapterWrapper(adapterClass.newInstance(), valueType); } catch (Exception e) { throw new JAXBMarshalException(e); } } } return null; } }
throw new JAXBMarshalException(e);
throw new JAXBMarshalException(Messages.MESSAGES.unableToMarshal(mediaType), e);
throw new JAXBMarshalException(Messages.MESSAGES.unableToMarshal(mediaType), e);
if (finder == null) throw new JAXBMarshalException(Messages.MESSAGES.unableToFindJAXBContext(mediaType)); throw new JAXBMarshalException(e); throw new JAXBMarshalException(e);
@Override public JAXBContext findJAXBContext(Class<?> type, Annotation[] annotations, MediaType mediaType, boolean reader) throws JAXBException { ContextResolver<JAXBContextFinder> resolver = providers.getContextResolver(JAXBContextFinder.class, mediaType); JAXBContextFinder finder = resolver.getContext(type); if (finder == null) { if (reader) throw new JAXBUnmarshalException(Messages.MESSAGES.couldNotFindJAXBContextFinder(mediaType)); else throw new JAXBMarshalException(Messages.MESSAGES.couldNotFindJAXBContextFinder(mediaType)); } XmlSeeAlso seeAlso = type.getAnnotation(XmlSeeAlso.class); return finder.findCacheContext(mediaType, annotations, seeAlso.value()); }
public JAXBContext findJAXBContext(Class<?> type, Annotation[] annotations, MediaType mediaType, boolean reader) throws JAXBException { ContextResolver<JAXBContextFinder> resolver = providers.getContextResolver(JAXBContextFinder.class, mediaType); JAXBContextFinder finder = resolver.getContext(type); if (finder == null) { if (reader) throw new JAXBUnmarshalException(Messages.MESSAGES.couldNotFindJAXBContextFinder(mediaType)); else throw new JAXBMarshalException(Messages.MESSAGES.couldNotFindJAXBContextFinder(mediaType)); } return finder.findCachedContext(type, mediaType, annotations); }
if (finder == null) throw new JAXBMarshalException(Messages.MESSAGES.unableToFindJAXBContext(mediaType)); throw new JAXBMarshalException(e);
/** * @see javax.ws.rs.ext.MessageBodyWriter#writeTo(java.lang.Object, java.lang.Class, * java.lang.reflect.Type, java.lang.annotation.Annotation[], javax.ws.rs.core.MediaType, * javax.ws.rs.core.MultivaluedMap, java.io.OutputStream) */ @Override public void writeTo(RDF t, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException { if (rdfContext == null) throw new JAXBMarshalException(Messages.i18n.format("UNABLE_TO_MARSHAL", mediaType), //$NON-NLS-1$ new NullPointerException(Messages.i18n.format("FAILED_TO_CREATE_ONT_JAXBCTX"))); //$NON-NLS-1$ try { rdfContext.createMarshaller().marshal(t, entityStream); } catch (JAXBException e) { throw new JAXBMarshalException(Messages.i18n.format("UNABLE_TO_MARSHAL", mediaType), e); //$NON-NLS-1$ } }
/** * @see javax.ws.rs.ext.MessageBodyWriter#writeTo(java.lang.Object, java.lang.Class, * java.lang.reflect.Type, java.lang.annotation.Annotation[], javax.ws.rs.core.MediaType, * javax.ws.rs.core.MultivaluedMap, java.io.OutputStream) */ @Override public void writeTo(AuditEntry t, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException { if (auditEntryContext == null) throw new JAXBMarshalException(Messages.i18n.format("UNABLE_TO_MARSHAL", mediaType), //$NON-NLS-1$ new NullPointerException(Messages.i18n.format("FAILED_TO_CREATE_AUDIT_JAXBCTX"))); //$NON-NLS-1$ try { auditEntryContext.createMarshaller().marshal(t, entityStream); } catch (JAXBException e) { throw new JAXBMarshalException(Messages.i18n.format("UNABLE_TO_MARSHAL", mediaType), e); //$NON-NLS-1$ } }
if (finder == null) throw new JAXBMarshalException(Messages.MESSAGES.unableToFindJAXBContext(mediaType));
public void writeTo(Feed feed, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException { JAXBContextFinder finder = getFinder(mediaType); if (finder == null) { throw new JAXBMarshalException("Unable to find JAXBContext for media type: " + mediaType); throw new JAXBMarshalException("Unable to marshal: " + mediaType, e);
if (finder == null) throw new JAXBMarshalException(Messages.MESSAGES.unableToFindJAXBContext(mediaType)); throw new JAXBMarshalException(e);
public void writeTo(Entry entry, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException { JAXBContextFinder finder = getFinder(mediaType); if (finder == null) { throw new JAXBMarshalException("Unable to find JAXBContext for media type: " + mediaType); throw new JAXBMarshalException("Unable to marshal: " + mediaType, e);
throw new JAXBMarshalException(Messages.MESSAGES.unableToMarshal(mediaType), e);
throw new JAXBMarshalException(Messages.MESSAGES.unableToMarshal(mediaType), e);