Search in sources :

Example 6 with BeanType

use of org.apache.cxf.aegis.type.basic.BeanType in project cxf by apache.

the class XMLTypeCreator method createDefaultType.

@Override
public AegisType createDefaultType(TypeClassInfo info) {
    Element mapping = findMapping(info.getType());
    List<Element> mappings = findMappings(info.getType());
    Class<?> relatedClass = TypeUtil.getTypeRelatedClass(info.getType());
    if (mapping != null || !mappings.isEmpty()) {
        String typeNameAtt = null;
        if (mapping != null) {
            typeNameAtt = DOMUtils.getAttributeValueEmptyNull(mapping, "name");
        }
        String extensibleElements = null;
        if (mapping != null) {
            extensibleElements = mapping.getAttribute("extensibleElements");
        }
        String extensibleAttributes = null;
        if (mapping != null) {
            extensibleAttributes = mapping.getAttribute("extensibleAttributes");
        }
        String defaultNS = NamespaceHelper.makeNamespaceFromClassName(relatedClass.getName(), "http");
        QName name = null;
        if (typeNameAtt != null) {
            name = NamespaceHelper.createQName(mapping, typeNameAtt, defaultNS);
            defaultNS = name.getNamespaceURI();
        }
        // We do not deal with Generic beans at this point.
        XMLBeanTypeInfo btinfo = new XMLBeanTypeInfo(relatedClass, mappings, defaultNS);
        btinfo.setTypeMapping(getTypeMapping());
        btinfo.setDefaultMinOccurs(getConfiguration().getDefaultMinOccurs());
        btinfo.setDefaultNillable(getConfiguration().isDefaultNillable());
        if (extensibleElements != null) {
            btinfo.setExtensibleElements(Boolean.valueOf(extensibleElements).booleanValue());
        } else {
            btinfo.setExtensibleElements(getConfiguration().isDefaultExtensibleElements());
        }
        if (extensibleAttributes != null) {
            btinfo.setExtensibleAttributes(Boolean.valueOf(extensibleAttributes).booleanValue());
        } else {
            btinfo.setExtensibleAttributes(getConfiguration().isDefaultExtensibleAttributes());
        }
        btinfo.setQualifyAttributes(this.getConfiguration().isQualifyAttributes());
        btinfo.setQualifyElements(this.getConfiguration().isQualifyElements());
        BeanType type = new BeanType(btinfo);
        if (name == null) {
            name = createQName(relatedClass);
        }
        type.setSchemaType(name);
        type.setTypeClass(info.getType());
        type.setTypeMapping(getTypeMapping());
        return type;
    }
    return nextCreator.createDefaultType(info);
}
Also used : BeanType(org.apache.cxf.aegis.type.basic.BeanType) QName(javax.xml.namespace.QName) Element(org.w3c.dom.Element) XMLBeanTypeInfo(org.apache.cxf.aegis.type.basic.XMLBeanTypeInfo)

Example 7 with BeanType

use of org.apache.cxf.aegis.type.basic.BeanType in project cxf by apache.

the class AnnotatedTypeTest method testAegisType.

/**
 * Test if attributeProperty is correctly mapped to attProp by
 * applying the xml mapping file <className>.aegis.xml
 */
@Test
public void testAegisType() {
    BeanType type = (BeanType) tm.getTypeCreator().createType(AnnotatedBean3.class);
    assertEquals(0, type.getTypeInfo().getAttributes().size());
    Iterator<QName> itr = type.getTypeInfo().getElements().iterator();
    assertTrue(itr.hasNext());
    QName q = itr.next();
    assertEquals("attProp", q.getLocalPart());
}
Also used : BeanType(org.apache.cxf.aegis.type.basic.BeanType) QName(javax.xml.namespace.QName) Test(org.junit.Test) AbstractAegisTest(org.apache.cxf.aegis.AbstractAegisTest)

Example 8 with BeanType

use of org.apache.cxf.aegis.type.basic.BeanType in project cxf by apache.

the class ConfigurationTest method testExtensibleDefaultFalse.

@Test
public void testExtensibleDefaultFalse() throws Exception {
    config.setDefaultExtensibleElements(false);
    config.setDefaultExtensibleAttributes(false);
    AegisType type = tm.getTypeCreator().createType(AnnotatedBean1.class);
    BeanTypeInfo info = ((BeanType) type).getTypeInfo();
    assertFalse(info.isExtensibleElements());
    assertFalse(info.isExtensibleAttributes());
}
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) Test(org.junit.Test) AbstractAegisTest(org.apache.cxf.aegis.AbstractAegisTest)

Example 9 with BeanType

use of org.apache.cxf.aegis.type.basic.BeanType in project cxf by apache.

the class ConfigurationTest method testMinOccursDefault0.

@Test
public void testMinOccursDefault0() throws Exception {
    config.setDefaultMinOccurs(0);
    AegisType type = tm.getTypeCreator().createType(AnnotatedBean1.class);
    BeanTypeInfo info = ((BeanType) type).getTypeInfo();
    assertEquals(info.getMinOccurs(new QName(info.getDefaultNamespace(), "bogusProperty")), 0);
}
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 10 with BeanType

use of org.apache.cxf.aegis.type.basic.BeanType 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

BeanType (org.apache.cxf.aegis.type.basic.BeanType)26 AbstractAegisTest (org.apache.cxf.aegis.AbstractAegisTest)19 Test (org.junit.Test)19 QName (javax.xml.namespace.QName)17 AegisType (org.apache.cxf.aegis.type.AegisType)8 BeanTypeInfo (org.apache.cxf.aegis.type.basic.BeanTypeInfo)8 TypeCreationOptions (org.apache.cxf.aegis.type.TypeCreationOptions)3 MessageWriter (org.apache.cxf.aegis.xml.MessageWriter)2 GenericArrayType (java.lang.reflect.GenericArrayType)1 ParameterizedType (java.lang.reflect.ParameterizedType)1 AegisContext (org.apache.cxf.aegis.AegisContext)1 DatabindingException (org.apache.cxf.aegis.DatabindingException)1 TypeMapping (org.apache.cxf.aegis.type.TypeMapping)1 TypeUtil (org.apache.cxf.aegis.type.TypeUtil)1 XMLBeanTypeInfo (org.apache.cxf.aegis.type.basic.XMLBeanTypeInfo)1 XmlSchema (org.apache.ws.commons.schema.XmlSchema)1 Element (org.w3c.dom.Element)1