Search in sources :

Example 1 with TypeMapping

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

the class XMLStreamReaderMappingTest method setUp.

@Before
public void setUp() throws Exception {
    super.setUp();
    addNamespace("b", "urn:beanz");
    addNamespace("xsi", Constants.URI_2001_SCHEMA_XSI);
    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.register(XMLStreamReader.class, new QName("urn:Bean", "SimpleBean"), new XMLStreamReaderType());
    mapping.setTypeCreator(context.createTypeCreator());
    context.setTypeMapping(mapping);
    context.initialize();
}
Also used : DefaultTypeMapping(org.apache.cxf.aegis.type.DefaultTypeMapping) QName(javax.xml.namespace.QName) AegisContext(org.apache.cxf.aegis.AegisContext) DefaultTypeMapping(org.apache.cxf.aegis.type.DefaultTypeMapping) TypeMapping(org.apache.cxf.aegis.type.TypeMapping) XMLStreamReaderType(org.apache.cxf.aegis.type.xml.XMLStreamReaderType) Before(org.junit.Before)

Example 2 with TypeMapping

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

the class AegisContext method initialize.

/**
 * Initialize the context. The encodingStyleURI allows .aegis.xml files to have multiple mappings for,
 * say, SOAP 1.1 versus SOAP 1.2. Passing null uses a default URI.
 *
 * @param mappingNamespaceURI URI to select mappings based on the encoding.
 */
public void initialize() {
    // allow spring config of an alternative mapping.
    if (configuration == null) {
        configuration = new TypeCreationOptions();
    }
    if (typeMapping == null) {
        boolean defaultNillable = configuration.isDefaultNillable();
        TypeMapping baseTM = DefaultTypeMapping.createDefaultTypeMapping(defaultNillable, mtomUseXmime, enableJDOMMappings);
        if (mappingNamespaceURI == null) {
            mappingNamespaceURI = DefaultTypeMapping.DEFAULT_MAPPING_URI;
        }
        DefaultTypeMapping defaultTypeMapping = new DefaultTypeMapping(mappingNamespaceURI, baseTM);
        defaultTypeMapping.setTypeCreator(createTypeCreator());
        typeMapping = defaultTypeMapping;
    }
    processRootTypes();
}
Also used : DefaultTypeMapping(org.apache.cxf.aegis.type.DefaultTypeMapping) TypeMapping(org.apache.cxf.aegis.type.TypeMapping) DefaultTypeMapping(org.apache.cxf.aegis.type.DefaultTypeMapping) TypeCreationOptions(org.apache.cxf.aegis.type.TypeCreationOptions)

Example 3 with TypeMapping

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

the class BeanType method getSuperType.

/**
 * Return the AegisType for the superclass if this type's class, if any.
 * @return
 */
public AegisType getSuperType() {
    BeanTypeInfo inf = getTypeInfo();
    Class<?> c = inf.getTypeClass();
    if (c.isInterface() && c.getInterfaces().length == 1) {
        c = c.getInterfaces()[0];
    } else {
        c = c.getSuperclass();
    }
    /*
         * Don't dig any deeper than Object or Exception
         */
    if (c != null && c != Object.class && c != Exception.class && c != RuntimeException.class && c != Enum.class && c != Serializable.class && c != Cloneable.class) {
        TypeMapping tm = inf.getTypeMapping();
        AegisType superType = tm.getType(c);
        if (superType == null) {
            // if we call createType, we know that we'll get a BeanType. */
            superType = getTypeMapping().getTypeCreator().createType(c);
            if (superType != null) {
                tm.register(superType);
                this.info.setExtension(true);
            }
        } else {
            this.info.setExtension(true);
        }
        return superType;
    }
    return null;
}
Also used : AegisType(org.apache.cxf.aegis.type.AegisType) TypeMapping(org.apache.cxf.aegis.type.TypeMapping) InvocationTargetException(java.lang.reflect.InvocationTargetException) DatabindingException(org.apache.cxf.aegis.DatabindingException)

Example 4 with TypeMapping

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

the class BeanTypeInfo method getType.

/**
 * Get the type class for the field with the specified QName.
 */
public AegisType getType(QName name) {
    // 1. Try a prexisting mapped type
    AegisType type = mappedName2type.get(name);
    // 2. Try to get the type by its name, if there is one
    if (type == null) {
        QName typeName = getMappedTypeName(name);
        if (typeName != null) {
            type = getTypeMapping().getType(typeName);
            if (type != null) {
                mapType(name, type);
            }
        }
    }
    // 3. Create the type from the property descriptor and map it
    if (type == null) {
        PropertyDescriptor desc;
        try {
            desc = getPropertyDescriptorFromMappedName(name);
        } catch (Exception e) {
            if (e instanceof DatabindingException) {
                throw (DatabindingException) e;
            }
            throw new DatabindingException("Couldn't get properties.", e);
        }
        if (desc == null) {
            return null;
        }
        try {
            TypeMapping tm = getTypeMapping();
            TypeCreator tc = tm.getTypeCreator();
            type = tc.createType(desc);
        } catch (DatabindingException e) {
            e.prepend("Couldn't create type for property " + desc.getName() + " on " + getTypeClass());
            throw e;
        }
        // second part is possible workaround for XFIRE-586
        if (registerType(desc)) {
            getTypeMapping().register(type);
        }
        mapType(name, type);
    }
    if (type == null) {
        throw new DatabindingException("Couldn't find type for property " + name);
    }
    return type;
}
Also used : DatabindingException(org.apache.cxf.aegis.DatabindingException) PropertyDescriptor(java.beans.PropertyDescriptor) AegisType(org.apache.cxf.aegis.type.AegisType) QName(javax.xml.namespace.QName) TypeMapping(org.apache.cxf.aegis.type.TypeMapping) TypeCreator(org.apache.cxf.aegis.type.TypeCreator) IntrospectionException(java.beans.IntrospectionException) DatabindingException(org.apache.cxf.aegis.DatabindingException)

Example 5 with TypeMapping

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

the class QualificationTest method testXmlDefaultQualifiedAttribute.

@Test
public void testXmlDefaultQualifiedAttribute() throws Exception {
    AegisContext context = new AegisContext();
    TypeCreationOptions typeCreationOptions = new TypeCreationOptions();
    typeCreationOptions.setQualifyAttributes(true);
    context.setTypeCreationOptions(typeCreationOptions);
    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[@pkg:attrXmlString]", element);
    assertXPathEquals("/b:root/@pkg: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) TypeCreationOptions(org.apache.cxf.aegis.type.TypeCreationOptions) Test(org.junit.Test) AbstractAegisTest(org.apache.cxf.aegis.AbstractAegisTest)

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