Search in sources :

Example 41 with AegisType

use of org.apache.cxf.aegis.type.AegisType 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 42 with AegisType

use of org.apache.cxf.aegis.type.AegisType in project cxf by apache.

the class AbstractEncodedTest method readRef.

public Object readRef(ElementReader root) throws XMLStreamException {
    Context context = getContext();
    // get AegisType based on the element qname
    MessageReader reader = root.getNextElementReader();
    AegisType type = this.mapping.getType(reader.getName());
    assertNotNull("type is null", type);
    // read ref
    SoapRefType soapRefType = new SoapRefType(type);
    SoapRef ref = (SoapRef) soapRefType.readObject(reader, context);
    reader.readToEnd();
    // read the trailing blocks (referenced objects)
    List<Object> roots = trailingBlocks.readBlocks(root, context);
    assertNotNull(roots);
    // close the input stream
    root.getXMLStreamReader().close();
    // return the ref
    return ref.get();
}
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) MessageReader(org.apache.cxf.aegis.xml.MessageReader)

Example 43 with AegisType

use of org.apache.cxf.aegis.type.AegisType 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 44 with AegisType

use of org.apache.cxf.aegis.type.AegisType in project cxf by apache.

the class ConfigurationTest method testNillableDefaultTrue.

@Test
public void testNillableDefaultTrue() throws Exception {
    config.setDefaultNillable(true);
    AegisType type = tm.getTypeCreator().createType(AnnotatedBean1.class);
    BeanTypeInfo info = ((BeanType) type).getTypeInfo();
    assertTrue(info.isNillable(new QName(info.getDefaultNamespace(), "bogusProperty")));
}
Also used : BeanTypeInfo(org.apache.cxf.aegis.type.basic.BeanTypeInfo) AegisType(org.apache.cxf.aegis.type.AegisType) BeanType(org.apache.cxf.aegis.type.basic.BeanType) QName(javax.xml.namespace.QName) Test(org.junit.Test) AbstractAegisTest(org.apache.cxf.aegis.AbstractAegisTest)

Example 45 with AegisType

use of org.apache.cxf.aegis.type.AegisType in project cxf by apache.

the class ConfigurationTest method testNillableDefaultFalse.

@Test
public void testNillableDefaultFalse() throws Exception {
    config.setDefaultNillable(false);
    AegisType type = tm.getTypeCreator().createType(AnnotatedBean1.class);
    BeanTypeInfo info = ((BeanType) type).getTypeInfo();
    assertFalse(info.isNillable(new QName(info.getDefaultNamespace(), "bogusProperty")));
}
Also used : BeanTypeInfo(org.apache.cxf.aegis.type.basic.BeanTypeInfo) AegisType(org.apache.cxf.aegis.type.AegisType) BeanType(org.apache.cxf.aegis.type.basic.BeanType) QName(javax.xml.namespace.QName) Test(org.junit.Test) AbstractAegisTest(org.apache.cxf.aegis.AbstractAegisTest)

Aggregations

AegisType (org.apache.cxf.aegis.type.AegisType)97 QName (javax.xml.namespace.QName)43 Test (org.junit.Test)40 AbstractAegisTest (org.apache.cxf.aegis.AbstractAegisTest)35 DatabindingException (org.apache.cxf.aegis.DatabindingException)18 AegisContext (org.apache.cxf.aegis.AegisContext)16 TypeMapping (org.apache.cxf.aegis.type.TypeMapping)11 Element (org.w3c.dom.Element)11 Context (org.apache.cxf.aegis.Context)10 BeanType (org.apache.cxf.aegis.type.basic.BeanType)10 Method (java.lang.reflect.Method)9 MessageReader (org.apache.cxf.aegis.xml.MessageReader)9 TypeCreationOptions (org.apache.cxf.aegis.type.TypeCreationOptions)8 BeanTypeInfo (org.apache.cxf.aegis.type.basic.BeanTypeInfo)8 CollectionType (org.apache.cxf.aegis.type.collection.CollectionType)8 HashSet (java.util.HashSet)7 MapType (org.apache.cxf.aegis.type.collection.MapType)7 MessageWriter (org.apache.cxf.aegis.xml.MessageWriter)7 ElementReader (org.apache.cxf.aegis.xml.stax.ElementReader)7 XMLStreamWriter (javax.xml.stream.XMLStreamWriter)5