Search in sources :

Example 16 with AegisType

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

the class AegisXMLStreamDataReader method read.

/**
 * {@inheritDoc}
 */
public Object read(XMLStreamReader reader, AegisType desiredType) throws Exception {
    setupReaderPosition(reader);
    ElementReader elReader = new ElementReader(reader);
    if (elReader.isXsiNil()) {
        elReader.readToEnd();
        return null;
    }
    AegisType type = TypeUtil.getReadTypeStandalone(reader, aegisContext, desiredType);
    if (type == null) {
        throw new DatabindingException(new Message("NO_MAPPING", LOG));
    }
    return type.readObject(elReader, context);
}
Also used : Message(org.apache.cxf.common.i18n.Message) AegisType(org.apache.cxf.aegis.type.AegisType) ElementReader(org.apache.cxf.aegis.xml.stax.ElementReader)

Example 17 with AegisType

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

the class AegisDatabinding method getSuggestedName.

public QName getSuggestedName(Service s, TypeMapping tm, OperationInfo op, int param) {
    Method m = getMethod(s, op);
    if (m == null) {
        return null;
    }
    QName name = tm.getTypeCreator().getElementName(m, param);
    // instead
    if (name == null) {
        AegisType type = tm.getTypeCreator().createType(m, param);
        if (type.isComplex() && !type.isAbstract()) {
            name = type.getSchemaType();
        }
    }
    return name;
}
Also used : AegisType(org.apache.cxf.aegis.type.AegisType) QName(javax.xml.namespace.QName) Method(java.lang.reflect.Method)

Example 18 with AegisType

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

the class AegisDatabinding method initializeMessage.

protected void initializeMessage(Service s, TypeMapping serviceTM, AbstractMessageContainer container, int partType, Set<AegisType> deps) {
    if (container == null) {
        return;
    }
    for (MessagePartInfo part : container.getMessageParts()) {
        AegisType type = getParameterType(s, serviceTM, part, partType);
        if (part.getXmlSchema() == null) {
            // schema hasn't been filled in yet
            if (type.isAbstract()) {
                part.setTypeQName(type.getSchemaType());
            } else {
                part.setElementQName(type.getSchemaType());
            }
        }
        Annotation[] anns = part.getProperty("parameter.annotations", Annotation[].class);
        long miValue = -1;
        if (type.hasMinOccurs()) {
            miValue = type.getMinOccurs();
        }
        Integer i = AnnotationReader.getMinOccurs(anns);
        if (i != null) {
            miValue = i;
        }
        if (miValue > 0) {
            part.setProperty("minOccurs", Long.toString(miValue));
        }
        // However, this if at least allow .aegis.xml files to get control.
        if (part.getProperty("nillable") == null) {
            boolean isNil = type.isNillable();
            Boolean b = AnnotationReader.isNillable(anns);
            if (b != null || (miValue != 0 && isNil)) {
                part.setProperty("nillable", b == null ? isNil : b);
            }
        /*
                if (miValue == -1 && (b == null ? isNil : b)) {
                    part.setProperty("minOccurs", "1");
                }
                */
        }
        if (type.hasMaxOccurs()) {
            String moValue;
            long mo = type.getMaxOccurs();
            if (mo != Long.MAX_VALUE) {
                moValue = Long.toString(mo);
                part.setProperty("maxOccurs", moValue);
            }
        }
        part2Type.put(part, type);
        // QName elName = getSuggestedName(service, op, param)
        deps.add(type);
        type.getTypeMapping().register(type);
        addDependencies(deps, type);
    }
}
Also used : AegisType(org.apache.cxf.aegis.type.AegisType) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) Annotation(java.lang.annotation.Annotation)

Example 19 with AegisType

use of org.apache.cxf.aegis.type.AegisType 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 20 with AegisType

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

the class CollectionType method writeObject.

@Override
public void writeObject(Object object, MessageWriter writer, Context context) throws DatabindingException {
    if (object == null) {
        return;
    }
    try {
        Collection<?> list = (Collection<?>) object;
        AegisType type = getComponentType();
        if (type == null) {
            throw new DatabindingException("Couldn't find component type for Collection.");
        }
        for (Iterator<?> itr = list.iterator(); itr.hasNext(); ) {
            final String ns;
            if (type.isAbstract()) {
                ns = getSchemaType().getNamespaceURI();
            } else {
                ns = type.getSchemaType().getNamespaceURI();
            }
            writeValue(itr.next(), writer, context, type, type.getSchemaType().getLocalPart(), ns);
        }
    } catch (IllegalArgumentException e) {
        throw new DatabindingException("Illegal argument.", e);
    }
}
Also used : DatabindingException(org.apache.cxf.aegis.DatabindingException) AegisType(org.apache.cxf.aegis.type.AegisType) Collection(java.util.Collection)

Aggregations

AegisType (org.apache.cxf.aegis.type.AegisType)97 QName (javax.xml.namespace.QName)43 Test (org.junit.Test)40 AbstractAegisTest (org.apache.cxf.aegis.AbstractAegisTest)35 DatabindingException (org.apache.cxf.aegis.DatabindingException)18 AegisContext (org.apache.cxf.aegis.AegisContext)16 TypeMapping (org.apache.cxf.aegis.type.TypeMapping)11 Element (org.w3c.dom.Element)11 Context (org.apache.cxf.aegis.Context)10 BeanType (org.apache.cxf.aegis.type.basic.BeanType)10 Method (java.lang.reflect.Method)9 MessageReader (org.apache.cxf.aegis.xml.MessageReader)9 TypeCreationOptions (org.apache.cxf.aegis.type.TypeCreationOptions)8 BeanTypeInfo (org.apache.cxf.aegis.type.basic.BeanTypeInfo)8 CollectionType (org.apache.cxf.aegis.type.collection.CollectionType)8 HashSet (java.util.HashSet)7 MapType (org.apache.cxf.aegis.type.collection.MapType)7 MessageWriter (org.apache.cxf.aegis.xml.MessageWriter)7 ElementReader (org.apache.cxf.aegis.xml.stax.ElementReader)7 XMLStreamWriter (javax.xml.stream.XMLStreamWriter)5