use of org.apache.cxf.aegis.type.AegisType in project cxf by apache.
the class AegisElementProvider method readFrom.
public T readFrom(Class<T> type, Type genericType, Annotation[] annotations, MediaType m, MultivaluedMap<String, String> headers, InputStream is) throws IOException {
if (genericType == null) {
genericType = type;
}
if (type == null) {
type = messyCastToRawType(genericType);
}
AegisContext context = getAegisContext(type, genericType);
AegisType typeToRead = context.getTypeMapping().getType(genericType);
AegisReader<XMLStreamReader> aegisReader = context.createXMLStreamReader();
XMLStreamReader xmlStreamReader = null;
try {
xmlStreamReader = createStreamReader(typeToRead, is);
return type.cast(aegisReader.read(xmlStreamReader, typeToRead));
} catch (Exception e) {
throw ExceptionUtils.toBadRequestException(e, null);
} finally {
try {
StaxUtils.close(xmlStreamReader);
} catch (XMLStreamException e) {
throw ExceptionUtils.toBadRequestException(e, null);
}
}
}
use of org.apache.cxf.aegis.type.AegisType in project tutorials by eugenp.
the class BaeldungIntegrationTest method marshalCourseRepo.
private void marshalCourseRepo(CourseRepo courseRepo) throws Exception {
AegisWriter<XMLStreamWriter> writer = context.createXMLStreamWriter();
AegisType aegisType = context.getTypeMapping().getType(CourseRepo.class);
XMLStreamWriter xmlWriter = XMLOutputFactory.newInstance().createXMLStreamWriter(new FileOutputStream(fileName));
writer.write(courseRepo, new QName("http://aegis.cxf.baeldung.com", "baeldung"), false, xmlWriter, aegisType);
xmlWriter.close();
}
use of org.apache.cxf.aegis.type.AegisType 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);
}
}
use of org.apache.cxf.aegis.type.AegisType in project cxf by apache.
the class TrailingBlocks method writeBlocks.
/**
* Writes all of the unmarshalled objects in the MarshalRegistry.
*
* @param writer the stream to write the objects
* @param context the marshal context
* @return a list containing the object instances written
*/
public List<Object> writeBlocks(MessageWriter writer, Context context) {
List<Object> blocks = new ArrayList<>();
for (Object instance : MarshalRegistry.get(context)) {
// determine instance type
AegisType type = objectType.determineType(context, instance.getClass());
if (type == null) {
TypeMapping tm = context.getTypeMapping();
if (tm == null) {
tm = objectType.getTypeMapping();
}
type = tm.getTypeCreator().createType(instance.getClass());
tm.register(type);
}
// create an new element for the instance
MessageWriter cwriter = writer.getElementWriter(type.getSchemaType());
// write the id attribute
String id = MarshalRegistry.get(context).getInstanceId(instance);
SoapEncodingUtil.writeId(cwriter, id);
// write the instance
objectType.writeObject(instance, cwriter, context);
blocks.add(instance);
// close the element
cwriter.close();
}
return blocks;
}
use of org.apache.cxf.aegis.type.AegisType in project cxf by apache.
the class Java5TypeCreator method createCollectionType.
@Override
public AegisType createCollectionType(TypeClassInfo info) {
Type type = info.getType();
Type componentType = getComponentType(type, 0);
if (componentType != null) {
return createCollectionTypeFromGeneric(info);
}
return nextCreator.createCollectionType(info);
}
Aggregations