Search in sources :

Example 11 with TypeMapping

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

the class ObjectType method determineType.

public AegisType determineType(Context context, Class<?> clazz) {
    TypeMapping tm = context.getTypeMapping();
    if (tm == null) {
        tm = getTypeMapping();
    }
    AegisType type = tm.getType(clazz);
    if (null != type) {
        return type;
    }
    Class<?>[] interfaces = clazz.getInterfaces();
    for (int i = 0; i < interfaces.length; i++) {
        Class<?> anInterface = interfaces[i];
        type = tm.getType(anInterface);
        if (null != type) {
            return type;
        }
    }
    Class<?> superclass = clazz.getSuperclass();
    if (null == superclass || Object.class.equals(superclass)) {
        return null;
    }
    return determineType(context, superclass);
}
Also used : AegisType(org.apache.cxf.aegis.type.AegisType) TypeMapping(org.apache.cxf.aegis.type.TypeMapping)

Example 12 with TypeMapping

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

the class ObjectType method readObject.

@Override
public Object readObject(MessageReader reader, Context context) throws DatabindingException {
    if (isNil(reader.getAttributeReader(XSI_NIL))) {
        while (reader.hasMoreElementReaders()) {
            reader.getNextElementReader();
        }
        return null;
    }
    MessageReader typeReader = reader.getAttributeReader(XSI_TYPE);
    if (null == typeReader && !readToDocument) {
        throw new DatabindingException("Missing 'xsi:type' attribute");
    }
    String typeName = null;
    if (typeReader != null) {
        typeName = typeReader.getValue();
    }
    if (null == typeName && !readToDocument) {
        throw new DatabindingException("Missing 'xsi:type' attribute value");
    }
    AegisType type = null;
    QName typeQName = null;
    if (typeName != null) {
        typeName = typeName.trim();
        typeQName = extractQName(reader, typeName);
    } else {
        typeQName = reader.getName();
    }
    TypeMapping tm = context.getTypeMapping();
    if (tm == null) {
        tm = getTypeMapping();
    }
    type = tm.getType(typeQName);
    if (type == null) {
        type = tm.getType(getSchemaType());
    }
    if (type == this) {
        throw new DatabindingException("Could not determine how to read type: " + typeQName);
    }
    if (type == null && readToDocument) {
        type = getTypeMapping().getType(Document.class);
    }
    if (null == type) {
        throw new DatabindingException("No mapped type for '" + typeName + "' (" + typeQName + ")");
    }
    return type.readObject(reader, context);
}
Also used : DatabindingException(org.apache.cxf.aegis.DatabindingException) AegisType(org.apache.cxf.aegis.type.AegisType) QName(javax.xml.namespace.QName) TypeMapping(org.apache.cxf.aegis.type.TypeMapping) MessageReader(org.apache.cxf.aegis.xml.MessageReader) Document(org.w3c.dom.Document)

Example 13 with TypeMapping

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

the class ObjectType method writeObject.

@Override
public void writeObject(Object object, MessageWriter writer, Context context) throws DatabindingException {
    if (null == object) {
        MessageWriter nilWriter = writer.getAttributeWriter(XSI_NIL);
        nilWriter.writeValue("true");
        nilWriter.close();
    } else {
        AegisType type = determineType(context, object.getClass());
        if (null == type) {
            TypeMapping tm = context.getTypeMapping();
            if (tm == null) {
                tm = getTypeMapping();
            }
            type = tm.getTypeCreator().createType(object.getClass());
            tm.register(type);
        }
        writer.writeXsiType(type.getSchemaType());
        boolean nextIsBeanType = type instanceof BeanType;
        if (nextIsBeanType) {
            ((BeanType) type).writeObjectFromObjectType(object, writer, context, true);
        } else {
            type.writeObject(object, writer, context);
        }
    }
}
Also used : AegisType(org.apache.cxf.aegis.type.AegisType) MessageWriter(org.apache.cxf.aegis.xml.MessageWriter) TypeMapping(org.apache.cxf.aegis.type.TypeMapping)

Example 14 with TypeMapping

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

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

the class AbstractEncodedTest method setUp.

@Before
public void setUp() throws Exception {
    super.setUp();
    addNamespace("b", "urn:Bean");
    addNamespace("a", "urn:anotherns");
    addNamespace("xsi", Constants.URI_2001_SCHEMA_XSI);
    addNamespace("soapenc", Soap11.getInstance().getSoapEncodingStyle());
    AegisContext context = new AegisContext();
    // create a different mapping than the context creates.
    TypeMapping baseMapping = DefaultTypeMapping.createSoap11TypeMapping(true, false, false);
    mapping = new DefaultTypeMapping(Constants.URI_2001_SCHEMA_XSD, baseMapping);
    mapping.setTypeCreator(context.createTypeCreator());
    context.setTypeMapping(mapping);
    context.initialize();
    // serialization root type
    trailingBlocks = new TrailingBlocks();
}
Also used : 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) Before(org.junit.Before)

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