Search in sources :

Example 1 with ArrayType

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

the class AegisDatabinding method getParameterType.

private AegisType getParameterType(Service s, TypeMapping tm, MessagePartInfo param, int paramtype) {
    AegisType type = tm.getType(param.getTypeQName());
    if (type != null && type.getTypeClass() != param.getTypeClass()) {
        type = null;
    }
    int offset = 0;
    if (paramtype == OUT_PARAM) {
        offset = 1;
    }
    TypeCreator typeCreator = tm.getTypeCreator();
    if (type == null) {
        // Current author doesn't know how type can be non-null here.
        boolean usingComponentType = false;
        OperationInfo op = param.getMessageInfo().getOperation();
        Method m = getMethod(s, op);
        TypeClassInfo info;
        if (paramtype != FAULT_PARAM && m != null) {
            info = typeCreator.createClassInfo(m, param.getIndex() - offset);
        } else {
            info = typeCreator.createBasicClassInfo(param.getTypeClass());
        }
        Boolean nillable = info.getNillable();
        /*
             * Note that, for types from the mapping, the minOccurs, maxOccurs, and nillable from the 'info'
             * will be ignored by createTypeForClass below. So we need to override.
             */
        type = typeCreator.createTypeForClass(info);
        // if not writing outer, we don't need anything special.
        if (param.getMessageInfo().getOperation().isUnwrapped() && param.getTypeClass().isArray() && type.isWriteOuter()) {
            /*
                 * The service factory expects arrays going into the wrapper to be mapped to the array
                 * component type and will then add min=0/max=unbounded. That doesn't work for Aegis where we
                 * already created a wrapper ArrayType so we'll let it know we want the default.
                 */
            param.setProperty("minOccurs", "1");
            param.setProperty("maxOccurs", "1");
            if (nillable == null) {
                nillable = Boolean.TRUE;
            }
            param.setProperty("nillable", nillable);
        } else {
            if (nillable != null) {
                param.setProperty("nillable", nillable);
            }
            /*
                 * TypeClassInfo uses -1 to mean 'not specified'
                 */
            if (info.getMinOccurs() != -1) {
                param.setProperty("minOccurs", Long.toString(info.getMinOccurs()));
            }
            if (info.getMaxOccurs() != -1) {
                param.setProperty("maxOccurs", Long.toString(info.getMaxOccurs()));
            }
            if ((type instanceof ArrayType) && !type.isWriteOuter()) {
                param.setProperty("org.apache.cxf.aegis.outerType", type);
                ArrayType aType = (ArrayType) type;
                type = aType.getComponentType();
                usingComponentType = true;
            }
        }
        if (info.getMappedName() != null) {
            param.setConcreteName(info.getMappedName());
            param.setName(info.getMappedName());
        }
        if (!usingComponentType) {
            // param setting above?
            if (info.nonDefaultAttributes()) {
                tm.register(type);
            }
            type.setTypeMapping(tm);
        }
        part2Type.put(param, type);
    }
    return type;
}
Also used : OperationInfo(org.apache.cxf.service.model.OperationInfo) ArrayType(org.apache.cxf.aegis.type.basic.ArrayType) AegisType(org.apache.cxf.aegis.type.AegisType) TypeClassInfo(org.apache.cxf.aegis.type.TypeClassInfo) Method(java.lang.reflect.Method) TypeCreator(org.apache.cxf.aegis.type.TypeCreator)

Example 2 with ArrayType

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

the class XMLStreamDataReader method read.

public Object read(MessagePartInfo part, XMLStreamReader input) {
    try {
        AegisType type = part.getProperty("org.apache.cxf.aegis.outerType", AegisType.class);
        if (type == null) {
            type = databinding.getType(part);
            return reader.read(input, type);
        }
        ArrayType arrayType = (ArrayType) type;
        return reader.readFlatArray(input, arrayType, part.getConcreteName());
    } catch (Exception e) {
        throw new Fault(e);
    }
}
Also used : ArrayType(org.apache.cxf.aegis.type.basic.ArrayType) AegisType(org.apache.cxf.aegis.type.AegisType) Fault(org.apache.cxf.interceptor.Fault)

Example 3 with ArrayType

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

the class XMLStreamDataWriter method write.

