Search in sources :

Example 31 with DatabindingException

use of org.apache.cxf.aegis.DatabindingException in project cxf by apache.

the class MapType method readObject.

@Override
public Object readObject(MessageReader reader, Context context) throws DatabindingException {
    Map<Object, Object> map = instantiateMap();
    try {
        while (reader.hasMoreElementReaders()) {
            MessageReader entryReader = reader.getNextElementReader();
            if (entryReader.getName().equals(getEntryName())) {
                Object key = null;
                Object value = null;
                while (entryReader.hasMoreElementReaders()) {
                    MessageReader evReader = entryReader.getNextElementReader();
                    if (evReader.getName().equals(getKeyName())) {
                        AegisType kType = TypeUtil.getReadType(evReader.getXMLStreamReader(), context.getGlobalContext(), getKeyType());
                        key = kType.readObject(evReader, context);
                    } else if (evReader.getName().equals(getValueName())) {
                        AegisType vType = TypeUtil.getReadType(evReader.getXMLStreamReader(), context.getGlobalContext(), getValueType());
                        value = vType.readObject(evReader, context);
                    } else {
                        readToEnd(evReader);
                    }
                }
                map.put(key, value);
            } else {
                readToEnd(entryReader);
            }
        }
        return map;
    } catch (IllegalArgumentException e) {
        throw new DatabindingException("Illegal argument.", e);
    }
}
Also used : DatabindingException(org.apache.cxf.aegis.DatabindingException) AegisType(org.apache.cxf.aegis.type.AegisType) MessageReader(org.apache.cxf.aegis.xml.MessageReader)

Example 32 with DatabindingException

use of org.apache.cxf.aegis.DatabindingException in project cxf by apache.

the class AbstractEncodedTest method verifyInvalid.

public void verifyInvalid(String resourceName, Class<?> expectedType) throws XMLStreamException {
    AegisType type = mapping.getType(expectedType);
    assertNotNull("type is null", type);
    Context context = getContext();
    ElementReader reader = new ElementReader(getClass().getResourceAsStream(resourceName));
    try {
        type.readObject(reader, context);
        fail("expected DatabindingException");
    } catch (DatabindingException expected) {
    // expected
    } finally {
        reader.getXMLStreamReader().close();
    }
}
Also used : MapNamespaceContext(org.apache.cxf.helpers.MapNamespaceContext) Context(org.apache.cxf.aegis.Context) AegisContext(org.apache.cxf.aegis.AegisContext) DatabindingException(org.apache.cxf.aegis.DatabindingException) AegisType(org.apache.cxf.aegis.type.AegisType) ElementReader(org.apache.cxf.aegis.xml.stax.ElementReader)

Example 33 with DatabindingException

use of org.apache.cxf.aegis.DatabindingException in project cxf by apache.

the class SoapArrayType method writeObject.

@Override
public void writeObject(Object values, MessageWriter writer, Context context) throws DatabindingException {
    if (values == null) {
        return;
    }
    // ComponentType
    AegisType type = getComponentType();
    if (type == null) {
        throw new DatabindingException("Couldn't find component type for array.");
    }
    // Root component's schema type
    QName rootType = getRootType();
    String prefix = writer.getPrefixForNamespace(rootType.getNamespaceURI(), rootType.getPrefix());
    if (prefix == null) {
        prefix = "";
    }
    rootType = new QName(rootType.getNamespaceURI(), rootType.getLocalPart(), prefix);
    // write the soap arrayType attribute
    ArrayTypeInfo arrayTypeInfo = new ArrayTypeInfo(rootType, getDimensions() - 1, Array.getLength(values));
    // ensure that the writer writes out this prefix...
    writer.getPrefixForNamespace(arrayTypeInfo.getTypeName().getNamespaceURI(), arrayTypeInfo.getTypeName().getPrefix());
    arrayTypeInfo.writeAttribute(writer);
    // write each element
    for (int i = 0; i < Array.getLength(values); i++) {
        writeValue(Array.get(values, i), writer, context, type);
    }
}
Also used : DatabindingException(org.apache.cxf.aegis.DatabindingException) AegisType(org.apache.cxf.aegis.type.AegisType) QName(javax.xml.namespace.QName)

Example 34 with DatabindingException

use of org.apache.cxf.aegis.DatabindingException in project cxf by apache.

the class TrailingBlocks method readBlocks.

/**
 * Reads all remailing elements in the reader and registers them with the SoapRefRegistry in the context.
 *
 * @param reader the stream to read
 * @param context the unmarshal context
 * @return a list containing the object instances read
 * @throws DatabindingException if a trailing block element does not contain a soap id attribute
 */
public List<Object> readBlocks(MessageReader reader, Context context) throws DatabindingException {
    List<Object> blocks = new ArrayList<>();
    // read extra serialization roots
    while (reader.hasMoreElementReaders()) {
        MessageReader creader = reader.getNextElementReader();
        // read the instance id
        String id = SoapEncodingUtil.readId(creader);
        if (id == null) {
            throw new DatabindingException("Trailing block does not contain a SOAP id attribute " + creader.getName());
        }
        // read the instance
        Object instance = objectType.readObject(creader, context);
        blocks.add(instance);
        // register the instance
        SoapRefRegistry.get(context).addInstance(id, instance);
        // close the element reader
        creader.readToEnd();
    }
    return blocks;
}
Also used : DatabindingException(org.apache.cxf.aegis.DatabindingException) ArrayList(java.util.ArrayList) MessageReader(org.apache.cxf.aegis.xml.MessageReader)

Example 35 with DatabindingException

use of org.apache.cxf.aegis.DatabindingException in project cxf by apache.

the class AbstractXOPType method readInclude.

private Object readInclude(String type, MessageReader reader, Context context) throws DatabindingException {
    String href = reader.getAttributeReader(XOP_HREF).getValue().trim();
    Attachment att = AttachmentUtil.getAttachment(href, context.getAttachments());
    if (att == null) {
        throw new DatabindingException("Could not find the attachment " + href);
    }
    try {
        return readAttachment(att, context);
    } catch (IOException e) {
        throw new DatabindingException("Could not read attachment", e);
    }
}
Also used : DatabindingException(org.apache.cxf.aegis.DatabindingException) Attachment(org.apache.cxf.message.Attachment) IOException(java.io.IOException)

Aggregations

DatabindingException (org.apache.cxf.aegis.DatabindingException)38 AegisType (org.apache.cxf.aegis.type.AegisType)17 QName (javax.xml.namespace.QName)9 MessageReader (org.apache.cxf.aegis.xml.MessageReader)8 XMLStreamException (javax.xml.stream.XMLStreamException)6 PropertyDescriptor (java.beans.PropertyDescriptor)5 XMLStreamReader (javax.xml.stream.XMLStreamReader)4 Element (org.w3c.dom.Element)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 ArrayList (java.util.ArrayList)3 Context (org.apache.cxf.aegis.Context)3 TypeMapping (org.apache.cxf.aegis.type.TypeMapping)3 BeanTypeInfo (org.apache.cxf.aegis.type.basic.BeanTypeInfo)3 ElementReader (org.apache.cxf.aegis.xml.stax.ElementReader)3 Document (org.w3c.dom.Document)3 IntrospectionException (java.beans.IntrospectionException)2 Method (java.lang.reflect.Method)2 Collection (java.util.Collection)2 AegisContext (org.apache.cxf.aegis.AegisContext)2 MessageWriter (org.apache.cxf.aegis.xml.MessageWriter)2