Search in sources :

Example 6 with Context

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

the class AbstractEncodedTest method readWriteReadRef.

public <T> T readWriteReadRef(String file, Class<T> typeClass) throws XMLStreamException {
    Context context = getContext();
    AegisType type = mapping.getType(typeClass);
    assertNotNull("no type found for " + typeClass.getName());
    // read file
    ElementReader reader = new ElementReader(getClass().getResourceAsStream(file));
    T value = typeClass.cast(type.readObject(reader, context));
    reader.getXMLStreamReader().close();
    // write value to element
    Element element = writeRef(value);
    // reread value from element
    value = typeClass.cast(readRef(element));
    return value;
}
Also used : MapNamespaceContext(org.apache.cxf.helpers.MapNamespaceContext) Context(org.apache.cxf.aegis.Context) AegisContext(org.apache.cxf.aegis.AegisContext) AegisType(org.apache.cxf.aegis.type.AegisType) Element(org.w3c.dom.Element) ElementReader(org.apache.cxf.aegis.xml.stax.ElementReader)

Example 7 with Context

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

the class AbstractEncodedTest method getContext.

protected Context getContext() {
    AegisContext globalContext = new AegisContext();
    globalContext.initialize();
    globalContext.setTypeMapping(mapping);
    return new Context(globalContext);
}
Also used : MapNamespaceContext(org.apache.cxf.helpers.MapNamespaceContext) Context(org.apache.cxf.aegis.Context) AegisContext(org.apache.cxf.aegis.AegisContext) AegisContext(org.apache.cxf.aegis.AegisContext)

Example 8 with Context

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

the class AbstractEncodedTest method writeRef.

public Element writeRef(Object instance) {
    AegisType type = mapping.getType(instance.getClass());
    assertNotNull("no type found for " + instance.getClass().getName());
    // create the document
    Element element = createElement("urn:Bean", "root", "b");
    MapNamespaceContext namespaces = new MapNamespaceContext();
    // we should not add the out namespace here, as it is not a part of root element
    /*for (Map.Entry<String, String> entry : getNamespaces().entrySet()) {
            namespaces.addNamespace(entry.getKey(), entry.getValue());
        }*/
    ElementWriter rootWriter = getElementWriter(element, namespaces);
    Context context = getContext();
    // get AegisType based on the object instance
    assertNotNull("type is null", type);
    // write the ref
    SoapRefType soapRefType = new SoapRefType(type);
    MessageWriter cwriter = rootWriter.getElementWriter(soapRefType.getSchemaType());
    soapRefType.writeObject(instance, cwriter, context);
    cwriter.close();
    // write the trailing blocks (referenced objects)
    trailingBlocks.writeBlocks(rootWriter, context);
    return element;
}
Also used : MapNamespaceContext(org.apache.cxf.helpers.MapNamespaceContext) Context(org.apache.cxf.aegis.Context) AegisContext(org.apache.cxf.aegis.AegisContext) AegisType(org.apache.cxf.aegis.type.AegisType) Element(org.w3c.dom.Element) MapNamespaceContext(org.apache.cxf.helpers.MapNamespaceContext) MessageWriter(org.apache.cxf.aegis.xml.MessageWriter) ElementWriter(org.apache.cxf.aegis.xml.stax.ElementWriter)

Example 9 with Context

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

the class SoapArrayTypeTest method testStructArray.

@Test
public void testStructArray() throws Exception {
    Context context = getContext();
    // b:address[2]
    ElementReader reader = new ElementReader(getClass().getResourceAsStream("arrayStructs.xml"));
    Address[] addresses = (Address[]) createArrayType(Address[].class).readObject(reader, context);
    reader.getXMLStreamReader().close();
    AbstractEncodedTest.validateShippingAddress(addresses[0]);
    AbstractEncodedTest.validateBillingAddress(addresses[1]);
    // round trip tests
    addresses = readWriteReadRef("arrayStructs.xml", Address[].class);
    AbstractEncodedTest.validateShippingAddress(addresses[0]);
    AbstractEncodedTest.validateBillingAddress(addresses[1]);
}
Also used : Context(org.apache.cxf.aegis.Context) ElementReader(org.apache.cxf.aegis.xml.stax.ElementReader) Test(org.junit.Test)

Example 10 with Context

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

the class SoapArrayTypeTest method testPartiallyTransmitted.

@Test
public void testPartiallyTransmitted() throws Exception {
    Context context = getContext();
    // xsd:int[5] offset="[2]"
    ElementReader reader = new ElementReader(getClass().getResourceAsStream("arrayPartiallyTransmitted.xml"));
    int[] numbers = (int[]) createArrayType(int[].class).readObject(reader, context);
    reader.getXMLStreamReader().close();
    assertArrayEquals(new int[] { 0, 0, 3, 4, 0 }, numbers);
    // round trip tests
    numbers = readWriteReadRef("arrayPartiallyTransmitted.xml", int[].class);
    assertArrayEquals(new int[] { 0, 0, 3, 4, 0 }, numbers);
}
Also used : Context(org.apache.cxf.aegis.Context) ElementReader(org.apache.cxf.aegis.xml.stax.ElementReader) Test(org.junit.Test)

Aggregations

Context (org.apache.cxf.aegis.Context)21 Test (org.junit.Test)13 AegisContext (org.apache.cxf.aegis.AegisContext)11 ElementReader (org.apache.cxf.aegis.xml.stax.ElementReader)11 AegisType (org.apache.cxf.aegis.type.AegisType)10 Element (org.w3c.dom.Element)7 QName (javax.xml.namespace.QName)5 AbstractAegisTest (org.apache.cxf.aegis.AbstractAegisTest)5 MapNamespaceContext (org.apache.cxf.helpers.MapNamespaceContext)5 XmlMappedAttributeBean (org.apache.cxf.aegis.services.XmlMappedAttributeBean)4 TypeMapping (org.apache.cxf.aegis.type.TypeMapping)4 DatabindingException (org.apache.cxf.aegis.DatabindingException)3 MessageWriter (org.apache.cxf.aegis.xml.MessageWriter)3 ElementWriter (org.apache.cxf.aegis.xml.stax.ElementWriter)3 BigDecimal (java.math.BigDecimal)2 AttributeBean (org.apache.cxf.aegis.services.AttributeBean)2 TypeCreationOptions (org.apache.cxf.aegis.type.TypeCreationOptions)2 Message (org.apache.cxf.common.i18n.Message)2 Fault (org.apache.cxf.interceptor.Fault)2 XmlSchemaElement (org.apache.ws.commons.schema.XmlSchemaElement)2