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);
}
}
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();
}
}
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);
}
}
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;
}
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);
}
}
Aggregations