Search in sources :

Example 16 with TypeMapping

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;
}
Also used : AegisType(org.apache.cxf.aegis.type.AegisType) ArrayList(java.util.ArrayList) TypeMapping(org.apache.cxf.aegis.type.TypeMapping) MessageWriter(org.apache.cxf.aegis.xml.MessageWriter)

Example 17 with TypeMapping

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?
}
Also used : BeanTypeInfo(org.apache.cxf.aegis.type.basic.BeanTypeInfo) BeanType(org.apache.cxf.aegis.type.basic.BeanType) XmlSchema(org.apache.ws.commons.schema.XmlSchema) QName(javax.xml.namespace.QName) AegisContext(org.apache.cxf.aegis.AegisContext) TypeMapping(org.apache.cxf.aegis.type.TypeMapping) Test(org.junit.Test) AbstractAegisTest(org.apache.cxf.aegis.AbstractAegisTest)

Example 18 with TypeMapping

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;
}
Also used : Type(java.lang.reflect.Type) DefaultTypeMapping(org.apache.cxf.aegis.type.DefaultTypeMapping) AegisContext(org.apache.cxf.aegis.AegisContext) DefaultTypeMapping(org.apache.cxf.aegis.type.DefaultTypeMapping) TypeMapping(org.apache.cxf.aegis.type.TypeMapping) TypeCreationOptions(org.apache.cxf.aegis.type.TypeCreationOptions) XMLTypeCreator(org.apache.cxf.aegis.type.XMLTypeCreator) TypeCreator(org.apache.cxf.aegis.type.TypeCreator) AbstractTypeCreator(org.apache.cxf.aegis.type.AbstractTypeCreator) Java5TypeCreator(org.apache.cxf.aegis.type.java5.Java5TypeCreator) HashSet(java.util.HashSet)

Aggregations

TypeMapping (org.apache.cxf.aegis.type.TypeMapping)18 AegisType (org.apache.cxf.aegis.type.AegisType)11 QName (javax.xml.namespace.QName)8 AegisContext (org.apache.cxf.aegis.AegisContext)8 AbstractAegisTest (org.apache.cxf.aegis.AbstractAegisTest)5 Test (org.junit.Test)5 Context (org.apache.cxf.aegis.Context)4 DatabindingException (org.apache.cxf.aegis.DatabindingException)4 XmlMappedAttributeBean (org.apache.cxf.aegis.services.XmlMappedAttributeBean)4 DefaultTypeMapping (org.apache.cxf.aegis.type.DefaultTypeMapping)4 TypeCreationOptions (org.apache.cxf.aegis.type.TypeCreationOptions)4 Element (org.w3c.dom.Element)4 ArrayList (java.util.ArrayList)2 AttributeBean (org.apache.cxf.aegis.services.AttributeBean)2 TypeCreator (org.apache.cxf.aegis.type.TypeCreator)2 MessageWriter (org.apache.cxf.aegis.xml.MessageWriter)2 Before (org.junit.Before)2 IntrospectionException (java.beans.IntrospectionException)1 PropertyDescriptor (java.beans.PropertyDescriptor)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1