protected void addFormValue(MultivaluedMap<String, String> form, String name, Object pValue, Annotation[] anns) { if (pValue != null) { if (InjectionUtils.isSupportedCollectionOrArray(pValue.getClass())) { Collection<?> c = pValue.getClass().isArray() ? Arrays.asList((Object[]) pValue) : (Collection<?>) pValue; for (Iterator<?> it = c.iterator(); it.hasNext();) { FormUtils.addPropertyToForm(form, name, convertParamValue(it.next(), anns)); } } else { FormUtils.addPropertyToForm(form, name, name.isEmpty() ? pValue : convertParamValue(pValue, anns)); } } }
protected void addFormValue(MultivaluedMap<String, String> form, String name, Object pValue, Annotation[] anns) { if (pValue != null) { if (InjectionUtils.isSupportedCollectionOrArray(pValue.getClass())) { Collection<?> c = pValue.getClass().isArray() ? Arrays.asList((Object[]) pValue) : (Collection<?>) pValue; for (Iterator<?> it = c.iterator(); it.hasNext();) { FormUtils.addPropertyToForm(form, name, convertParamValue(it.next(), anns)); } } else { FormUtils.addPropertyToForm(form, name, name.isEmpty() ? pValue : convertParamValue(pValue, anns)); } } }
private void addFormValue(MultivaluedMap<String, String> form, String name, Object pValue, Annotation[] anns) { if (pValue != null) { if (InjectionUtils.isSupportedCollectionOrArray(pValue.getClass())) { Collection<?> c = pValue.getClass().isArray() ? Arrays.asList((Object[]) pValue) : (Collection<?>) pValue; for (Iterator<?> it = c.iterator(); it.hasNext();) { FormUtils.addPropertyToForm(form, name, convertParamValue(it.next(), anns)); } } else { FormUtils.addPropertyToForm(form, name, name.isEmpty() ? pValue : convertParamValue(pValue, anns)); } } }
private void doWriteBeanParam(StringBuilder sb, Class<?> type, Parameter pm, String parentName, List<Class<?>> parentBeanClasses, boolean isJson) { Map<Parameter, Class<?>> pms = InjectionUtils.getParametersFromBeanClass(type, pm.getType(), true); for (Map.Entry<Parameter, Class<?>> entry : pms.entrySet()) { String name = entry.getKey().getName(); if (parentName != null) { name = parentName + "." + name; } Class<?> paramCls = entry.getValue(); boolean isPrimitive = InjectionUtils.isPrimitive(paramCls) || paramCls.isEnum(); if (isPrimitive || Date.class.isAssignableFrom(paramCls) || InjectionUtils.isSupportedCollectionOrArray(paramCls)) { doWriteParam(sb, entry.getKey(), paramCls, paramCls, name, new Annotation[] {}, isJson); } else if (!parentBeanClasses.contains(paramCls)) { parentBeanClasses.add(paramCls); doWriteBeanParam(sb, paramCls, entry.getKey(), name, parentBeanClasses, isJson); parentBeanClasses.remove(paramCls); } } }
@Override public boolean isReadable(Class<?> type, Type genericType, Annotation[] anns, MediaType mt) { if (!super.isReadable(type, genericType, anns, mt)) { return false; } if (InjectionUtils.isSupportedCollectionOrArray(type)) { return supportJaxbOnly; } // if the user has set the list of in classes and a given class // is in that list then it can only be handled by the template if (inClassCanBeHandled(type.getName()) || inClassesToHandle == null && !supportJaxbOnly) { return inTemplatesAvailable(type, anns, mt); } return supportJaxbOnly; }
@Override public boolean isWriteable(Class<?> type, Type genericType, Annotation[] anns, MediaType mt) { // JAXB support is required if (!super.isWriteable(type, genericType, anns, mt)) { return false; } if (InjectionUtils.isSupportedCollectionOrArray(type)) { return supportJaxbOnly; } // if the user has set the list of out classes and a given class // is in that list then it can only be handled by the template if (outClassCanBeHandled(type.getName()) || outClassesToHandle == null && !supportJaxbOnly) { return outTemplatesAvailable(type, anns, mt); } return supportJaxbOnly; }
@Override public boolean isReadable(Class<?> type, Type genericType, Annotation[] anns, MediaType mt) { if (!super.isReadable(type, genericType, anns, mt)) { return false; } if (InjectionUtils.isSupportedCollectionOrArray(type)) { return supportJaxbOnly; } // if the user has set the list of in classes and a given class // is in that list then it can only be handled by the template if (inClassCanBeHandled(type.getName()) || inClassesToHandle == null && !supportJaxbOnly) { return inTemplatesAvailable(mt); } else { return supportJaxbOnly; } }
public boolean isReadable(Class<?> type, Type genericType, Annotation[] anns, MediaType mt) { if (InjectionUtils.isSupportedCollectionOrArray(type)) { type = InjectionUtils.getActualType(genericType); if (type == null) { return false; } } return canBeReadAsJaxbElement(type) || isSupported(type, genericType, anns); }
@Override public boolean isWriteable(Class<?> type, Type genericType, Annotation[] anns, MediaType mt) { // JAXB support is required if (!super.isWriteable(type, genericType, anns, mt)) { return false; } if (InjectionUtils.isSupportedCollectionOrArray(type)) { return supportJaxbOnly; } // if the user has set the list of out classes and a given class // is in that list then it can only be handled by the template if (outClassCanBeHandled(type.getName()) || outClassesToHandle == null && !supportJaxbOnly) { return outTemplatesAvailable(mt); } else { return supportJaxbOnly; } }
public boolean isWriteable(Class<?> type, Type genericType, Annotation[] anns, MediaType mt) { if (InjectionUtils.isSupportedCollectionOrArray(type)) { type = InjectionUtils.getActualType(genericType); if (type == null) { return false; } } return marshalAsJaxbElement && (!xmlTypeAsJaxbElementOnly || isXmlType(type)) || isSupported(type, genericType, anns); } public void writeTo(T t, Type genericType, Annotation[] annotations,
public boolean isWriteable(Class<?> type, Type genericType, Annotation[] anns, MediaType mt) { if (InjectionUtils.isSupportedCollectionOrArray(type)) { type = InjectionUtils.getActualType(genericType); if (type == null) { return false; } } return marshalAsJaxbElement && (!xmlTypeAsJaxbElementOnly || isXmlType(type)) || isSupported(type, genericType, anns); } public void writeTo(T t, Type genericType, Annotation annotations[],
public boolean isReadable(Class<?> type, Type genericType, Annotation[] anns, MediaType mt) { if (InjectionUtils.isSupportedCollectionOrArray(type)) { type = InjectionUtils.getActualType(genericType); if (type == null) { return false; } } return canBeReadAsJaxbElement(type) || isSupported(type, genericType, anns); }
public static Type processGenericTypeIfNeeded(Class<?> serviceCls, Class<?> paramCls, Type type) { if (type instanceof TypeVariable) { type = InjectionUtils.getSuperType(serviceCls, (TypeVariable<?>)type); } else if (type instanceof ParameterizedType && ((ParameterizedType)type).getActualTypeArguments()[0] instanceof TypeVariable && isSupportedCollectionOrArray(getRawType(type))) { TypeVariable<?> typeVar = (TypeVariable<?>)((ParameterizedType)type).getActualTypeArguments()[0]; Type theType = InjectionUtils.getSuperType(serviceCls, typeVar); Class<?> cls = theType instanceof Class ? (Class<?>)theType : InjectionUtils.getActualType(theType, 0); type = new ParameterizedCollectionType(cls); } if (type == null || type == Object.class) { type = paramCls; } return type; }
public void writeTo(T obj, Class<?> cls, Type genericType, Annotation[] anns, MediaType m, MultivaluedMap<String, Object> headers, OutputStream os) throws IOException { try { String encoding = HttpUtils.getSetEncoding(m, headers, StandardCharsets.UTF_8.name()); if (InjectionUtils.isSupportedCollectionOrArray(cls)) { marshalCollection(cls, obj, genericType, encoding, os, m, anns); } else { Object actualObject = checkAdapter(obj, cls, anns, true); Class<?> actualClass = obj != actualObject || cls.isInterface() ? actualObject.getClass() : cls; marshal(actualObject, actualClass, genericType, encoding, os, m, anns); } } catch (JAXBException e) { handleJAXBException(e, false); } catch (WebApplicationException e) { throw e; } catch (Exception e) { LOG.warning(ExceptionUtils.getStackTrace(e)); throw ExceptionUtils.toInternalServerErrorException(e, null); } }
@Override protected XMLStreamReader createReader(Class<?> type, Type genericType, InputStream is) throws Exception { if (!InjectionUtils.isSupportedCollectionOrArray(type)) { getQName(type); } else { getQName(InjectionUtils.getActualType(genericType)); } return JSONUtils.createStreamReader(is, readXsiType, namespaceMap); }
public static Type processGenericTypeIfNeeded(Class<?> serviceCls, Class<?> paramCls, Type type) { if (type instanceof TypeVariable) { type = InjectionUtils.getSuperType(serviceCls, (TypeVariable<?>)type); } else if (type instanceof ParameterizedType) { ParameterizedType pt = (ParameterizedType)type; if (pt.getActualTypeArguments()[0] instanceof TypeVariable && isSupportedCollectionOrArray(getRawType(pt))) { TypeVariable<?> typeVar = (TypeVariable<?>)pt.getActualTypeArguments()[0]; Type theType = InjectionUtils.getSuperType(serviceCls, typeVar); if (theType instanceof Class) { type = new ParameterizedCollectionType((Class<?>)theType); } else { type = processGenericTypeIfNeeded(serviceCls, paramCls, theType); type = new ParameterizedCollectionType(type); } } } if (type == null || type == Object.class) { type = paramCls; } return type; }
public void writeTo(T obj, Class<?> cls, Type genericType, Annotation[] anns, MediaType m, MultivaluedMap<String, Object> headers, OutputStream os) throws IOException { try { String encoding = HttpUtils.getSetEncoding(m, headers, null); if (InjectionUtils.isSupportedCollectionOrArray(cls)) { marshalCollection(cls, obj, genericType, encoding, os, m, anns); } else { Object actualObject = checkAdapter(obj, cls, anns, true); Class<?> actualClass = obj != actualObject || cls.isInterface() ? actualObject.getClass() : cls; marshal(actualObject, actualClass, genericType, encoding, os, m, anns); } } catch (JAXBException e) { handleJAXBException(e, false); } catch (WebApplicationException e) { throw e; } catch (Exception e) { LOG.warning(ExceptionUtils.getStackTrace(e)); throw ExceptionUtils.toInternalServerErrorException(e, null); } }
protected XMLStreamReader getStreamReader(InputStream is, Class<?> type, MediaType mt) { MessageContext mc = getContext(); XMLStreamReader reader = mc != null ? mc.getContent(XMLStreamReader.class) : null; if (reader == null && mc != null) { XMLInputFactory factory = (XMLInputFactory)mc.get(XMLInputFactory.class.getName()); if (factory != null) { try { reader = factory.createXMLStreamReader(is); } catch (XMLStreamException e) { throw ExceptionUtils.toInternalServerErrorException( new RuntimeException("Can not create XMLStreamReader", e), null); } } } if (reader == null && is == null) { reader = getStreamHandlerFromCurrentMessage(XMLStreamReader.class); } reader = createTransformReaderIfNeeded(reader, is); reader = createDepthReaderIfNeeded(reader, is); if (InjectionUtils.isSupportedCollectionOrArray(type)) { return new JAXBCollectionWrapperReader(TransformUtils.createNewReaderIfNeeded(reader, is)); } return reader; }
@Override public Representation handleResponseRepresentation(final ClassResourceInfo cri, final OperationResourceInfo ori, final Class<?> type, final MediaType mediaType) { final Representation representation = getNext().handleResponseRepresentation(cri, ori, type, mediaType); if (representation == null || definition == null) { return null; } final boolean isCollection = InjectionUtils.isSupportedCollectionOrArray(type); Class<?> theActualType = type; java.lang.reflect.Method opMethod = getMethod(ori); if (isCollection) { theActualType = InjectionUtils.getActualType(opMethod.getGenericReturnType()); } else { theActualType = ResourceUtils.getActualJaxbType(type, opMethod, false); } final QName name = definition.resolve(theActualType); if (name != null) { representation.setElement(name); } return representation; }
@Override protected XMLStreamWriter createWriter(Class<?> type, Type genericType, String enc, OutputStream os) throws Exception { QName qname = null; if (!InjectionUtils.isSupportedCollectionOrArray(type)) { qname = getQName(type); } else { qname = getQName(InjectionUtils.getActualType(genericType)); } Configuration config = JSONUtils.createConfiguration(namespaceMap, writeXsiType && !ignoreNamespaces, false, null); XMLStreamWriter writer = JSONUtils.createStreamWriter(os, qname, writeXsiType && !ignoreNamespaces, config, serializeAsArray, arrayKeys, dropRootElement, enc); writer = JSONUtils.createIgnoreMixedContentWriterIfNeeded(writer, ignoreMixedContent); return JSONUtils.createIgnoreNsWriterIfNeeded(writer, ignoreNamespaces, !writeXsiType); }