Search in sources :

Example 6 with TypeMapping

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

the class QualificationTest method testAnnotatedDefaultQualifiedAttribute.

@Test
public void testAnnotatedDefaultQualifiedAttribute() 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(AttributeBean.class);
    type.setSchemaType(new QName("urn:Bean", "bean"));
    Context messageContext = new Context(context);
    AttributeBean bean = new AttributeBean();
    Element element = writeObjectToElement(type, bean, messageContext);
    assertValid("/b:root[@xyzzy:attrExplicitString]", element);
    assertXPathEquals("/b:root/@xyzzy:attrExplicitString", "attrExplicit", element);
    assertValid("/b:root[@pkg:attrPlainString]", element);
    assertXPathEquals("/b:root/@pkg:attrPlainString", "attrPlain", element);
}
Also used : Context(org.apache.cxf.aegis.Context) AegisContext(org.apache.cxf.aegis.AegisContext) 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) XmlMappedAttributeBean(org.apache.cxf.aegis.services.XmlMappedAttributeBean) AttributeBean(org.apache.cxf.aegis.services.AttributeBean) TypeCreationOptions(org.apache.cxf.aegis.type.TypeCreationOptions) Test(org.junit.Test) AbstractAegisTest(org.apache.cxf.aegis.AbstractAegisTest)

Example 7 with TypeMapping

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

the class QualificationTest method testAnnotatedDefaultUnqualifiedAttribute.

@Test
public void testAnnotatedDefaultUnqualifiedAttribute() throws Exception {
    AegisContext context = new AegisContext();
    context.initialize();
    TypeMapping mapping = context.getTypeMapping();
    AegisType type = mapping.getTypeCreator().createType(AttributeBean.class);
    type.setSchemaType(new QName("urn:Bean", "bean"));
    Context messageContext = new Context(context);
    AttributeBean bean = new AttributeBean();
    Element element = writeObjectToElement(type, bean, messageContext);
    assertValid("/b:root[@xyzzy:attrExplicitString]", element);
    assertXPathEquals("/b:root/@xyzzy:attrExplicitString", "attrExplicit", element);
    assertValid("/b:root[@attrPlainString]", element);
    assertXPathEquals("/b:root/@attrPlainString", "attrPlain", element);
}
Also used : Context(org.apache.cxf.aegis.Context) AegisContext(org.apache.cxf.aegis.AegisContext) 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) XmlMappedAttributeBean(org.apache.cxf.aegis.services.XmlMappedAttributeBean) AttributeBean(org.apache.cxf.aegis.services.AttributeBean) Test(org.junit.Test) AbstractAegisTest(org.apache.cxf.aegis.AbstractAegisTest)

Example 8 with TypeMapping

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

the class SoapArrayType method readObject.

@Override
public Object readObject(MessageReader reader, Context context) throws DatabindingException {
    try {
        // get the encoded array type info
        TypeMapping tm = context.getTypeMapping();
        if (tm == null) {
            tm = getTypeMapping();
        }
        ArrayTypeInfo arrayTypeInfo = new ArrayTypeInfo(reader, tm);
        // verify arrayType dimensions are the same as this type class's array dimensions
        if (getDimensions() != arrayTypeInfo.getTotalDimensions()) {
            throw new DatabindingException("In " + getSchemaType() + " expected array with " + getDimensions() + " dimensions, but arrayType has " + arrayTypeInfo.getTotalDimensions() + " dimensions: " + arrayTypeInfo.toString());
        }
        // calculate max size
        int maxSize = 1;
        for (int dimension : arrayTypeInfo.getDimensions()) {
            maxSize *= dimension;
        }
        // verify offset doesn't exceed maximum size
        if (arrayTypeInfo.getOffset() >= maxSize) {
            throw new DatabindingException("The array offset " + arrayTypeInfo.getOffset() + " in " + getSchemaType() + " exceeds the expecte size of " + maxSize);
        }
        // read the values
        List<Object> values = readCollection(reader, context, arrayTypeInfo, maxSize - arrayTypeInfo.getOffset());
        // if it is a partially transmitted array offset the array values
        if (arrayTypeInfo.getOffset() > 0) {
            List<Object> list = new ArrayList<>(values.size() + arrayTypeInfo.getOffset());
            list.addAll(Collections.nCopies(arrayTypeInfo.getOffset(), null));
            list.addAll(values);
            values = list;
        }
        // check bounds
        if (values.size() > maxSize) {
            throw new DatabindingException("The number of elements " + values.size() + " in " + getSchemaType() + " exceeds the expecte size of " + maxSize);
        }
        if (values.size() < maxSize) {
            values.addAll(Collections.nCopies(maxSize - values.size(), null));
        // todo is this an error?
        // throw new DatabindingException("The number of elements in " + getSchemaType() +
        // " is less then the expected size of " + expectedSize);
        }
        if (values.size() != maxSize) {
            throw new IllegalStateException("Internal error: Expected values collection to contain " + maxSize + " elements but it contains " + values.size() + " elements");
        }
        // create the array
        return makeArray(values, arrayTypeInfo.getDimensions(), getTypeClass().getComponentType());
    } catch (IllegalArgumentException e) {
        throw new DatabindingException("Illegal argument.", e);
    }
}
Also used : DatabindingException(org.apache.cxf.aegis.DatabindingException) ArrayList(java.util.ArrayList) TypeMapping(org.apache.cxf.aegis.type.TypeMapping)

Example 9 with TypeMapping

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

the class ExplicitPrefixTest method setupService.

private ServiceAndMapping setupService(Class<?> seiClass, Map<String, String> namespaces) {
    AegisDatabinding db = new AegisDatabinding();
    db.setNamespaceMap(namespaces);
    Server s = createService(seiClass, null, db);
    ServiceAndMapping serviceAndMapping = new ServiceAndMapping();
    serviceAndMapping.setServer(s);
    serviceAndMapping.setService(s.getEndpoint().getService());
    serviceAndMapping.setTypeMapping((TypeMapping) serviceAndMapping.getService().get(TypeMapping.class.getName()));
    return serviceAndMapping;
}
Also used : Server(org.apache.cxf.endpoint.Server) TypeMapping(org.apache.cxf.aegis.type.TypeMapping) AegisDatabinding(org.apache.cxf.aegis.databinding.AegisDatabinding)

Example 10 with TypeMapping

use of org.apache.cxf.aegis.type.TypeMapping in project qi4j-sdk by Qi4j.

the class ValueCompositeCxfType method getOrCreateNonQi4jType.

private AegisType getOrCreateNonQi4jType(Object value) {
    AegisType type;
    TypeMapping mapping = getTypeMapping();
    Class<?> javaType = value.getClass();
    type = mapping.getType(javaType);
    if (type == null) {
        // This might be wrong and instead the ultimate top parent should be used. This works, since
        // we know that we are the top parent.
        type = getTypeMapping().getTypeCreator().createType(javaType);
        mapping.register(type);
    }
    return type;
}
Also used : AegisType(org.apache.cxf.aegis.type.AegisType) TypeMapping(org.apache.cxf.aegis.type.TypeMapping)

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