use of org.apache.cxf.aegis.type.TypeMapping 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.TypeMapping in project cxf by apache.
the class CustomMappingTest method testInheritedMapping.
@Test
public void testInheritedMapping() throws Exception {
BeanTypeInfo bti = new BeanTypeInfo(GregorianCalendar.class, "http://util.java");
BeanType beanType = new BeanType(bti);
beanType.setSchemaType(new QName("http://util.java{GregorianCalendar}"));
AegisContext context = new AegisContext();
context.initialize();
TypeMapping mapping = context.getTypeMapping();
// we are replacing the default mapping.
mapping.register(beanType);
XmlSchema schema = newXmlSchema("http://util.java");
beanType.writeSchema(schema);
// well, test?
}
use of org.apache.cxf.aegis.type.TypeMapping in project cxf by apache.
the class NoNamespaceAegisElementProvider method getAegisContext.
@Override
protected AegisContext getAegisContext(Class<?> plainClass, Type genericType) {
AegisContext context = new AegisContext();
context.setWriteXsiTypes(writeXsiType);
context.setReadXsiTypes(readXsiType);
TypeCreationOptions tco = new TypeCreationOptions();
tco.setQualifyElements(false);
Set<java.lang.reflect.Type> rootClasses = new HashSet<java.lang.reflect.Type>();
rootClasses.add(genericType);
context.setTypeCreationOptions(tco);
context.setRootClasses(rootClasses);
TypeMapping baseMapping = DefaultTypeMapping.createSoap11TypeMapping(true, false, false);
DefaultTypeMapping mapping = new DefaultTypeMapping(Constants.URI_2001_SCHEMA_XSD, baseMapping);
TypeCreator stockTypeCreator = createTypeCreator(tco);
mapping.setTypeCreator(stockTypeCreator);
context.setTypeMapping(mapping);
context.initialize();
return context;
}
Aggregations