public void write(Object obj, MessagePartInfo part, XMLStreamWriter output) {
    AegisType type = databinding.getType(part);
    if (type == null) {
        type = databinding.getTypeFromClass(obj.getClass());
    }
    if (type == null) {
        throw new Fault(new Message("NO_MESSAGE_FOR_PART", LOG, part));
    }
    Context context = new Context(databinding.getAegisContext());
    context.setAttachments(attachments);
    type = TypeUtil.getWriteType(databinding.getAegisContext(), obj, type);
    /*
         * We arrive here with a 'type' of the inner type if isWriteOuter is null.
         * However, in that case, the original type is available.
         */
    AegisType outerType = null;
    if (part != null) {
        outerType = part.getProperty("org.apache.cxf.aegis.outerType", AegisType.class);
    }
    try {
        if (obj == null) {
            if (part.getXmlSchema() instanceof XmlSchemaElement && ((XmlSchemaElement) part.getXmlSchema()).getMinOccurs() == 0) {
                // skip writing minOccurs=0 stuff if obj is null
                return;
            } else if (type.isNillable()) {
                ElementWriter writer = new ElementWriter(output);
                MessageWriter w2 = writer.getElementWriter(part.getConcreteName());
                w2.writeXsiNil();
                w2.close();
                return;
            }
        }
        ElementWriter writer = new ElementWriter(output);
        // outerType is only != null for a flat array.
        if (outerType == null) {
            MessageWriter w2 = writer.getElementWriter(part != null ? part.getConcreteName() : type.getSchemaType());
            type.writeObject(obj, w2, context);
            w2.close();
        } else {
            // it has better be an array (!)
            ArrayType aType = (ArrayType) outerType;
            // the part has to have a name or we can't do this.
            aType.writeObject(obj, writer, context, part.getConcreteName());
        }
    } catch (DatabindingException e) {
        throw new RuntimeException(e);
    }
}
Also used : Context(org.apache.cxf.aegis.Context) ArrayType(org.apache.cxf.aegis.type.basic.ArrayType) DatabindingException(org.apache.cxf.aegis.DatabindingException) Message(org.apache.cxf.common.i18n.Message) AegisType(org.apache.cxf.aegis.type.AegisType) XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement) MessageWriter(org.apache.cxf.aegis.xml.MessageWriter) Fault(org.apache.cxf.interceptor.Fault) ElementWriter(org.apache.cxf.aegis.xml.stax.ElementWriter)

Example 4 with ArrayType

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

the class AbstractTypeCreator method createArrayType.

protected AegisType createArrayType(TypeClassInfo info) {
    ArrayType type = new ArrayType();
    type.setTypeMapping(getTypeMapping());
    type.setTypeClass(info.getType());
    type.setSchemaType(createCollectionQName(info, type.getComponentType()));
    if (info.getMinOccurs() != -1) {
        type.setMinOccurs(info.getMinOccurs());
    } else {
        type.setMinOccurs(typeConfiguration.getDefaultMinOccurs());
    }
    if (info.getMaxOccurs() != -1) {
        type.setMaxOccurs(info.getMaxOccurs());
    }
    type.setFlat(info.isFlat());
    return type;
}
Also used : ArrayType(org.apache.cxf.aegis.type.basic.ArrayType)

Aggregations

ArrayType (org.apache.cxf.aegis.type.basic.ArrayType)4 AegisType (org.apache.cxf.aegis.type.AegisType)3 Fault (org.apache.cxf.interceptor.Fault)2 Method (java.lang.reflect.Method)1 Context (org.apache.cxf.aegis.Context)1 DatabindingException (org.apache.cxf.aegis.DatabindingException)1 TypeClassInfo (org.apache.cxf.aegis.type.TypeClassInfo)1 TypeCreator (org.apache.cxf.aegis.type.TypeCreator)1 MessageWriter (org.apache.cxf.aegis.xml.MessageWriter)1 ElementWriter (org.apache.cxf.aegis.xml.stax.ElementWriter)1 Message (org.apache.cxf.common.i18n.Message)1 OperationInfo (org.apache.cxf.service.model.OperationInfo)1 XmlSchemaElement (org.apache.ws.commons.schema.XmlSchemaElement)1