示例#1
0
  // CHECKSTYLE:OFF
  protected void marshalCollectionMember(
      Object obj,
      Class<?> cls,
      Type genericType,
      String enc,
      OutputStream os,
      Annotation[] anns,
      MediaType mt,
      String ns)
      throws Exception {
    // CHECKSTYLE:ON
    if (!(obj instanceof JAXBElement)) {
      obj = convertToJaxbElementIfNeeded(obj, cls, genericType);
    }

    if (obj instanceof JAXBElement && cls != JAXBElement.class) {
      cls = JAXBElement.class;
    }

    Marshaller ms = createMarshaller(obj, cls, genericType, enc);
    ms.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
    if (ns.length() > 0) {
      Map<String, String> map = new HashMap<String, String>();
      // set the default just in case
      if (!nsPrefixes.containsKey(ns)) {
        map.put(ns, "ns1");
      }
      map.putAll(nsPrefixes);
      setNamespaceMapper(ms, map);
    }
    marshal(obj, cls, genericType, enc, os, anns, mt, ms);
  }
示例#2
0
 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);
   }
 }
示例#3
0
  protected void marshal(
      Object obj,
      Class<?> cls,
      Type genericType,
      String enc,
      OutputStream os,
      MediaType mt,
      Annotation[] anns)
      throws Exception {
    obj = convertToJaxbElementIfNeeded(obj, cls, genericType);
    if (obj instanceof JAXBElement && cls != JAXBElement.class) {
      cls = JAXBElement.class;
    }

    Marshaller ms = createMarshaller(obj, cls, genericType, enc);
    if (!nsPrefixes.isEmpty()) {
      setNamespaceMapper(ms, nsPrefixes);
    }
    addAttachmentMarshaller(ms);
    processXmlAnnotations(ms, mt, anns);
    marshal(obj, cls, genericType, enc, os, anns, mt, ms);
  }
示例#4
0
 protected void marshal(
     Object obj, Class<?> cls, Type genericType, String enc, OutputStream os, MediaType mt)
     throws Exception {
   marshal(obj, cls, genericType, enc, os, mt, new Annotation[] {});
 }