Search in sources :

Example 36 with DatabindingException

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

the class XMLStreamReaderType method writeObject.

@Override
public void writeObject(Object object, MessageWriter writer, Context context) throws DatabindingException {
    XMLStreamReader reader = (XMLStreamReader) object;
    try {
        StaxUtils.copy(reader, ((ElementWriter) writer).getXMLStreamWriter());
        reader.close();
    } catch (XMLStreamException e) {
        throw new DatabindingException("Could not write xml.", e);
    }
}
Also used : DatabindingException(org.apache.cxf.aegis.DatabindingException) XMLStreamReader(javax.xml.stream.XMLStreamReader) XMLStreamException(javax.xml.stream.XMLStreamException)

Example 37 with DatabindingException

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

the class ElementReader method checkHasMoreChildReaders.

private boolean checkHasMoreChildReaders() {
    try {
        int event = root.getEventType();
        while (root.hasNext()) {
            switch(event) {
                case XMLStreamConstants.START_ELEMENT:
                    if (root.getDepth() > depth) {
                        hasCheckedChildren = true;
                        hasChildren = true;
                        return true;
                    }
                    break;
                case XMLStreamConstants.END_ELEMENT:
                    if (root.getDepth() < depth) {
                        hasCheckedChildren = true;
                        hasChildren = false;
                        if (root.hasNext()) {
                            root.next();
                        }
                        return false;
                    }
                    break;
                case XMLStreamConstants.END_DOCUMENT:
                    // We should never get here...
                    hasCheckedChildren = true;
                    hasChildren = false;
                    return false;
                default:
                    break;
            }
            if (root.hasNext()) {
                event = root.next();
            }
        }
        hasCheckedChildren = true;
        hasChildren = false;
        return false;
    } catch (XMLStreamException e) {
        throw new DatabindingException("Error parsing document.", e);
    }
}
Also used : DatabindingException(org.apache.cxf.aegis.DatabindingException) XMLStreamException(javax.xml.stream.XMLStreamException)

Example 38 with DatabindingException

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

the class NoDefaultConstructorBeanKeyType method readObject.

@Override
public Object readObject(MessageReader reader, Context context) throws DatabindingException {
    BeanTypeInfo inf = getTypeInfo();
    try {
        String key = null;
        // Read child elements
        while (reader.hasMoreElementReaders()) {
            MessageReader childReader = reader.getNextElementReader();
            if (childReader.isXsiNil()) {
                childReader.readToEnd();
                continue;
            }
            QName name = childReader.getName();
            AegisType defaultType = inf.getType(name);
            AegisType type = TypeUtil.getReadType(childReader.getXMLStreamReader(), context.getGlobalContext(), defaultType);
            if (type != null) {
                String value = (String) type.readObject(childReader, context);
                if ("key".equals(name.getLocalPart())) {
                    key = value;
                }
            } else {
                childReader.readToEnd();
            }
        }
        return new NoDefaultConstructorBeanKeyImpl(key);
    } catch (IllegalArgumentException e) {
        throw new DatabindingException("Illegal argument. " + e.getMessage(), e);
    }
}
Also used : BeanTypeInfo(org.apache.cxf.aegis.type.basic.BeanTypeInfo) DatabindingException(org.apache.cxf.aegis.DatabindingException) AegisType(org.apache.cxf.aegis.type.AegisType) QName(javax.xml.namespace.QName) NoDefaultConstructorBeanKeyImpl(org.apache.cxf.aegis.custom.service.NoDefaultConstructorBeanKeyImpl) MessageReader(org.apache.cxf.aegis.xml.MessageReader)

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