Search in sources :

Example 66 with AegisType

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

the class QualificationTest method testXmlDefaultUnqualifiedAttribute.

@Test
public void testXmlDefaultUnqualifiedAttribute() throws Exception {
    AegisContext context = new AegisContext();
    context.initialize();
    TypeMapping mapping = context.getTypeMapping();
    AegisType type = mapping.getTypeCreator().createType(XmlMappedAttributeBean.class);
    type.setSchemaType(new QName("urn:Bean", "bean"));
    Context messageContext = new Context(context);
    XmlMappedAttributeBean bean = new XmlMappedAttributeBean();
    Element element = writeObjectToElement(type, bean, messageContext);
    assertValid("/b:root[@attrXmlString]", element);
    assertXPathEquals("/b:root/@attrXmlString", "attrXml", element);
}
Also used : Context(org.apache.cxf.aegis.Context) AegisContext(org.apache.cxf.aegis.AegisContext) XmlMappedAttributeBean(org.apache.cxf.aegis.services.XmlMappedAttributeBean) AegisType(org.apache.cxf.aegis.type.AegisType) QName(javax.xml.namespace.QName) Element(org.w3c.dom.Element) AegisContext(org.apache.cxf.aegis.AegisContext) TypeMapping(org.apache.cxf.aegis.type.TypeMapping) Test(org.junit.Test) AbstractAegisTest(org.apache.cxf.aegis.AbstractAegisTest)

Example 67 with AegisType

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

the class StandaloneWriteTest method testBean.

@Test
public void testBean() throws Exception {
    context = new AegisContext();
    Set<java.lang.reflect.Type> rootClasses = new HashSet<>();
    rootClasses.add(SimpleBean.class);
    context.setRootClasses(rootClasses);
    context.initialize();
    SimpleBean sb = new SimpleBean();
    sb.setCharacter('\u4000');
    sb.setHowdy("doody");
    AegisType sbType = context.getTypeMapping().getType(sb.getClass());
    AegisWriter<XMLStreamWriter> writer = context.createXMLStreamWriter();
    StringWriter stringWriter = new StringWriter();
    XMLStreamWriter xmlWriter = xmlOutputFactory.createXMLStreamWriter(stringWriter);
    writer.write(sb, new QName("urn:meow", "catnip"), false, xmlWriter, sbType);
    xmlWriter.close();
    String xml = stringWriter.toString();
    assertTrue(xml.contains("doody"));
}
Also used : StringType(org.apache.cxf.aegis.type.basic.StringType) AegisType(org.apache.cxf.aegis.type.AegisType) StringWriter(java.io.StringWriter) AegisType(org.apache.cxf.aegis.type.AegisType) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) QName(javax.xml.namespace.QName) SimpleBean(org.apache.cxf.aegis.services.SimpleBean) AegisContext(org.apache.cxf.aegis.AegisContext) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 68 with AegisType

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

the class StandaloneWriteTest method testTypeLookup.

@Test
public void testTypeLookup() throws Exception {
    context = new AegisContext();
    context.initialize();
    AegisType st = context.getTypeMapping().getType(new QName(XMLConstants.W3C_XML_SCHEMA_NS_URI, "string"));
    assertNotNull(st);
    assertEquals(st.getClass(), StringType.class);
}
Also used : AegisType(org.apache.cxf.aegis.type.AegisType) QName(javax.xml.namespace.QName) AegisContext(org.apache.cxf.aegis.AegisContext) Test(org.junit.Test)

Example 69 with AegisType

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

the class SoapArrayTypeTest method createArrayType.

private SoapArrayType createArrayType(Class<?> typeClass, QName schemaType) {
    AegisType type = mapping.getType(typeClass);
    if (type != null) {
        return (SoapArrayType) type;
    }
    SoapArrayType arrayType = new SoapArrayType();
    arrayType.setTypeClass(typeClass);
    arrayType.setTypeMapping(mapping);
    arrayType.setSchemaType(schemaType);
    return arrayType;
}
Also used : AegisType(org.apache.cxf.aegis.type.AegisType)

Example 70 with AegisType

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

the class CollectionTest method testRecursiveCollections.

@Test
public void testRecursiveCollections() throws Exception {
    Method m = CollectionService.class.getMethod("getStringCollections", new Class[0]);
    AegisType type = creator.createType(m, -1);
    tm.register(type);
    assertTrue(type instanceof CollectionType);
    CollectionType colType = (CollectionType) type;
    QName componentName = colType.getSchemaType();
    assertEquals("ArrayOfArrayOfString", componentName.getLocalPart());
    type = colType.getComponentType();
    assertNotNull(type);
    assertTrue(type instanceof CollectionType);
    CollectionType colType2 = (CollectionType) type;
    componentName = colType2.getSchemaType();
    assertEquals("ArrayOfString", componentName.getLocalPart());
    type = colType2.getComponentType();
    assertTrue(type.getTypeClass().isAssignableFrom(String.class));
}
Also used : AegisType(org.apache.cxf.aegis.type.AegisType) QName(javax.xml.namespace.QName) CollectionType(org.apache.cxf.aegis.type.collection.CollectionType) Method(java.lang.reflect.Method) 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