Search in sources :

Example 16 with BeanType

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

the class JaxbTypeTest method testNillableAndMinOccurs.

@Test
public void testNillableAndMinOccurs() {
    BeanType type = (BeanType) tm.getTypeCreator().createType(JaxbBean4.class);
    AnnotatedTypeInfo info = (AnnotatedTypeInfo) type.getTypeInfo();
    Iterator<QName> elements = info.getElements().iterator();
    assertTrue(elements.hasNext());
    // nillable first
    QName element = elements.next();
    if ("minOccursProperty".equals(element.getLocalPart())) {
        assertEquals(1, info.getMinOccurs(element));
    } else {
        assertFalse(info.isNillable(element));
    }
    assertTrue(elements.hasNext());
    // minOccurs = 1 second
    element = elements.next();
    if ("minOccursProperty".equals(element.getLocalPart())) {
        assertEquals(1, info.getMinOccurs(element));
    } else {
        assertFalse(info.isNillable(element));
    }
}
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 17 with BeanType

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

the class StructType method writeElement.

/**
 * Writes a nested element with an unqualified name.
 */
@Override
protected void writeElement(QName name, Object value, AegisType type, MessageWriter writer, Context context) {
    // Nested elements are unqualified
    name = new QName("", name.getLocalPart());
    MessageWriter cwriter = writer.getElementWriter(name);
    if (type instanceof BeanType || type instanceof SoapArrayType) {
        String refId = MarshalRegistry.get(context).getInstanceId(value);
        SoapEncodingUtil.writeRef(cwriter, refId);
    } else {
        type.writeObject(value, cwriter, context);
    }
    cwriter.close();
}
Also used : BeanType(org.apache.cxf.aegis.type.basic.BeanType) QName(javax.xml.namespace.QName) MessageWriter(org.apache.cxf.aegis.xml.MessageWriter)

Example 18 with BeanType

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

the class AegisContext method processRootTypes.

/**
 * Examine a list of override classes, and register all of them.
 *
 * @param tm type manager for this binding
 * @param classes list of class names
 */
private void processRootTypes() {
    rootTypes = new HashSet<>();
    // app may have already supplied classes.
    if (rootClasses == null) {
        rootClasses = new HashSet<java.lang.reflect.Type>();
    }
    rootTypeQNames = new HashSet<>();
    if (this.rootClassNames != null) {
        for (String typeName : rootClassNames) {
            Class<?> c = null;
            try {
                c = ClassLoaderUtils.loadClass(typeName, TypeUtil.class);
            } catch (ClassNotFoundException e) {
                throw new DatabindingException("Could not find override type class: " + typeName, e);
            }
            rootClasses.add(c);
        }
    }
    // This is a list of AegisType rather than Class so that it can set up for generic collections.
    // When we see a generic, we process both the generic outer class and each parameter class.
    // This is not the same thing as allowing mappings of arbitrary x<q> types.
    Set<Class<?>> rootMappableClassSet = rootMappableClasses();
    /*
         * First loop: process non-Class roots, creating full types for them
         * and registering them.
         */
    for (java.lang.reflect.Type reflectType : rootClasses) {
        if (!(reflectType instanceof Class)) {
            // if it's not a Class, it can't be mapped from Class to type in the mapping.
            // so we create
            AegisType aegisType = typeMapping.getTypeCreator().createType(reflectType);
            typeMapping.register(aegisType);
            // note: we don't handle arbitrary generics, so no BeanType
            // check here.
            rootTypeQNames.add(aegisType.getSchemaType());
        }
    }
    /*
         * Second loop: process Class roots, including those derived from
         * generic types, creating when not in the default mappings.
         */
    for (Class<?> c : rootMappableClassSet) {
        AegisType t = typeMapping.getType(c);
        if (t == null) {
            t = typeMapping.getTypeCreator().createType(c);
            typeMapping.register(t);
        }
        rootTypeQNames.add(t.getSchemaType());
        if (t instanceof BeanType) {
            BeanType bt = (BeanType) t;
            bt.getTypeInfo().setExtension(true);
            rootTypes.add(bt);
        }
    }
}
Also used : AegisType(org.apache.cxf.aegis.type.AegisType) GenericArrayType(java.lang.reflect.GenericArrayType) BeanType(org.apache.cxf.aegis.type.basic.BeanType) ParameterizedType(java.lang.reflect.ParameterizedType) AegisType(org.apache.cxf.aegis.type.AegisType) BeanType(org.apache.cxf.aegis.type.basic.BeanType) TypeUtil(org.apache.cxf.aegis.type.TypeUtil)

Example 19 with BeanType

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

the class AnnotatedTypeTest method testNillableAndMinOccurs.

@Test
public void testNillableAndMinOccurs() {
    BeanType type = (BeanType) tm.getTypeCreator().createType(AnnotatedBean4.class);
    AnnotatedTypeInfo info = (AnnotatedTypeInfo) type.getTypeInfo();
    Iterator<QName> elements = info.getElements().iterator();
    assertTrue(elements.hasNext());
    // nillable first
    QName element = elements.next();
    if ("minOccursProperty".equals(element.getLocalPart())) {
        assertEquals(1, info.getMinOccurs(element));
    } else {
        assertFalse(info.isNillable(element));
    }
    assertTrue(elements.hasNext());
    // minOccurs = 1 second
    element = elements.next();
    if ("minOccursProperty".equals(element.getLocalPart())) {
        assertEquals(1, info.getMinOccurs(element));
    } else {
        assertFalse(info.isNillable(element));
    }
}
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 20 with BeanType

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

the class AnnotatedTypeTest method testGetSetRequired.

@Test
public void testGetSetRequired() throws Exception {
    BeanType type = new BeanType(new AnnotatedTypeInfo(tm, BadBean.class, "urn:foo", new TypeCreationOptions()));
    type.setSchemaType(new QName("urn:foo", "BadBean"));
    assertFalse(type.getTypeInfo().getElements().iterator().hasNext());
}
Also used : BeanType(org.apache.cxf.aegis.type.basic.BeanType) QName(javax.xml.namespace.QName) TypeCreationOptions(org.apache.cxf.aegis.type.TypeCreationOptions) 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