Search in sources :

Example 1 with AegisType

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

the class MapTest method testType.

@Test
public void testType() throws Exception {
    Method m = MapService.class.getMethod("getMap", new Class[0]);
    AegisType type = creator.createType(m, -1);
    tm.register(type);
    assertTrue(type instanceof MapType);
    MapType mapType = (MapType) type;
    QName keyName = mapType.getKeyName();
    assertNotNull(keyName);
    type = mapType.getKeyType();
    assertNotNull(type);
    assertTrue(type.getTypeClass().isAssignableFrom(String.class));
    type = mapType.getValueType();
    assertNotNull(type);
    assertTrue(type.getTypeClass().isAssignableFrom(Integer.class));
}
Also used : AegisType(org.apache.cxf.aegis.type.AegisType) QName(javax.xml.namespace.QName) Method(java.lang.reflect.Method) MapType(org.apache.cxf.aegis.type.collection.MapType) Test(org.junit.Test) AbstractAegisTest(org.apache.cxf.aegis.AbstractAegisTest)

Example 2 with AegisType

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

the class MapTest method testPDType.

@Test
public void testPDType() throws Exception {
    PropertyDescriptor pd = Introspector.getBeanInfo(MapDTO.class, Object.class).getPropertyDescriptors()[0];
    AegisType type = creator.createType(pd);
    tm.register(type);
    assertTrue(type instanceof MapType);
    MapType mapType = (MapType) type;
    QName keyName = mapType.getKeyName();
    assertNotNull(keyName);
    type = mapType.getKeyType();
    assertNotNull(type);
    assertTrue(type.getTypeClass().isAssignableFrom(String.class));
    type = mapType.getValueType();
    assertNotNull(type);
    assertTrue(type.getTypeClass().isAssignableFrom(Integer.class));
}
Also used : PropertyDescriptor(java.beans.PropertyDescriptor) AegisType(org.apache.cxf.aegis.type.AegisType) QName(javax.xml.namespace.QName) MapType(org.apache.cxf.aegis.type.collection.MapType) Test(org.junit.Test) AbstractAegisTest(org.apache.cxf.aegis.AbstractAegisTest)

Example 3 with AegisType

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

the class XFireTypeTest method testType.

@Test
public void testType() {
    AnnotatedTypeInfo info = new AnnotatedTypeInfo(tm, XFireBean1.class, "urn:foo", new TypeCreationOptions());
    Iterator<QName> elements = info.getElements().iterator();
    assertTrue(elements.hasNext());
    QName element = elements.next();
    assertTrue(elements.hasNext());
    AegisType custom = info.getType(element);
    if ("bogusProperty".equals(element.getLocalPart())) {
        assertTrue(custom instanceof StringType);
    } else if ("elementProperty".equals(element.getLocalPart())) {
        assertTrue(custom instanceof CustomStringType);
    } else {
        fail("Unexpected element name: " + element.getLocalPart());
    }
    element = elements.next();
    assertFalse(elements.hasNext());
    custom = info.getType(element);
    if ("bogusProperty".equals(element.getLocalPart())) {
        assertTrue(custom instanceof StringType);
    } else if ("elementProperty".equals(element.getLocalPart())) {
        assertTrue(custom instanceof CustomStringType);
    } else {
        fail("Unexpected element name: " + element.getLocalPart());
    }
    Iterator<QName> atts = info.getAttributes().iterator();
    assertTrue(atts.hasNext());
    atts.next();
    assertFalse(atts.hasNext());
    assertTrue(info.isExtensibleElements());
    assertTrue(info.isExtensibleAttributes());
}
Also used : AegisType(org.apache.cxf.aegis.type.AegisType) StringType(org.apache.cxf.aegis.type.basic.StringType) QName(javax.xml.namespace.QName) TypeCreationOptions(org.apache.cxf.aegis.type.TypeCreationOptions) Test(org.junit.Test) AbstractAegisTest(org.apache.cxf.aegis.AbstractAegisTest)

Example 4 with AegisType

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

the class TestDateMapping method testWriteCustomTypeSchemaType.

@Test
public void testWriteCustomTypeSchemaType() throws Exception {
    context = new AegisContext();
    Set<java.lang.reflect.Type> rootClasses = new HashSet<java.lang.reflect.Type>();
    rootClasses.add(BeanWithDate.class);
    context.setRootClasses(rootClasses);
    context.initialize();
    BeanWithDate bean = new BeanWithDate();
    java.sql.Date date = new java.sql.Date(0);
    bean.setFig(date);
    AegisType sbType = context.getTypeMapping().getType(bean.getClass());
    // dummy to put schema in.
    XmlSchema root = new XmlSchema();
    /* will explode if the type object created for the custom mapping isn't fully initialized.
      */
    sbType.writeSchema(root);
}
Also used : AegisType(org.apache.cxf.aegis.type.AegisType) AegisContext(org.apache.cxf.aegis.AegisContext) AegisType(org.apache.cxf.aegis.type.AegisType) XmlSchema(org.apache.ws.commons.schema.XmlSchema) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 5 with AegisType

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

the class AegisXMLStreamDataReader method read.

/**
 * {@inheritDoc}
 */
public Object read(XMLStreamReader reader, AegisType desiredType) throws Exception {
    setupReaderPosition(reader);
    ElementReader elReader = new ElementReader(reader);
    if (elReader.isXsiNil()) {
        elReader.readToEnd();
        return null;
    }
    AegisType type = TypeUtil.getReadTypeStandalone(reader, aegisContext, desiredType);
    if (type == null) {
        throw new DatabindingException(new Message("NO_MAPPING", LOG));
    }
    return type.readObject(elReader, context);
}
Also used : Message(org.apache.cxf.common.i18n.Message) AegisType(org.apache.cxf.aegis.type.AegisType) ElementReader(org.apache.cxf.aegis.xml.stax.ElementReader)

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)17 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 HashSet (java.util.HashSet)8 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 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