Ejemplo n.º 1
0
 /**
  * Nillable is only allowed if the actual property is Nullable
  *
  * @param name
  * @return
  */
 public boolean isNillable(QName name) {
   AegisType type = getType(name);
   if (!type.isNillable()) {
     return false;
   }
   return nillable;
 }
Ejemplo n.º 2
0
  public ArrayTypeInfo(MessageReader reader, TypeMapping tm) {
    this(
        reader.getXMLStreamReader().getNamespaceContext(),
        readAttributeValue(reader, SOAP_ARRAY_TYPE),
        readAttributeValue(reader, SOAP_ARRAY_OFFSET));

    // if type is xsd:ur-type replace it with xsd:anyType
    String namespace = reader.getNamespaceForPrefix(typeName.getPrefix());
    if (!StringUtils.isEmpty(namespace)) {
      if (SOAPConstants.XSD.equals(namespace) && "ur-type".equals(typeName.getLocalPart())) {
        typeName = new QName(namespace, "anyType", typeName.getPrefix());
      } else {
        typeName = new QName(namespace, typeName.getLocalPart(), typeName.getPrefix());
      }
    }

    if (tm != null) {
      type = tm.getType(typeName);

      if (ranks > 0) {
        Class<?> componentType = type.getTypeClass();
        for (int i = 1; i < ranks + dimensions.size(); i++) {
          componentType = Array.newInstance(componentType, 0).getClass();
        }

        SoapArrayType arrayType = new SoapArrayType();
        arrayType.setTypeClass(componentType);
        arrayType.setTypeMapping(type.getTypeMapping());
        type = arrayType;
      }
    }
  }
Ejemplo n.º 3
0
  public void write(Object obj, MessagePartInfo part, Element output) {
    AegisType type = databinding.getType(part);

    if (type == null) {
      throw new Fault(new Message("NO_MESSAGE_FOR_PART", LOG));
    }

    Context context = new Context(databinding.getAegisContext());

    context.setAttachments(attachments);
    type = TypeUtil.getWriteType(databinding.getAegisContext(), obj, type);
    try {
      W3CDOMStreamWriter domWriter = new W3CDOMStreamWriter(output);
      ElementWriter writer = new ElementWriter(domWriter);
      MessageWriter w2 = writer.getElementWriter(part.getConcreteName());
      if (type.isNillable() && type.isWriteOuter() && obj == null) {
        w2.writeXsiNil();
        w2.close();
        return;
      }

      type.writeObject(obj, w2, context);
      w2.close();
    } catch (DatabindingException e) {
      throw new RuntimeException(e);
    }
  }
Ejemplo n.º 4
0
 @Override
 protected XMLStreamReader createStreamReader(AegisType typeToRead, InputStream is)
     throws Exception {
   // the namespace map. Oh, the namespace map.
   // This is wrong, but might make unit tests pass until we redesign.
   if (typeToRead != null) {
     namespaceMap.putIfAbsent(typeToRead.getSchemaType().getNamespaceURI(), "ns1");
   }
   return JSONUtils.createStreamReader(is, readXsiType, namespaceMap);
 }
Ejemplo n.º 5
0
  @Override
  public void writeTo(
      T obj,
      Class<?> type,
      Type genericType,
      Annotation[] anns,
      MediaType m,
      MultivaluedMap<String, Object> headers,
      OutputStream os)
      throws IOException {
    if (type == null) {
      type = obj.getClass();
    }
    if (genericType == null) {
      genericType = type;
    }
    AegisContext context = getAegisContext(type, genericType);
    AegisType aegisType = context.getTypeMapping().getType(genericType);
    AegisWriter<XMLStreamWriter> aegisWriter = context.createXMLStreamWriter();
    try {
      W3CDOMStreamWriter w3cStreamWriter = new W3CDOMStreamWriter();
      XMLStreamWriter spyingWriter =
          new PrefixCollectingXMLStreamWriter(w3cStreamWriter, namespaceMap);
      spyingWriter.writeStartDocument();
      // use type qname as element qname?
      aegisWriter.write(obj, aegisType.getSchemaType(), false, spyingWriter, aegisType);
      spyingWriter.writeEndDocument();
      spyingWriter.close();
      Document dom = w3cStreamWriter.getDocument();
      // ok, now the namespace map has all the prefixes.

      XMLStreamWriter xmlStreamWriter = createStreamWriter(aegisType.getSchemaType(), os);
      xmlStreamWriter.writeStartDocument();
      StaxUtils.copy(dom, xmlStreamWriter);
      // Jettison needs, and StaxUtils.copy doesn't do it.
      xmlStreamWriter.writeEndDocument();
      xmlStreamWriter.flush();
      xmlStreamWriter.close();
    } catch (Exception e) {
      throw new WebApplicationException(e);
    }
  }